﻿namespace = pam_secular_faith_events

# Secular Faith & Rite: ambient flavor events for the yearly pool (By God Alone)

##########################################################################################
# 0001 - Holy Smoke (incense / saint veneration)
##########################################################################################
pam_secular_faith_events.0001 = {
	type = character_event
	title = pam_secular_faith_events.0001.t
	desc = pam_secular_faith_events.0001.desc
	theme = christian
	override_background = temple
	override_effect_2d = { reference = smoke }
	widgets = {
		widget = {
			gui = event_window_widget_vfx_godray
			container = background_shader_vfx_container
		}
	}

	left_portrait = {
		character = root
		animation = prayer_standing
		camera = camera_event_left_away_3_4_small
	}
	right_portrait = {
		character = scope:chaplain
		animation = thurible
		camera = camera_event_center_pointing_forward_fov35
	}

	cooldown = { years = 10 }

	trigger = {
		pam_secular_faith_landed_actor_trigger = yes
		faith.religion = { is_in_family = rf_abrahamic }
		cp:councillor_court_chaplain ?= {
			is_available_ai_adult = yes
		}
	}

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

	option = { # Lose yourself in private prayer
		name = pam_secular_faith_events.0001.a
		change_spiritual_fulfillment = minor_spiritual_fulfillment_value
		stress_and_fulfillment_impact = {
			cynical = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = { has_trait = cynical factor = 0 }
		}
	}

	option = { # Dedicate the rite to the god of wealth
		name = pam_secular_faith_events.0001.b
		add_piety = medium_piety_gain
		add_character_modifier = {
			modifier = pam_sf_devotion_modifier
			years = 15
		}
		stress_and_fulfillment_impact = {
			generous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = { has_trait = generous factor = 0 }
		}
	}

	option = { # Share the devotion with the court
		name = pam_secular_faith_events.0001.c
		add_prestige = medium_prestige_gain
		add_character_modifier = {
			modifier = pam_sf_serenity_modifier
			years = 3
		}
		stress_and_fulfillment_impact = {
			zealous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = { has_trait = zealous factor = 0 }
		}
	}
}

##########################################################################################
# 0002 - Pikuach Nefesh (rescue a traveler on the Sabbath)
##########################################################################################
scripted_effect pam_secular_faith_shabbat_rescue_success_effect = {
	if = {
		limit = { can_add_hook = { target = scope:traveler_in_danger type = saved_my_life_hook } }
		add_hook = { type = saved_my_life_hook target = scope:traveler_in_danger }
	}
	scope:traveler_in_danger = {
		add_opinion = { target = root modifier = grateful_opinion opinion = 30 }
		if = {
			limit = { exists = current_travel_plan }
			current_travel_plan = { add_travel_plan_modifier = pam_sf_safe_passage_modifier }
		}
	}
}

scripted_effect pam_secular_faith_shabbat_rescue_failure_effect = {
	scope:traveler_in_danger = {
		increase_wounds_no_death_effect = { REASON = fight }
		if = {
			limit = { exists = current_travel_plan }
			current_travel_plan = { add_travel_plan_modifier = pam_sf_waylaid_road_modifier }
		}
	}
}

pam_secular_faith_events.0002 = {
	type = character_event
	title = pam_secular_faith_events.0002.t
	desc = pam_secular_faith_events.0002.desc
	theme = christian
	override_background = terrain_scope
	widgets = {
		widget = { gui = event_window_widget_vfx_heavy_smoke container = foreground_shader_vfx_container }
	}

	left_portrait = {
		character = scope:traveler_in_danger
		animation = sword_yield_start
		camera = camera_event_right_forward
	}
	lower_right_portrait = {
		character = scope:chaplain
	}

	cooldown = { years = 10 }

	trigger = {
		pam_secular_faith_landed_actor_trigger = yes
		cp:councillor_court_chaplain ?= {
			is_available_ai_adult = yes
		}
		religion = religion:judaism_religion
		any_held_title = {
			tier = tier_county
			any_county_province = {
				any_character_in_location = {
					is_ai = yes
					current_travel_plan.travel_plan_owner ?= this
					this != root
					is_physically_able_adult = yes
				}
			}
		}
	}

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

		random_held_title = {
			limit = {
				tier = tier_county
				any_county_province = {
					any_character_in_location = {
						is_ai = yes
						current_travel_plan.travel_plan_owner ?= this
						this != root
						is_physically_able_adult = yes
					}
				}
			}
			random_county_province = {
				limit = {
					any_character_in_location = {
						is_ai = yes
						current_travel_plan.travel_plan_owner ?= this
						this != root
						is_physically_able_adult = yes
					}
				}
				save_scope_as = background_terrain_scope
				random_character_in_location = {
					limit = {
						is_ai = yes
						current_travel_plan.travel_plan_owner ?= this
						this != root
						is_physically_able_adult = yes
					}
					save_scope_as = traveler_in_danger
				}
			}
		}
	}

	option = { # Ride out at once and save them
		name = pam_secular_faith_events.0002.a
		add_piety = major_piety_gain
		pam_secular_faith_shabbat_rescue_success_effect = yes
		random = {
			chance = {
				value = 30
				subtract = {
					add = root.prowess
					multiply = 2
				}
				min = 1
			}
			increase_wounds_no_death_effect = { REASON = fight }
		}
		stress_and_fulfillment_impact = {
			base = medium_stress_gain
			craven = massive_stress_impact_gain
			sadistic = minor_stress_impact_gain
			callous = minor_stress_impact_gain
			brave = massive_stress_impact_loss
			zealous = medium_stress_impact_loss
		}
		ai_chance = {
			base = 100
			modifier = {
				OR = {
					has_trait = craven
					has_trait = sadistic
					has_trait = callous
					prowess < 10
				}
				factor = 0
			}
		}
	}

	option = { # Learning challenge: the higher the learning, the likelier the rescue
		name = pam_secular_faith_events.0002.b
		duel = {
			skill = learning
			value = high_skill_rating
			50 = { # Success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				pam_secular_faith_shabbat_rescue_success_effect = yes
				add_piety = major_piety_gain
				scope:chaplain = { add_opinion = { target = root modifier = pious_opinion opinion = 30 } }
			}
			50 = { # We took too long
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				pam_secular_faith_shabbat_rescue_failure_effect = yes
				scope:chaplain = {
					add_opinion = {
						target = root
						modifier = impious_opinion
						opinion = -20
					}
				}
			}
		}
		stress_and_fulfillment_impact = {
			impatient = massive_stress_impact_gain
			sadistic = minor_stress_impact_gain
			callous = minor_stress_impact_gain
			humble = medium_stress_impact_loss
			patient = medium_stress_impact_loss
		}
		ai_chance = {
			base = 100
			modifier = {
				OR = {
					has_trait = impatient
					has_trait = sadistic
					has_trait = callous
				}
				factor = 0
			}
		}
	}

	option = { # Do not save them
		name = pam_secular_faith_events.0002.c
		pam_secular_faith_shabbat_rescue_failure_effect = yes
		stress_and_fulfillment_impact = {
			craven = major_stress_impact_loss
			brave = massive_stress_impact_gain
			compassionate = medium_stress_impact_gain
		}
		ai_chance = {
			base = 25
			modifier = {
				OR = {
					has_trait = brave
					has_trait = compassionate
				}
				factor = 0
			}
		}
	}
}

##########################################################################################
# 0003 - A Vision in the Night (divine vision)
##########################################################################################
scripted_effect pam_secular_faith_seed_unknown_tenet_effect = {
	random_list = {
		10 = {
			trigger = { NOT = { knows_tenet = tenet_ritual_cannibalism } }
			add_known_tenet = tenet_ritual_cannibalism
			pam_secular_faith_seed_tenet_message_effect = { TENET = tenet:tenet_ritual_cannibalism }
		}
		10 = {
			trigger = { NOT = { knows_tenet = tenet_sacred_shadows } }
			add_known_tenet = tenet_sacred_shadows
			pam_secular_faith_seed_tenet_message_effect = { TENET = tenet:tenet_sacred_shadows }
		}
		10 = {
			trigger = { NOT = { knows_tenet = tenet_human_sacrifice } }
			add_known_tenet = tenet_human_sacrifice
			pam_secular_faith_seed_tenet_message_effect = { TENET = tenet:tenet_human_sacrifice }
		}
		10 = {
			trigger = { NOT = { knows_tenet = tenet_pursuit_of_power } }
			add_known_tenet = tenet_pursuit_of_power
			pam_secular_faith_seed_tenet_message_effect = { TENET = tenet:tenet_pursuit_of_power }
		}
		10 = {
			trigger = { NOT = { knows_tenet = tenet_carnal_exaltation } }
			add_known_tenet = tenet_carnal_exaltation
			pam_secular_faith_seed_tenet_message_effect = { TENET = tenet:tenet_carnal_exaltation }
		}
		10 = {
			trigger = { NOT = { knows_tenet = tenet_hedonistic } }
			add_known_tenet = tenet_hedonistic
			pam_secular_faith_seed_tenet_message_effect = { TENET = tenet:tenet_hedonistic }
		}
		# Safety fallback - only reachable once every notable tenet above is already known, so the list is never empty.
		1 = {
			trigger = {
				knows_tenet = tenet_ritual_cannibalism
				knows_tenet = tenet_sacred_shadows
				knows_tenet = tenet_human_sacrifice
				knows_tenet = tenet_pursuit_of_power
				knows_tenet = tenet_carnal_exaltation
				knows_tenet = tenet_hedonistic
			}
			change_spiritual_fulfillment = minor_spiritual_fulfillment_value
		}
	}
}

pam_secular_faith_events.0003 = {
	type = character_event
	title = pam_secular_faith_events.0003.t
	desc = pam_secular_faith_events.0003.desc
	theme = christian
	override_background = bedchamber
	widgets = {
		widget = { gui = event_window_widget_vfx_background_night_scene container = foreground_shader_vfx_container }
		widget = { gui = event_window_widget_vfx_left_character_double_vision_severe 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 = divine_ecstasy
		camera = camera_event_right_forward
		outfit_tags = { nightgown }
	}

	cooldown = { years = 10 }

	trigger = {
		pam_secular_faith_clergy_ok_actor_trigger = yes
	}

	option = { # Heed it as divine truth
		name = pam_secular_faith_events.0003.a
		pam_secular_faith_seed_unknown_tenet_effect = yes
		change_spiritual_fulfillment = medium_spiritual_fulfillment_value
		stress_and_fulfillment_impact = {
			cynical = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = { has_trait = cynical factor = 0 }
		}
	}

	option = { # Dismiss it as a fever dream
		name = pam_secular_faith_events.0003.b
		skill = learning
		trigger = {
			learning >= decent_skill_rating
		}
		show_as_unavailable = { always = yes }
		add_scholar_trait_or_xp_effect = { VALUE = 10 }
		stress_and_fulfillment_impact = {
			base = minor_stress_loss
			cynical = minor_stress_loss
			zealous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = { has_trait = zealous factor = 0 }
		}
	}

	option = { # Proclaim the vision to clergy and court
		name = pam_secular_faith_events.0003.c
		trigger = {
			cp:councillor_court_chaplain ?= {
				is_available_ai_adult = yes
			}
		}
		add_piety = medium_piety_gain
		add_character_modifier = {
			modifier = pam_sf_visionary_renown_modifier
			years = 15
		}
		stress_and_fulfillment_impact = {
			shy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = { has_trait = shy factor = 0 }
		}
	}
}

##########################################################################################
# 0004 - Forbidden Truth (temptation -> secret personal tenet)
##########################################################################################
pam_secular_faith_events.0004 = {
	type = character_event
	title = pam_secular_faith_events.0004.t
	desc = pam_secular_faith_events.0004.desc
	theme = christian
	override_background = corridor_night
	widgets = {
		widget = { gui = event_window_widget_vfx_background_flickering_candlelight_dark container = foreground_shader_vfx_container }
		widget = { gui = event_window_widget_vfx_left_character_flickering_candlelight_dark container = foreground_shader_vfx_container }
	}

	left_portrait = {
		character = root
		animation = prayer_standing
	}

	cooldown = { years = 25 }

	trigger = {
		pam_secular_faith_clergy_ok_actor_trigger = yes
		pam_can_adopt_forbidden_personal_tenet_trigger = yes
	}

	# We pre-select so the desc can name the tenet, and the trigger already guarantees a candidate
	immediate = {
		random_desired_tenet = {
			only_positive = yes
			threshold = 1
			selection_count = 97
			limit = {
				save_temporary_scope_as = pam_sf_forbidden_candidate
				NOT = { root = { any_personal_tenet = { this = scope:pam_sf_forbidden_candidate } } }
				root.faith.main_rite = {
					has_tenet_status = {
						tenet = scope:pam_sf_forbidden_candidate
						status = prohibited
					}
				}
			}
			save_scope_as = pam_sf_forbidden_tenet
		}
	}

	option = { # Embrace the forbidden truth, in secret
		name = pam_secular_faith_events.0004.a
		add_internal_flag = dangerous
		force_set_personal_tenet = scope:pam_sf_forbidden_tenet
		change_spiritual_fulfillment = 150
		stress_and_fulfillment_impact = {
			base = massive_stress_impact_loss
			zealous = medium_stress_impact_gain
			cynical = minor_stress_impact_loss
		}
		ai_chance = {
			base = 25
			modifier = {
				factor = 0
				OR = {
					has_trait = zealous
					has_trait = humble
					has_trait = content
				}
			}
		}
	}

	option = { # Reject it and reaffirm your faith
		name = pam_secular_faith_events.0004.b
		add_piety = minor_piety_gain
		stress_and_fulfillment_impact = {
			zealous = medium_stress_impact_loss
			humble = minor_stress_impact_loss
			content = minor_stress_impact_loss
		}
		ai_chance = {
			base = 75
		}
	}
}

##########################################################################################
# 0005 - By Candlelight (evening study reveals a foreign tenet or doctrine)
##########################################################################################
scripted_effect pam_secular_faith_study_revelation_select_effect = {
	random_list = {
		50 = {
			trigger = {
				any_character_tenet = {
					knowledge_filter = unknown
					count >= 1
				}
			}
			random_character_tenet = {
				knowledge_filter = unknown
				save_scope_as = pam_sf_revelation_tenet
			}
		}
		50 = {
			trigger = {
				any_character_doctrine = {
					knowledge_filter = unknown
					passive_rite_learning_doctrine_is_learnable_trigger = yes
					count >= 1
				}
			}
			random_character_doctrine = {
				knowledge_filter = unknown
				limit = { passive_rite_learning_doctrine_is_learnable_trigger = yes }
				save_scope_as = pam_sf_revelation_doctrine
			}
		}
	}
}

# Grant knowledge of whichever subject pam_secular_faith_study_revelation_select_effect picked.
scripted_effect pam_secular_faith_study_revelation_learn_effect = {
	if = {
		limit = { exists = scope:pam_sf_revelation_tenet }
		add_known_tenet = scope:pam_sf_revelation_tenet
	}
	else_if = {
		limit = { exists = scope:pam_sf_revelation_doctrine }
		add_known_doctrine = scope:pam_sf_revelation_doctrine
	}
}

pam_secular_faith_events.0005 = {
	type = character_event
	title = pam_secular_faith_events.0005.t
	desc = {
		desc = pam_secular_faith_events.0005.desc_intro
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:pam_sf_revelation_tenet }
				desc = pam_secular_faith_events.0005.desc_tenet
			}
			triggered_desc = {
				trigger = { exists = scope:pam_sf_revelation_doctrine }
				desc = pam_secular_faith_events.0005.desc_doctrine
			}
		}
		desc = pam_secular_faith_events.0005.desc_end
	}
	theme = christian
	override_background = study
	widgets = {
		widget = { gui = event_window_widget_vfx_background_flickering_candlelight_dark container = foreground_shader_vfx_container }
		widget = { gui = event_window_widget_vfx_left_character_flickering_candlelight_dark container = foreground_shader_vfx_container }
	}

	left_portrait = {
		character = root
		animation = reading
		camera = camera_event_right
	}

	cooldown = { years = 10 }

	trigger = {
		pam_secular_faith_clergy_ok_actor_trigger = yes
		# At least one foreign tenet or learnable doctrine must remain unknown for there to be a revelation.
		OR = {
			any_character_tenet = {
				knowledge_filter = unknown
				count >= 1
			}
			any_character_doctrine = {
				knowledge_filter = unknown
				passive_rite_learning_doctrine_is_learnable_trigger = yes
				count >= 1
			}
		}
		OR = {
			AND = {
				learning >= high_skill_rating
				NOR = { # Cannot read
					government_has_flag = government_is_tribal
					government_has_flag = government_is_nomadic
				}
			}
			has_focus_or_focus_trait_trigger = { FOCUS = learning_theology_focus }
			has_trait = lifestyle_mystic
			has_trait = lifestyle_scholar
		}
		NOT = { has_trait = blind }
	}

	immediate = {
		pam_secular_faith_study_revelation_select_effect = yes
	}

	option = { # Set it down while it is still fresh
		name = pam_secular_faith_events.0005.a
		pam_secular_faith_study_revelation_learn_effect = yes
		add_scholar_trait_or_xp_effect = { VALUE = 5 }
		stress_and_fulfillment_impact = {
			base = minor_stress_loss
			zealous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = { has_trait = zealous factor = 0 }
		}
	}

	option = { # Set it down as a scholar would
		name = pam_secular_faith_events.0005.b
		show_as_unavailable = { always = yes }
		trigger = {
			has_trait = lifestyle_scholar
		}
		pam_secular_faith_study_revelation_learn_effect = yes
		add_learning_lifestyle_xp = major_lifestyle_xp
		add_scholar_trait_or_xp_effect = { VALUE = 20 }
		ai_chance = {
			base = 1000
		}
	}

	option = { # Pray the strange thought away
		name = pam_secular_faith_events.0005.c
		add_piety = minor_piety_gain
		stress_and_fulfillment_impact = {
			cynical = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = { has_trait = cynical factor = 0 }
		}
	}
}

##########################################################################################
# 0006 - Bones of a Saint (the relic-seller)
##########################################################################################
scripted_trigger pam_sf_relic_seller_valid_trigger = {
	is_available_healthy_ai_adult = yes
	has_no_particular_noble_roots_trigger = yes
	faith = root.faith
}

pam_secular_faith_events.0006 = {
	type = character_event
	title = pam_secular_faith_events.0006.t
	desc = pam_secular_faith_events.0006.desc
	theme = christian
	override_background = market

	left_portrait = {
		character = root
		animation = contemplating
	}
	right_portrait = {
		character = scope:relic_seller
		animation = beg
	}

	cooldown = { years = 50 }

	trigger = {
		pam_secular_faith_christian_actor_trigger = yes
		gold > 0
	}

	immediate = {
		if = {
			limit = {
				any_pool_character = {
					province = root.location
					pam_sf_relic_seller_valid_trigger = yes
				}
			}
			random_pool_character = {
				province = root.location
				limit = { pam_sf_relic_seller_valid_trigger = yes }
				save_scope_as = relic_seller
			}
		}
		else = {
			create_character = {
				location = root.capital_province
				template = monk_character_template
				faith = root.faith
				rite = root.rite
				culture = root.culture
				save_scope_as = relic_seller
				after_creation = {
					add_character_flag = created
				}
			}
		}
	}

	option = { # Appraise it as a scholar - a learned eye may judge it a far finer piece
		name = pam_secular_faith_events.0006.a
		trigger = {
			has_trait = lifestyle_scholar
		}
		show_as_unavailable = { always = yes }
		custom_tooltip = pam_sf_examine_relic_tt
		pay_short_term_gold = {
			target = scope:relic_seller
			gold = minor_gold_value
		}
		add_scholar_trait_or_xp_effect = { VALUE = 20 }
		hidden_effect = {
			random_list = {
				50 = { # A plain relic, like any other
					modifier = { factor = 0.5 learning >= 12 }
					pam_create_saint_fingerbone_relic_effect = { OWNER = root QUALITY = 10 WEALTH = 10 }
				}
				35 = { # A piece of some renown
					modifier = {
						add = learning
					}
					pam_create_saint_fingerbone_relic_effect = { OWNER = root QUALITY = 40 WEALTH = 20 }
				}
				10 = { # A famed relic, its provenance compelling
					modifier = {
						add = learning
					}
					pam_create_saint_fingerbone_relic_effect = { OWNER = root QUALITY = 80 WEALTH = 55 }
				}
				5 = { # An illustrious treasure - the find of a lifetime
					modifier = {
						add = learning
					}
					pam_create_saint_fingerbone_relic_effect = { OWNER = root QUALITY = 95 WEALTH = 90 }
				}
			}
		}
		ai_chance = {
			base = 100
		}
	}

	option = { # Buy it on faith - always a humble, common relic
		name = pam_secular_faith_events.0006.b
		custom_tooltip = pam_sf_acquire_relic_tt
		pay_short_term_gold = {
			target = scope:relic_seller
			gold = minor_gold_value
		}
		pam_create_saint_fingerbone_relic_effect = { OWNER = root QUALITY = 10 WEALTH = 10 }
		add_piety = medium_piety_gain
		stress_and_fulfillment_impact = {
			cynical = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = cynical
					has_trait = paranoid
				}
			}
		}
	}

	option = { # Send the peddler away
		name = pam_secular_faith_events.0006.c
		ai_chance = {
			base = 100
		}
	}

	after = {
		scope:relic_seller = {
			silent_disappearance_ai_if_created_effect = yes
		}
	}
}

##########################################################################################
# 0007 - Arrogant Bishop
##########################################################################################
pam_secular_faith_events.0007 = {
	type = character_event
	title = pam_secular_faith_events.0007.t
	desc = pam_secular_faith_events.0007.desc
	theme = christian
	override_background = council_chamber

	left_portrait = {
		character = root
		animation = anger
	}
	right_portrait = {
		character = scope:defiant_bishop
		animation = priest_corrupt
	}

	cooldown = { years = 10 }

	trigger = {
		pam_secular_faith_christian_actor_trigger = yes
		any_vassal = {
			government_has_flag = government_is_theocracy
			faith = root.faith
			is_available_ai_adult = yes
			opinion = {
				target = root
				value < 20
			}
			OR = {
				has_trait = arrogant
				has_trait = ambitious
			}
			NOR = {
				has_trait = humble
				has_trait = calm
			}
		}
	}

	immediate = {
		random_vassal = {
			limit = {
				government_has_flag = government_is_theocracy
				faith = root.faith
				is_available_ai_adult = yes
				opinion = {
					target = root
					value < 20
				}
				OR = {
					has_trait = arrogant
					has_trait = ambitious
				}
				NOR = {
					has_trait = humble
					has_trait = calm
				}
			}
			save_scope_as = defiant_bishop
		}
	}

	option = { # Dazzle the bishop with religious knowledge
		name = pam_secular_faith_events.0007.a
		trigger = {
			has_trait = lifestyle_scholar
		}
		show_as_unavailable = {
			always = yes
		}
		add_prestige = medium_prestige_gain
		add_piety = medium_piety_gain
		scope:defiant_bishop = {
			add_opinion = {
				modifier = grateful_opinion
				opinion = 50
				target = root
			}
		}
		if = {
			limit = { can_add_hook = { target = scope:defiant_bishop type = favor_hook } }
			add_hook = {
				type = favor_hook
				target = scope:defiant_bishop
			}
		}
		stress_and_fulfillment_impact = {
			arrogant = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = { has_trait = arrogant factor = 0 }
		}
	}

	option = { # Let the smug clergy get to you
		name = pam_secular_faith_events.0007.b
		scope:defiant_bishop = {
			add_prestige = medium_prestige_gain
			add_opinion = {
				modifier = grateful_opinion
				opinion = 50
				target = root
			}
		}
		add_piety = medium_piety_gain
		add_prestige = medium_prestige_loss
		ai_chance = {
			base = 100
		}
	}

	option = { # Send them packing
		name = pam_secular_faith_events.0007.c
		add_prestige = minor_prestige_gain
		add_piety = minor_piety_loss
		scope:defiant_bishop = {
			add_opinion = {
				target = root
				modifier = annoyed_opinion
				opinion = -20
			}
		}
		stress_and_fulfillment_impact = {
			humble = minor_stress_impact_gain
			patient = minor_stress_impact_gain
			calm = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				OR = {
					has_trait = humble
					has_trait = patient
					has_trait = calm
				}
				factor = 0
			}
		}
	}
}

##########################################################################################
# 0008 - The Weight of Sin (guilt after a deed)
##########################################################################################
pam_secular_faith_events.0008 = {
	type = character_event
	title = pam_secular_faith_events.0008.t
	desc = pam_secular_faith_events.0008.desc
	theme = christian
	override_background = temple
	widgets = {
		widget = { gui = event_window_widget_vfx_background_flickering_candlelight_dark container = foreground_shader_vfx_container }
		widget = { gui = event_window_widget_vfx_left_character_flickering_candlelight_dark container = foreground_shader_vfx_container }
		widget = { gui = event_window_widget_vfx_right_character_flickering_candlelight_dark container = foreground_shader_vfx_container }
	}

	left_portrait = {
		character = scope:confessor
		animation = divine_gesture_3
		camera = camera_event_left_to_the_left
	}
	right_portrait = {
		character = root
		animation = mental_anguish
	}

	cooldown = { years = 5 }

	trigger = {
		pam_secular_faith_christian_actor_trigger = yes
		cp:councillor_court_chaplain ?= {
			is_available_ai_adult = yes
		}
		any_character_trait = {
			has_trait_category = personality
			root.rite = { trait_is_sin_rite = prev }
		}
	}

	immediate = {
		cp:councillor_court_chaplain = { save_scope_as = confessor }
		# Pick one sinful personality trait so the text and the penance name the same sin
		random_character_trait = {
			limit = {
				has_trait_category = personality
				save_temporary_scope_as = temp_trait
				root.rite = { trait_is_sin_rite = scope:temp_trait }
			}
			save_scope_as = penance_sin
		}
	}

	option = { # Take up the penance the chaplain suggests
		name = pam_secular_faith_events.0008.a
		change_spiritual_fulfillment = minor_spiritual_fulfillment_value
		pam_apply_penance_modifier_effect = yes
		stress_and_fulfillment_impact = {
			base = medium_stress_impact_gain
			cynical = minor_stress_impact_gain
			humble = minor_stress_impact_loss
		}
		ai_chance = {
			base = 100
			modifier = { has_trait = cynical factor = 0 }
		}
	}

	option = { # Sit with it; do nothing
		name = pam_secular_faith_events.0008.b
		stress_and_fulfillment_impact = {
			humble = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = { has_trait = humble factor = 0 }
		}
	}
}

##########################################################################################
# 0009 - A Christlike Stranger (Christ-in-disguise)
##########################################################################################
pam_secular_faith_events.0009 = {
	type = character_event
	title = pam_secular_faith_events.0009.t
	desc = pam_secular_faith_events.0009.desc
	theme = christian
	override_background = { reference = courtyard }
	override_effect_2d = { reference = rain }

	left_portrait = {
		character = root
		animation = contemplating
	}
	right_portrait = {
		character = scope:stranger
		animation = beg
	}

	cooldown = { years = 100 }

	trigger = {
		pam_secular_faith_christian_actor_trigger = yes
		is_ai = no
	}

	immediate = {
		create_character = {
			location = root.capital_province
			template = pam_sf_christlike_stranger_character
			faith = root.faith
			rite = root.rite
			culture = root.culture
			save_scope_as = stranger
			after_creation = {
				random_list = {
					100 = {
						# Character is of average weight, nothing happens
					}
					25 = {
						change_current_weight = -25
					}
					25 = {
						change_current_weight = -75
					}
					25 = {
						change_current_weight = -100
					}
					5 = {
						change_current_weight = -200
					}
				}
				add_character_flag = peasant_outfit
				add_character_flag = created
			}
		}
	}

	option = { # Welcome them into your hall
		name = pam_secular_faith_events.0009.a
		add_courtier = scope:stranger
		hidden_effect = {
			scope:stranger = { remove_character_flag = created }
		}
		trigger_event = {
			id = pam_secular_faith_events.0010
			days = 30
		}
		stress_and_fulfillment_impact = {
			paranoid = medium_stress_impact_gain
			callous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = paranoid
					has_trait = callous
				}
			}
		}
	}

	option = { # Send them off with bread and a blessing
		name = pam_secular_faith_events.0009.b
		add_piety = minor_piety_gain
		remove_short_term_gold = 1
		hidden_effect = {
			scope:stranger = { silent_disappearance_effect = yes }
		}
		stress_and_fulfillment_impact = {
			trusting = medium_stress_impact_gain
			generous = medium_stress_impact_gain
			compassionate = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = trusting
					has_trait = generous
					has_trait = compassionate
				}
			}
		}
	}
}

##########################################################################################
# 0010 - Who Came In From the Cold (the stranger revealed) - scheduled follow-up to 0009
##########################################################################################
pam_secular_faith_events.0010 = {
	type = character_event
	title = pam_secular_faith_events.0010.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { has_variable = pam_sf_stranger_blessed }
				desc = pam_secular_faith_events.0010.desc_blessed
			}
			triggered_desc = {
				trigger = { has_variable = pam_sf_stranger_thief }
				desc = pam_secular_faith_events.0010.desc_thief
			}
		}
	}
	theme = christian
	override_background = sitting_room

	left_portrait = {
		character = root
		triggered_animation = {
			trigger = { has_variable = pam_sf_stranger_blessed }
			animation = prayer_crossing
		}
		animation = mental_anguish
		camera = camera_event_left_to_the_left
	}
	right_portrait = {
		character = scope:stranger
		triggered_animation = {
			trigger = { root = { has_variable = pam_sf_stranger_blessed } }
			animation = zealous_superior
		}
		animation = eccentric
	}

	widgets = {
		widget = { gui = event_window_widget_vfx_background_flickering_candlelight_dark container = foreground_shader_vfx_container }
		widget = { gui = event_window_widget_vfx_left_character_flickering_candlelight_dark container = foreground_shader_vfx_container }
		widget = { gui = event_window_widget_vfx_right_character_flickering_candlelight_dark container = foreground_shader_vfx_container }
	}

	trigger = {
		exists = scope:stranger
		scope:stranger = {
			is_physically_able = yes
			is_courtier_of = root
		}
	}

	immediate = {
		scope:stranger = {
			remove_character_flag = peasant_outfit
		}
		# A devout, learned host is likelier to have sheltered a true saint than let in a thief.
		random_list = {
			50 = {
				modifier = {
					add = {
						value = root.piety_level
						multiply = 10
					}
					piety_level >= 1
				}
				modifier = {
					add = {
						value = root.learning
						multiply = 2
					}
				}
				set_variable = pam_sf_stranger_blessed
			}
			50 = {
				set_variable = pam_sf_stranger_thief
				hidden_effect = {
					scope:stranger = {
						select_and_move_to_pool_effect = yes
					}
				}
			}
		}
	}

	option = { # The stranger proves a saintly paragon
		name = pam_secular_faith_events.0010.a
		trigger = { has_variable = pam_sf_stranger_blessed }
		scope:stranger = {
			hidden_effect = {
				remove_any_education_traits_effect = yes
			}
			add_trait = shrewd
			add_trait = education_learning_5
			add_trait = theologian
			add_learning_skill = max_template_high_skill
			add_stewardship_skill = max_template_high_skill
			add_diplomacy_skill = max_template_high_skill
			hidden_effect = {
				force_character_skill_recalculation = yes
			}
			add_opinion = {
				modifier = grateful_opinion
				opinion = 30
				target = root
			}
		}
		add_hook = {
			type = loyalty_hook
			target = scope:stranger
		}
		change_spiritual_fulfillment = medium_spiritual_fulfillment_value
		remove_variable = pam_sf_stranger_blessed
		stress_and_fulfillment_impact = {
			trusting = medium_stress_impact_loss
		}
		ai_chance = {
			base = 100
		}
	}

	option = { # The stranger proves a thief, already fled
		name = pam_secular_faith_events.0010.b
		trigger = { has_variable = pam_sf_stranger_thief }
		remove_short_term_gold = medium_gold_value
		add_stress = minor_stress_gain
		change_spiritual_fulfillment = minor_spiritual_fulfillment_loss
		scope:stranger = {
			hidden_effect = {
				remove_any_education_traits_effect = yes
			}
			add_gold = root.medium_gold_value
			add_trait = shrewd
			add_trait = education_intrigue_5
			add_intrigue_skill = max_template_high_skill
			hidden_effect = {
				force_character_skill_recalculation = yes
			}
		}
		remove_variable = pam_sf_stranger_thief
		stress_and_fulfillment_impact = {
			trusting = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = { has_trait = trusting factor = 0 }
		}
	}
}

##########################################################################################
# 0011 - The Penitents (a flagellant procession reaches the capital)
##########################################################################################
scripted_trigger pam_sf_penitent_pool_valid_trigger = {
	is_available_healthy_ai_adult = yes
	has_no_particular_noble_roots_trigger = yes
	faith = root.faith
}

pam_secular_faith_events.0011 = {
	type = character_event
	title = pam_secular_faith_events.0011.t
	desc = pam_secular_faith_events.0011.desc
	theme = christian
	override_background = courtyard

	left_portrait = {
		character = scope:lead_penitent
		animation = self_flagellation
		camera = camera_event_very_right
	}
	right_portrait = {
		character = scope:follower_penitent
		animation = whipping
		camera = camera_event_very_right_fov35
	}

	cooldown = { years = 30 }

	trigger = {
		pam_secular_faith_christian_actor_trigger = yes
		is_landed = yes
		exists = capital_county
		rite = {
			has_at_least_tenet_status = {
				tenet = tenet_mortification_of_the_flesh
				status = permitted
			}
		}
		any_pool_character = {
			province = root.location
			pam_sf_penitent_pool_valid_trigger = yes
			rite = {
				has_at_least_tenet_status = {
					tenet = tenet_mortification_of_the_flesh
					status = permitted
				}
			}
			count >= 2
		}
	}

	immediate = {
		random_pool_character = {
			province = root.location
			limit = { pam_sf_penitent_pool_valid_trigger = yes }
			save_scope_as = lead_penitent
		}
		random_pool_character = {
			province = root.location
			limit = {
				pam_sf_penitent_pool_valid_trigger = yes
				this != scope:lead_penitent
			}
			save_scope_as = follower_penitent
		}
		hidden_effect = {
			scope:lead_penitent = {
				add_trait = flagellant
				increase_wounds_effect = { REASON = whipping }
				add_character_flag = peasant_outfit
				add_character_flag = no_hat
			}
			scope:follower_penitent = {
				add_trait = flagellant
				increase_wounds_effect = { REASON = whipping }
				add_character_flag = peasant_outfit
				add_character_flag = no_hat
			}
		}
		capital_county = {
			change_county_control = -10
			add_county_modifier = {
				modifier = pam_sf_flagellant_cults_county_modifier
				years = 10
			}
		}
	}

	option = { # Study the phenomenon deeper
		name = pam_secular_faith_events.0011.a
		trigger = {
			has_trait = lifestyle_scholar
		}
		show_as_unavailable = {
			NOT = {
				knows_tenet = tenet_exaltation_of_pain
			}
		}
		add_scholar_trait_or_xp_effect = { VALUE = 10 }
		if = {
			limit = {
				NOT = {
					knows_tenet = tenet_mortification_of_the_flesh
				}
			}
			add_known_tenet = tenet_mortification_of_the_flesh
			pam_secular_faith_seed_tenet_message_effect = { TENET = tenet:tenet_mortification_of_the_flesh }
		}
		add_known_tenet = tenet_exaltation_of_pain
		pam_secular_faith_seed_tenet_message_effect = { TENET = tenet:tenet_exaltation_of_pain }
		stress_and_fulfillment_impact = {
			arrogant = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = { has_trait = arrogant factor = 0 }
		}
	}

	option = { # Join them
		name = pam_secular_faith_events.0011.b
		if = {
			limit = {
				NOT = {
					knows_tenet = tenet_mortification_of_the_flesh
				}
			}
			add_known_tenet = tenet_mortification_of_the_flesh
			pam_secular_faith_seed_tenet_message_effect = { TENET = tenet:tenet_mortification_of_the_flesh }
		}
		if = {
			limit = {
				NOT = {
					has_trait = flagellant
				}
			}
			add_trait = flagellant
		}
		add_piety = massive_piety_gain
		change_spiritual_fulfillment = medium_spiritual_fulfillment_value
		increase_wounds_effect = { REASON = whipping }
		add_courtier = scope:lead_penitent
		add_courtier = scope:follower_penitent
		stress_and_fulfillment_impact = {
			base = medium_stress_impact_gain
			humble = minor_stress_impact_loss
			zealous = minor_stress_impact_loss
			cynical = medium_stress_impact_gain
			arrogant = medium_stress_impact_gain
		}
		ai_chance = {
			base = 5
			modifier = {
				OR = {
					has_trait = cynical
					has_trait = arrogant
					has_trait = calm
				}
				factor = 0
			}
		}
	}

	option = { # Drive them off as fanatics
		name = pam_secular_faith_events.0011.c
		capital_county = {
			remove_county_modifier = pam_sf_flagellant_cults_county_modifier
			change_county_control = 10
		}
		add_prestige = minor_prestige_gain
		stress_and_fulfillment_impact = {
			flagellant = massive_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = { has_trait = flagellant factor = 0 }
		}
	}
}

##########################################################################################
# 0012 - Blessing of Arms (peacetime consecration)
##########################################################################################
pam_secular_faith_events.0012 = {
	type = character_event
	title = pam_secular_faith_events.0012.t
	desc = pam_secular_faith_events.0012.desc
	theme = christian
	override_background = temple
	widgets = {
		widget = {
			gui = event_window_widget_vfx_godray
			container = background_shader_vfx_container
		}
	}

	left_portrait = {
		character = root
		animation = marshal
		camera = camera_event_very_left
	}
	right_portrait = {
		character = scope:chaplain
		animation = situla
		camera = camera_event_right_pointing_right
	}

	cooldown = { years = 10 }

	trigger = {
		pam_secular_faith_christian_actor_trigger = yes
		is_at_war = no
		exists = house
		cp:councillor_court_chaplain ?= {
			is_available_ai_adult = yes
			ai_has_warlike_personality = yes
		}
	}

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

	option = { # Consecrate your arms to the warrior-saint
		name = pam_secular_faith_events.0012.a
		add_piety = minor_piety_gain
		add_character_modifier = {
			modifier = pam_sf_consecrated_arms_modifier
			years = 15
		}
		ai_chance = {
			base = 100
			modifier = { has_trait = craven factor = 0 }
		}
	}

	option = { # Knight your heir at the rite
		name = pam_secular_faith_events.0012.b
		add_piety = minor_piety_gain
		dynasty = { add_dynasty_prestige = miniscule_dynasty_prestige_gain }
		ai_chance = {
			base = 100
		}
	}

	option = { # Keep it modest
		name = pam_secular_faith_events.0012.c
		change_spiritual_fulfillment = minor_spiritual_fulfillment_value
		stress_and_fulfillment_impact = {
			arrogant = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = { has_trait = arrogant factor = 0 }
		}
	}
}

##########################################################################################
# 0013 - A Death Foretold (stage 1: the warning)
##########################################################################################
scripted_trigger pam_sf_prophet_valid_trigger = {
	is_available_healthy_ai_adult = yes
	has_no_particular_noble_roots_trigger = yes
	faith = root.faith
}

scripted_trigger pam_sf_doomed_soul_valid_trigger = {
	is_available_ai_adult = yes
	OR = {
		is_old_character = yes
		has_any_illness = yes
		health <= poor_health
	}
	trigger_if = {
		limit = { exists = root.primary_heir }
		NOT = { this = root.primary_heir }
	}
	trigger_if = {
		limit = { exists = root.primary_spouse }
		NOT = { this = root.primary_spouse }
	}
}

pam_secular_faith_events.0013 = {
	type = character_event
	title = pam_secular_faith_events.0013.t
	desc = pam_secular_faith_events.0013.desc
	theme = christian
	override_background = throne_room

	left_portrait = {
		character = scope:doomed_soul
		animation = fear
		camera = camera_event_very_left
	}
	right_portrait = {
		character = scope:prophet
		animation = condemnation
		camera = camera_event_very_right_fov35
	}

	cooldown = { years = 100 }

	trigger = {
		is_ai = no # Prevent too many inspirations
		pam_secular_faith_christian_actor_trigger = yes
		any_pool_character = {
			province = root.location
			pam_sf_prophet_valid_trigger = yes
		}
		any_courtier = {
			pam_sf_doomed_soul_valid_trigger = yes
		}
	}

	immediate = {
		random_pool_character = {
			province = root.location
			limit = { pam_sf_prophet_valid_trigger = yes }
			hidden_effect = {
				if = {
					limit = {
						NOT = {
							has_trait = devoted
						}
					}
					add_trait = devoted
				}
			}
			hidden_effect = {
				if = {
					limit = {
						NOT = {
							has_trait = possessed_1
						}
					}
					add_trait = possessed_1
				}
			}
			save_scope_as = prophet
		}
		random_courtier = {
			limit = {
				pam_sf_doomed_soul_valid_trigger = yes
				NOT = { this = scope:prophet }
			}
			save_scope_as = doomed_soul
		}
	}

	option = { # Believe him - see to their soul
		name = pam_secular_faith_events.0013.a
		flavor = prophecy_foretold_tt
		save_scope_value_as = { name = prophet_stance value = flag:heeded }
		trigger_event = { id = pam_secular_faith_events.0014 days = 30 }
		stress_and_fulfillment_impact = {
			zealous = minor_stress_impact_loss
			cynical = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = { has_trait = cynical factor = 0 }
		}
	}

	option = { # Mock him and cast him out
		name = pam_secular_faith_events.0013.b
		flavor = prophecy_foretold_2_tt
		save_scope_value_as = { name = prophet_stance value = flag:mocked }
		trigger_event = { id = pam_secular_faith_events.0014 days = 30 }
		stress_and_fulfillment_impact = {
			cynical = minor_stress_impact_loss
			zealous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = { has_trait = zealous factor = 0 }
		}
	}
}

##########################################################################################
# 0014 - Prophetic Reckoning (A Death Foretold stage 2) - scheduled follow-up to 0013
##########################################################################################
pam_secular_faith_events.0014 = {
	type = character_event
	title = pam_secular_faith_events.0014.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:doomed_soul = { is_alive = no } }
				desc = pam_secular_faith_events.0014.desc_fulfilled
			}
			triggered_desc = {
				trigger = { always = yes }
				desc = pam_secular_faith_events.0014.desc_failed
			}
		}
		triggered_desc = {
			trigger = {
				OR = {
					AND = {
						scope:prophet_stance = flag:heeded
						scope:doomed_soul = { is_alive = yes }
					}
					AND = {
						scope:prophet_stance = flag:mocked
						scope:doomed_soul = { is_alive = no }
					}
				}
			}
			desc = pam_secular_faith_events.0014.desc_wrong_prediction
		}
	}
	theme = christian
	override_background = throne_room

	left_portrait = {
		character = root
		triggered_animation = {
			trigger = {
				scope:doomed_soul ?= {
					is_alive = no
				}
			}
			animation = interested
		}
		animation = dismissal
	}

	right_portrait = {
		character = scope:prophet
		triggered_animation = {
			trigger = {
				scope:doomed_soul ?= {
					is_alive = no
				}
			}
			animation = zealous_superior
		}
		animation = priest_corrupt
	}

	lower_center_portrait = {
		character = scope:doomed_soul
		triggered_animation = {
			trigger = {
				scope:doomed_soul ?= {
					is_alive = no
				}
			}
			animation = dead
		}
		animation = happiness
	}

	trigger = {
		exists = scope:prophet
		exists = scope:doomed_soul
		exists = scope:prophet_stance
	}

	immediate = {
		hidden_effect = {
			scope:doomed_soul = {
				if = {
					limit = {
						is_alive = yes
					}
					random = {
						chance = {
							value = 25
							if = {
								limit = {
									scope:prophet_stance = flag:heeded
								}
								add = 50
							}
						}
						death = { death_reason = death_natural_causes }
					}
				}
			}
		}
	}

	# Heeded, and the doom came as foretold, gain an inspiration
	option = {
		name = pam_secular_faith_events.0014.a
		trigger = {
			scope:prophet_stance = flag:heeded
			scope:doomed_soul = { is_alive = no }
		}
		add_piety = medium_piety_gain
		add_courtier = scope:prophet
		custom_tooltip = gains_religious_inspiration_tt
		scope:prophet = {
			add_learning_skill = 12
			hidden_effect = {
				force_character_skill_recalculation = yes
			}
			create_inspiration = religious_inspiration
		}
		create_character_memory = {
			type = pam_sf_prophecy_fulfilled_memory
			participants = {
				prophet = scope:prophet
				doomed = scope:doomed_soul
			}
		}
		ai_chance = { base = 100 }
	}

	# Heeded, and the doom came as foretold, gain SF
	option = {
		name = pam_secular_faith_events.0014.b
		trigger = {
			scope:prophet_stance = flag:heeded
			scope:doomed_soul = { is_alive = no }
		}
		change_spiritual_fulfillment = minor_spiritual_fulfillment_value
		create_character_memory = {
			type = pam_sf_prophecy_fulfilled_memory
			participants = {
				prophet = scope:prophet
				doomed = scope:doomed_soul
			}
		}
		ai_chance = { base = 100 }
	}

	# Heeded, but the death didn't happen
	option = {
		name = pam_secular_faith_events.0014.c
		trigger = {
			scope:prophet_stance = flag:heeded
			scope:doomed_soul = { is_alive = yes }
		}
		change_spiritual_fulfillment = minor_spiritual_fulfillment_loss
		add_stress = minor_stress_gain
		ai_chance = { base = 100 }
	}

	# Mocked, and the doom fell all the same
	option = {
		name = pam_secular_faith_events.0014.d
		trigger = {
			scope:prophet_stance = flag:mocked
			scope:doomed_soul = { is_alive = no }
		}
		change_spiritual_fulfillment = minor_spiritual_fulfillment_loss
		add_stress = minor_stress_gain
		create_character_memory = {
			type = pam_sf_prophecy_fulfilled_memory
			participants = {
				prophet = scope:prophet
				doomed = scope:doomed_soul
			}
		}
		ai_chance = { base = 100 }
	}

	# Mocked, and the doom never came
	option = {
		name = pam_secular_faith_events.0014.e
		trigger = {
			scope:prophet_stance = flag:mocked
			scope:doomed_soul = { is_alive = yes }
		}
		add_piety = medium_piety_gain
		add_prestige = medium_prestige_gain
		ai_chance = { base = 100 }
	}
}

##########################################################################################
# 0015 - The Weeping Icon
##########################################################################################
pam_secular_faith_events.0015 = {
	type = character_event
	title = pam_secular_faith_events.0015.t
	desc = pam_secular_faith_events.0015.desc
	theme = christian
	override_background = temple_church
	override_effect_2d = { reference = legend_glow }
	widgets = {
		widget = {
			gui = event_window_widget_vfx_godray
			container = background_shader_vfx_container
		}
	}

	left_portrait = {
		character = scope:chaplain
		animation = divine_ecstasy
	}
	right_portrait = {
		character = root
		animation = prayer_standing_eyes
	}

	cooldown = { years = 10 }

	trigger = {
		pam_secular_faith_christian_actor_trigger = yes
		cp:councillor_court_chaplain ?= {
			is_available_ai_adult = yes
		}
		rite = { NOT = { rite_has_tenet = tenet_aniconism } }
		capital_county ?= {
			any_county_province = { has_holding_type = church_holding }
		}
	}

	immediate = {
		cp:councillor_court_chaplain = { save_scope_as = chaplain }
		capital_county = {
			random_county_province = {
				limit = { has_holding_type = church_holding }
				barony = { save_scope_as = miracle_church }
			}
		}
	}

	option = { # Investigate it coolly
		name = pam_secular_faith_events.0015.a
		flavor = no_miracles_tt
		trigger = {
			learning >= 12
		}
		show_as_unavailable = { always = yes }
		add_scholar_trait_or_xp_effect = { VALUE = 20 }
		if = {
			limit = { can_add_hook = { target = scope:chaplain type = weak_blackmail_hook_no_secret } }
			add_hook = {
				type = weak_blackmail_hook_no_secret
				target = scope:chaplain
			}
		}
		ai_chance = {
			base = 100
		}
	}

	option = { # Proclaim it and open your chapel to pilgrims
		name = pam_secular_faith_events.0015.b
		scope:miracle_church.title_province = {
			add_province_modifier = {
				modifier = pam_sf_site_of_miracle_county_modifier
				years = 15
			}
		}
		add_piety = major_piety_gain
		ai_chance = {
			base = 100
		}
	}

	option = { # Keep it as a private grace
		name = pam_secular_faith_events.0015.c
		change_spiritual_fulfillment = medium_spiritual_fulfillment_value
		add_character_modifier = {
			modifier = pam_sf_grace_modifier
			years = 15
		}
		scope:chaplain = {
			add_opinion = {
				target = root
				modifier = upset_opinion
				opinion = -10
			}
		}
		stress_and_fulfillment_impact = {
			arrogant = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = { has_trait = arrogant factor = 0 }
		}
	}

	option = { # Nonsense
		name = pam_secular_faith_events.0015.d
		add_prestige = miniscule_prestige_gain
		stress_and_fulfillment_impact = {
			humble = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = { has_trait = humble factor = 0 }
		}
	}
}

##########################################################################################
# 0016 - A Price for the Pulpit (simony: a wanderer buys the realm-priest office)
##########################################################################################
scripted_effect pam_sf_install_bought_priest_effect = {
	hidden_effect = {
		add_courtier = scope:candidate
	}
	assign_councillor_type = {
		type = councillor_court_chaplain
		target = scope:candidate
		remove_existing_councillor = yes
	}
	if = {
		limit = { can_add_hook = { target = scope:candidate type = favor_hook } }
		add_hook = {
			type = favor_hook
			target = scope:candidate
		}
	}
	if = {
		limit = { can_set_relation_rival_trigger = { CHARACTER = scope:old_realm_priest } }
		set_relation_potential_rival = {
			target = scope:old_realm_priest
			reason = pam_sf_rival_bought_office
		}
	}
}

scripted_trigger pam_sf_bought_priest_candidate_valid_trigger = {
	is_available_healthy_ai_adult = yes
	faith = root.faith
	root.faith = { has_allowed_gender_for_clergy = prev }
	can_be_court_chaplain_trigger = { COURT_OWNER = root }
}

pam_secular_faith_events.0016 = {
	type = character_event
	title = pam_secular_faith_events.0016.t
	desc = {
		desc = pam_secular_faith_events.0016.desc_intro
		first_valid = {
			triggered_desc = {
				trigger = {
					rite = { rite_has_tenet = tenet_simony }
				}
				desc = pam_secular_faith_events.0016.desc_sanctioned
			}
			triggered_desc = {
				trigger = { always = yes }
				desc = pam_secular_faith_events.0016.desc_sinful
			}
		}
	}
	theme = christian
	override_background = council_chamber

	left_portrait = {
		character = root
		animation = contemplating
	}
	right_portrait = {
		character = scope:candidate
		animation = bribing
		camera = camera_event_very_right_fov35
	}
	lower_center_portrait = {
		character = scope:old_realm_priest
		animation = divine_gesture_3
	}

	cooldown = { years = 10 }

	trigger = {
		pam_secular_faith_christian_actor_trigger = yes
		is_landed = yes
		cp:councillor_court_chaplain ?= {
			is_available_ai_adult = yes
			is_ruler = no
		}
		any_pool_character = {
			province = root.location
			pam_sf_bought_priest_candidate_valid_trigger = yes
		}
	}

	immediate = {
		cp:councillor_court_chaplain = { save_scope_as = old_realm_priest }
		random_pool_character = {
			province = root.location
			limit = { pam_sf_bought_priest_candidate_valid_trigger = yes }
			weight = {
				base = 1
				modifier = {
					add = gold
					gold >= 1
				}
				modifier = {
					add = {
						value = learning
						multiply = 3
					}
					learning >= 8
				}
			}
			save_scope_as = candidate
			hidden_effect = {
				if = {
					limit = {
						gold < root.major_gold_value
					}
					add_gold = root.major_gold_value
				}
			}
		}
	}

	option = { # Forbidden simony - take the bribe and install him anyway
		name = pam_secular_faith_events.0016.a
		trigger = {
			NOR = {
				rite = { rite_has_tenet = tenet_simony }
				has_personal_tenet = tenet_simony
			}
		}
		scope:candidate = {
			pay_short_term_gold = {
				target = root
				gold = root.major_gold_value
			}
		}
		pam_sf_install_bought_priest_effect = yes
		add_piety = medium_piety_loss
		change_spiritual_fulfillment = minor_spiritual_fulfillment_loss
		stress_and_fulfillment_impact = {
			just = medium_stress_impact_gain
			humble = medium_stress_impact_gain
			generous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				OR = {
					has_trait = just
					has_trait = humble
					has_trait = generous
				}
				factor = 0
			}
		}
	}

	option = { # Sanctioned simony - the rite or a personal tenet permits the sale
		name = pam_secular_faith_events.0016.b
		trigger = {
			OR = {
				rite = { rite_has_tenet = tenet_simony }
				has_personal_tenet = tenet_simony
			}
		}
		scope:candidate = {
			pay_short_term_gold = {
				target = root
				gold = root.major_gold_value
			}
		}
		pam_sf_install_bought_priest_effect = yes
		stress_and_fulfillment_impact = {
			generous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = { has_trait = generous factor = 0 }
		}
	}

	option = { # Refuse the coin and keep your own priest
		name = pam_secular_faith_events.0016.c
		add_prestige = minor_prestige_gain
		if = {
			limit = {
				NOT = {
					rite = { rite_has_tenet = tenet_simony }
				}
			}
			add_piety = minor_piety_gain
		}
		stress_and_fulfillment_impact = {
			greedy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = { has_trait = greedy factor = 0 }
		}
	}
}

##########################################################################################
# 0017 - A Heretic at Court
##########################################################################################
scripted_trigger pam_sf_court_heretic_valid_trigger = {
	is_adult = yes
	faith != root.faith
	faith = {
		faith_hostility_level = {
			target = root.faith
			value > faith_astray_level
		}
	}
}

pam_secular_faith_events.0017 = {
	type = character_event
	title = pam_secular_faith_events.0017.t
	desc = pam_secular_faith_events.0017.desc
	theme = christian
	override_background = relaxing_room

	left_portrait = {
		character = scope:accused
		animation = zealous_superior
		camera = camera_event_very_left
	}
	right_portrait = {
		character = scope:chaplain
		animation = condemnation
		camera = camera_event_very_right_fov35
	}

	cooldown = { years = 10 }

	trigger = {
		pam_secular_faith_christian_actor_trigger = yes
		cp:councillor_court_chaplain ?= {
			is_available_ai_adult = yes
			has_personality_submissive_trigger = no
		}
		any_courtier = {
			pam_sf_court_heretic_valid_trigger = yes
		}
	}

	immediate = {
		cp:councillor_court_chaplain = { save_scope_as = chaplain }
		# Prefer a heretic the ruler is already warming to, so the "shield them" friendship payoff lands.
		random_courtier = {
			limit = { pam_sf_court_heretic_valid_trigger = yes }
			weight = {
				base = 1
				modifier = {
					add = 100
					has_relation_potential_friend = root
				}
			}
			save_scope_as = accused
		}
	}

	option = { # Reason with them and win them to the faith
		name = pam_secular_faith_events.0017.a
		skill = diplomacy
		duel = {
			skill = diplomacy
			target = scope:accused
			50 = { # Reason prevails - they convert willingly
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.0
				}
				send_interface_toast = {
					type = event_toast_effect_good
					title = pam_secular_faith_events.0017.a.success
					left_icon = scope:accused
					right_icon = root
					scope:accused = { set_character_rite = root.rite }
					add_piety = minor_piety_gain
				}
			}
			50 = { # They will not be moved, and resent the pressure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.0
				}
				send_interface_toast = {
					type = event_toast_effect_neutral
					title = pam_secular_faith_events.0017.a.failure
					left_icon = scope:accused
					right_icon = root
					scope:accused = {
						add_opinion = {
							modifier = unwanted_religious_conversion_opinion
							target = root
						}
					}
				}
			}
		}
		scope:chaplain = {
			add_opinion = {
				modifier = pious_opinion
				opinion = 20
				target = root
			}
		}
		ai_chance = {
			base = 100
		}
	}

	option = { # Cast the heretic into a cell
		name = pam_secular_faith_events.0017.b
		rightfully_imprison_character_effect = { TARGET = scope:accused IMPRISONER = root }
		stress_and_fulfillment_impact = {
			compassionate = minor_stress_impact_gain
		}
		scope:chaplain = {
			add_opinion = {
				modifier = pious_opinion
				opinion = 20
				target = root
			}
		}
		ai_chance = {
			base = 100
			modifier = { has_trait = compassionate factor = 0 }
		}
	}

	option = { # Shield them from the clergy
		name = pam_secular_faith_events.0017.c
		scope:chaplain = {
			add_opinion = {
				modifier = impious_opinion
				opinion = -10
				target = root
			}
		}
		if = {
			limit = {
				can_set_relation_friend_trigger = { CHARACTER = scope:accused }
			}
			set_relation_friend = {
				target = scope:accused
				reason = pam_sf_friend_shielded
			}
		}
		stress_and_fulfillment_impact = {
			zealous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = { has_trait = zealous factor = 0 }
		}
	}
}

##########################################################################################
# 0018 - A Child for God (oblation)
##########################################################################################
scripted_trigger pam_sf_oblation_child_valid_trigger = {
	is_available = yes
	is_ruler = no
	liege ?= root
	OR = {
		has_trait_submissive_trigger = yes
		has_trait_introverted_trigger = yes
	}
	age <= 15
	age >= 7
	NOR = {
		has_character_flag = pam_sf_oblation_asked
		exists = betrothed
		has_trait_extroverted_trigger = yes
		has_trait_dominant_trigger = yes
	}
	faith = root.faith
}

pam_secular_faith_events.0018 = {
	type = character_event
	title = pam_secular_faith_events.0018.t
	desc = pam_secular_faith_events.0018.desc
	theme = christian
	override_background = temple

	left_portrait = {
		character = scope:chaplain
		animation = divine_gesture_3
		camera = camera_event_very_left
	}
	right_portrait = {
		character = scope:pious_child
		animation = prayer_standing
		camera = camera_event_very_right_fov35
	}
	lower_center_portrait = scope:clerical_holder

	cooldown = { years = 5 }

	trigger = {
		pam_secular_faith_christian_actor_trigger = yes
		is_landed = yes
		cp:councillor_court_chaplain ?= {
			is_available_ai_adult = yes
		}
		any_child = {
			pam_sf_oblation_child_valid_trigger = yes
		}
	}

	immediate = {
		cp:councillor_court_chaplain = { save_scope_as = chaplain }
		random_child = {
			limit = { pam_sf_oblation_child_valid_trigger = yes }
			save_scope_as = pious_child
			add_character_flag = pam_sf_oblation_asked
		}
		if = {
			limit = {
				exists = capital_county.clerical_region_title.holder
				capital_county.clerical_region_title.holder != root
				capital_county.clerical_region_title.holder = { is_ai = yes }
			}
			capital_county.clerical_region_title.holder = { save_scope_as = clerical_holder }
		}
	}

	option = { # Make them an Oblate
		name = pam_secular_faith_events.0018.a
		add_piety = major_piety_gain
		scope:pious_child = {
			change_spiritual_fulfillment = massive_spiritual_fulfillment_value
			add_stress = major_stress_loss
			add_trait = devoted
			add_opinion = {
				target = root
				modifier = happy_opinion
				opinion = 50
			}
			add_trait_xp = {
				trait = devoted
				value = 30
			}
		}
		stress_and_fulfillment_impact = {
			cynical = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = { has_trait = cynical factor = 0 }
		}
	}

	option = { # Make them an Oblate
		name = pam_secular_faith_events.0018.b
		trigger = {
			exists = scope:clerical_holder
		}
		add_piety = major_piety_gain
		scope:clerical_holder = {
			add_opinion = {
				target = root
				modifier = pious_opinion
				opinion = 30
			}
			add_courtier = scope:pious_child
		}
		scope:pious_child = {
			change_spiritual_fulfillment = massive_spiritual_fulfillment_value
			add_stress = major_stress_loss
			add_trait = devoted
			add_opinion = {
				target = root
				modifier = happy_opinion
				opinion = 50
			}
			add_trait_xp = {
				trait = devoted
				value = 30
			}
		}
		stress_and_fulfillment_impact = {
			cynical = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = { has_trait = cynical factor = 0 }
		}
	}

	option = { # Deny
		name = pam_secular_faith_events.0018.c
		add_prestige = miniscule_prestige_gain
		stress_and_fulfillment_impact = {
			zealous = minor_stress_impact_gain
			humble = minor_stress_impact_gain
			compassionate = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				OR = {
					has_trait = zealous
					has_trait = humble
					has_trait = compassionate
				}
				factor = 0
			}
		}
	}
}

##########################################################################################
# 0019 - The Peace of God
##########################################################################################
scripted_trigger pam_sf_vassal_feud_war_trigger = {
	primary_attacker = { is_vassal_of = root  is_ai = yes }
	primary_defender = { is_vassal_of = root  is_ai = yes }
	NOT = { any_war_participant = { is_ai = no } }
}

# Ends every qualifying vassal feud in a white peace, processing each war once from its attacker's side.
scripted_effect pam_sf_end_vassal_feuds_effect = {
	every_vassal = {
		limit = { is_ai = yes }
		save_temporary_scope_as = peace_vassal
		every_character_war = {
			limit = {
				primary_attacker = { this = scope:peace_vassal }
				pam_sf_vassal_feud_war_trigger = yes
			}
			end_war = white_peace
		}
	}
}

pam_secular_faith_events.0019 = {
	type = character_event
	title = pam_secular_faith_events.0019.t
	desc = pam_secular_faith_events.0019.desc
	theme = christian
	override_background = temple

	left_portrait = {
		character = scope:chaplain
		animation = divine_gesture_4
		camera = camera_event_very_left
	}
	right_portrait = {
		character = root
		animation = contemplating
	}
	lower_left_portrait = {
		character = scope:feud_attacker
		animation = war_over_win
	}
	lower_right_portrait = {
		character = scope:feud_defender
		animation = war_attacker
	}

	cooldown = { years = 10 }

	# Fires when two of the ruler's direct vassals (AI only, no player) are at war with each other.
	trigger = {
		pam_secular_faith_christian_actor_trigger = yes
		rite = {
			has_at_least_tenet_status = {
				tenet = tenet_peace_of_god
				status = permitted
			}
		}
		cp:councillor_court_chaplain ?= {
			is_available_ai_adult = yes
			NOT = {
				has_relation_rival = root
			}
			is_at_war = no
		}
		any_vassal = {
			any_character_war = { pam_sf_vassal_feud_war_trigger = yes }
		}
	}

	immediate = {
		cp:councillor_court_chaplain = { save_scope_as = chaplain }
		# Put a face on the unrest: name one feuding pair for the scene.
		random_vassal = {
			limit = {
				any_character_war = { pam_sf_vassal_feud_war_trigger = yes }
			}
			random_character_war = {
				limit = { pam_sf_vassal_feud_war_trigger = yes }
				primary_attacker = { save_scope_as = feud_attacker }
				primary_defender = { save_scope_as = feud_defender }
			}
		}
	}

	option = { # Proclaim and enforce the Peace of God
		name = pam_secular_faith_events.0019.a
		custom_tooltip = pam_sf_peace_of_god_ends_wars_tt
		add_piety = major_piety_gain
		add_character_modifier = {
			modifier = pam_sf_peace_of_god_modifier
			years = 10
		}
		hidden_effect = { pam_sf_end_vassal_feuds_effect = yes }
		ai_chance = {
			base = 100
		}
	}

	option = { # Broker the peace, and bind the lords to you
		name = pam_secular_faith_events.0019.b
		custom_tooltip = pam_sf_peace_of_god_ends_wars_tt
		add_piety = minor_piety_gain
		if = {
			limit = { can_add_hook = { target = scope:feud_attacker type = favor_hook } }
			add_hook = { type = favor_hook target = scope:feud_attacker }
		}
		if = {
			limit = { can_add_hook = { target = scope:feud_defender type = favor_hook } }
			add_hook = { type = favor_hook target = scope:feud_defender }
		}
		hidden_effect = { pam_sf_end_vassal_feuds_effect = yes }
		stress_and_fulfillment_impact = {
			just = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = { has_trait = just factor = 0 }
		}
	}

	option = { # Let them settle it with steel
		name = pam_secular_faith_events.0019.c
		add_prestige = minor_prestige_gain
		stress_and_fulfillment_impact = {
			compassionate = medium_stress_impact_gain
			just = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = compassionate
					has_trait = just
				}
			}
		}
	}
}

##########################################################################################
# 0020 - The Consecration (fired from on_building_completed; not in the yearly pool)
##########################################################################################
pam_secular_faith_events.0020 = {
	type = character_event
	title = pam_secular_faith_events.0020.t
	desc = pam_secular_faith_events.0020.desc
	theme = christian
	override_background = holy_site_generic_scope
	override_effect_2d = { reference = smoke }

	left_portrait = {
		character = root
		animation = prayer_standing_eyes
		camera = camera_event_left_away_3_4
	}
	right_portrait = {
		character = scope:chaplain
		animation = thurible
		camera = camera_event_right_away
	}

	trigger = {
		pam_secular_faith_christian_actor_trigger = yes
		exists = scope:pam_sf_consecrated_county
		NOT = { has_character_flag = pam_sf_first_church_consecrated }
		cp:councillor_court_chaplain ?= {
			is_available_ai_adult = yes
		}
	}

	immediate = {
		add_character_flag = pam_sf_first_church_consecrated
		scope:pam_sf_consecrated_county = {
			save_scope_as = consecrated_county
			save_scope_as = holy_site_scope
		}
		cp:councillor_court_chaplain = { save_scope_as = chaplain }
	}

	option = { # Give thanks - piety, peace of soul, and the clergy's favor
		name = pam_secular_faith_events.0020.a
		add_piety = medium_piety_gain
		change_spiritual_fulfillment = medium_spiritual_fulfillment_value
		ai_chance = {
			base = 100
		}
	}

	option = { # Endow it richly - the parish quickens the county
		name = pam_secular_faith_events.0020.b
		scope:consecrated_county = {
			change_development_progress = major_development_progress_gain
			add_county_modifier = {
				modifier = pam_sf_consecrated_county_modifier
				years = 10
			}
		}
		ai_chance = {
			base = 100
		}
	}

	option = { # Found a school beside the altar
		name = pam_secular_faith_events.0020.c
		add_scholar_trait_or_xp_effect = { VALUE = 40 }
		add_learning_lifestyle_xp = major_lifestyle_xp
		ai_chance = {
			base = 100
		}
	}

	option = { # Vow that this is the first of many
		name = pam_secular_faith_events.0020.d
		add_character_modifier = { modifier = pam_sf_church_builder_modifier }
		add_piety = minor_piety_gain
		ai_chance = {
			base = 100
		}
	}
}

##########################################################################################
# 0021 - A Sign in the Heavens (an omen)
##########################################################################################
pam_secular_faith_events.0021 = {
	type = character_event
	title = pam_secular_faith_events.0021.t
	desc = pam_secular_faith_events.0021.desc
	theme = christian
	override_background = courtyard

	left_portrait = {
		character = root
		animation = divine_ecstasy
		camera = camera_event_right_fully_away
	}
	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_godray container = foreground_shader_vfx_container }
	}

	cooldown = { years = 15 }

	trigger = {
		pam_secular_faith_christian_actor_trigger = yes
	}

	option = { # Scholar: chart it as the learned do
		name = pam_secular_faith_events.0021.a
		trigger = { has_trait = lifestyle_scholar }
		show_as_unavailable = { always = yes }
		add_scholar_trait_or_xp_effect = { VALUE = 40 }
		add_learning_lifestyle_xp = major_lifestyle_xp
		ai_chance = {
			base = 100
		}
	}

	option = { # Astrologer's eye: cast its meaning by the stars
		name = pam_secular_faith_events.0021.b
		trigger = { learning >= 12 }
		skill = learning
		show_as_unavailable = { always = yes }
		add_character_modifier = {
			modifier = pam_sf_favorable_omen_modifier
			years = 15
		}
		change_spiritual_fulfillment = minor_spiritual_fulfillment_value
		stress_and_fulfillment_impact = {
			cynical = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = { has_trait = cynical factor = 0 }
		}
	}

	option = { # Soldier's read: an omen of conquest
		name = pam_secular_faith_events.0021.c
		trigger = { martial >= 12 }
		skill = martial
		show_as_unavailable = { always = yes }
		add_character_modifier = {
			modifier = pam_sf_omen_of_victory_modifier
			years = 15
		}
		change_spiritual_fulfillment = minor_spiritual_fulfillment_value
		stress_and_fulfillment_impact = {
			cynical = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = { has_trait = cynical factor = 0 }
		}
	}

	option = { # Read nothing into it
		name = pam_secular_faith_events.0021.d
		add_piety = minor_piety_gain
		ai_chance = {
			base = 100
		}
	}
}

##########################################################################################
# 0022 - The King's Touch
##########################################################################################
scripted_effect pam_secular_faith_recover_from_any_disease_effect = {
	if = { limit = { has_trait = ill } recover_from_disease_effect = { DISEASE = ill } }
	if = { limit = { has_trait = pneumonic } recover_from_disease_effect = { DISEASE = pneumonic } }
	if = { limit = { has_trait = gout_ridden } recover_from_disease_effect = { DISEASE = gout_ridden } }
	if = { limit = { has_trait = typhus } recover_from_disease_effect = { DISEASE = typhus } }
	if = { limit = { has_trait = consumption } recover_from_disease_effect = { DISEASE = consumption } }
	if = { limit = { has_trait = cancer } recover_from_disease_effect = { DISEASE = cancer } }
	if = { limit = { has_trait = lovers_pox } recover_from_disease_effect = { DISEASE = lovers_pox } }
	if = { limit = { OR = { has_trait = great_pox has_trait = early_great_pox } } recover_from_disease_effect = { DISEASE = great_pox } }
	if = { limit = { has_trait = smallpox } recover_from_disease_effect = { DISEASE = smallpox } }
	if = { limit = { has_trait = bubonic_plague } recover_from_disease_effect = { DISEASE = bubonic_plague } }
	if = { limit = { has_trait = measles } recover_from_disease_effect = { DISEASE = measles } }
	if = { limit = { has_trait = dysentery } recover_from_disease_effect = { DISEASE = dysentery } }
	if = { limit = { has_trait = ergotism } recover_from_disease_effect = { DISEASE = ergotism } }
}

scripted_effect pam_secular_faith_contract_disease_from_effect = {
	if = { limit = { $GIVER$ = { has_trait = bubonic_plague } } contract_disease_effect = { DISEASE = bubonic_plague TREATMENT_EVENT = yes } }
	else_if = { limit = { $GIVER$ = { has_trait = smallpox } } contract_disease_effect = { DISEASE = smallpox TREATMENT_EVENT = yes } }
	else_if = { limit = { $GIVER$ = { has_trait = typhus } } contract_disease_effect = { DISEASE = typhus TREATMENT_EVENT = yes } }
	else_if = { limit = { $GIVER$ = { has_trait = consumption } } contract_disease_effect = { DISEASE = consumption TREATMENT_EVENT = yes } }
	else_if = { limit = { $GIVER$ = { has_trait = pneumonic } } contract_disease_effect = { DISEASE = pneumonic TREATMENT_EVENT = yes } }
	else_if = { limit = { $GIVER$ = { has_trait = measles } } contract_disease_effect = { DISEASE = measles TREATMENT_EVENT = yes } }
	else_if = { limit = { $GIVER$ = { has_trait = dysentery } } contract_disease_effect = { DISEASE = dysentery TREATMENT_EVENT = yes } }
	else_if = { limit = { $GIVER$ = { has_trait = ill } } contract_disease_effect = { DISEASE = ill TREATMENT_EVENT = yes } }
}

scripted_trigger pam_sf_kings_touch_patient_valid_trigger = {
	is_available_ai_adult = yes
	is_clergy = no
	NOR = {
		has_relation_rival = root
		is_close_family_of = root
	}
	ai_zeal >= 0
	faith = root.faith
	any_character_trait = {
		has_trait_flag = illness
	}
}

scripted_trigger pam_sf_kings_touch_contagion_possible_trigger = {
	OR = {
		AND = { scope:sick_courtier = { has_trait = bubonic_plague }  can_contract_disease_trigger = { DISEASE = bubonic_plague } }
		AND = { scope:sick_courtier = { has_trait = smallpox }  can_contract_disease_trigger = { DISEASE = smallpox } }
		AND = { scope:sick_courtier = { has_trait = typhus }  can_contract_disease_trigger = { DISEASE = typhus } }
		AND = { scope:sick_courtier = { has_trait = consumption }  can_contract_disease_trigger = { DISEASE = consumption } }
		AND = { scope:sick_courtier = { has_trait = pneumonic }  can_contract_disease_trigger = { DISEASE = pneumonic } }
		AND = { scope:sick_courtier = { has_trait = measles }  can_contract_disease_trigger = { DISEASE = measles } }
		AND = { scope:sick_courtier = { has_trait = dysentery }  can_contract_disease_trigger = { DISEASE = dysentery } }
		AND = { scope:sick_courtier = { has_trait = ill }  can_contract_disease_trigger = { DISEASE = ill } }
	}
}

pam_secular_faith_events.0022 = {
	type = character_event
	title = pam_secular_faith_events.0022.t
	desc = {
		desc = pam_secular_faith_events.0022.desc_intro
		first_valid = {
			triggered_desc = {
				trigger = { scope:illness_trait = trait:ill }
				desc = pam_secular_faith_events.0022.desc_ill
			}
			desc = pam_secular_faith_events.0022.desc_other
		}
		desc = pam_secular_faith_events.0022.desc_end
	}
	theme = christian
	override_background = sitting_room

	left_portrait = {
		character = root
		animation = divine_gesture_1
	}
	right_portrait = {
		character = scope:sick_courtier
		animation = sick
	}

	cooldown = { years = 10 }

	trigger = {
		pam_secular_faith_christian_actor_trigger = yes
		any_courtier = {
			pam_sf_kings_touch_patient_valid_trigger = yes
		}
		court_physician_available_trigger = yes
	}

	immediate = {
		random_courtier = {
			limit = { pam_sf_kings_touch_patient_valid_trigger = yes }
			save_scope_as = sick_courtier
			random_character_trait = {
				limit = {
					has_trait_flag = illness
				}
				save_scope_as = illness_trait
			}
		}
		save_court_physician_as_effect = { SCOPE_NAME = physician }
	}

	option = { # Lay your hands on them yourself
		name = pam_secular_faith_events.0022.a
		add_internal_flag = dangerous
		custom_tooltip = pam_sf_kings_touch_gamble_tt
		add_legitimacy_effect = { LEGITIMACY = minor_legitimacy_gain }
		change_spiritual_fulfillment = minor_spiritual_fulfillment_value
		scope:sick_courtier = {
			add_opinion = {
				modifier = grateful_opinion
				opinion = 30
				target = root
			}
		}
		if = {
			limit = { can_add_hook = { target = scope:sick_courtier type = favor_hook } }
			add_hook = {
				type = favor_hook
				target = scope:sick_courtier
			}
		}
		hidden_effect = {
			random_list = {
				# Cured - comfort, good nursing and the will to live rally the body
				35 = {
					modifier = { add = 15  learning >= 8 }
					modifier = { add = 10  piety_level >= 3 }
					create_character_memory = {
						type = pam_sf_kings_touch_healing_memory
						participants = { healed_subject = scope:sick_courtier }
					}
					send_interface_toast = {
						type = event_toast_effect_good
						title = pam_sf_kings_touch_cured_toast
						left_icon = scope:sick_courtier
						right_icon = root
						scope:sick_courtier = { pam_secular_faith_recover_from_any_disease_effect = yes }
					}
				}
				# The sickness passes to you
				10 = {
					trigger = { pam_sf_kings_touch_contagion_possible_trigger = yes }
					modifier = { add = 15  health <= 3 }
					modifier = { add = 10  age >= 50 }
					send_interface_toast = {
						type = event_toast_effect_bad
						title = pam_sf_kings_touch_infected_toast
						left_icon = root
						pam_secular_faith_contract_disease_from_effect = { GIVER = scope:sick_courtier }
					}
				}
				# The touch changes nothing
				55 = {
					send_interface_toast = {
						type = event_toast_effect_neutral
						title = pam_sf_kings_touch_nothing_toast
						left_icon = scope:sick_courtier
					}
				}
			}
		}
		stress_and_fulfillment_impact = {
			craven = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = { has_trait = craven factor = 0 }
		}
	}

	option = { # Bless them from a safe distance
		name = pam_secular_faith_events.0022.b
		add_piety = minor_piety_gain
		scope:sick_courtier = {
			add_opinion = {
				modifier = disappointed_opinion
				target = root
				opinion = -10
			}
		}
		ai_chance = {
			base = 100
		}
	}
}

##########################################################################################
# 0023 - A Wandering Scribe
##########################################################################################
scripted_trigger pam_sf_scriptorium_scholar_valid_trigger = {
	is_available_healthy_ai_adult = yes
	has_no_particular_noble_roots_trigger = yes
	faith = root.faith
	root.faith = { has_allowed_gender_for_clergy = prev }
	OR = {
		learning >= 12
		has_trait = theologian
		has_trait = erudite
		has_trait = lifestyle_scholar
	}
}

pam_secular_faith_events.0023 = {
	type = character_event
	title = pam_secular_faith_events.0023.t
	desc = pam_secular_faith_events.0023.desc
	theme = christian
	override_background = study

	left_portrait = {
		character = scope:scholar
		animation = divine_gesture_4
	}
	right_portrait = {
		character = root
		animation = contemplating
	}

	cooldown = { years = 10 }

	trigger = {
		pam_secular_faith_christian_actor_trigger = yes
		any_pool_character = {
			province = root.location
			pam_sf_scriptorium_scholar_valid_trigger = yes
		}
	}

	immediate = {
		random_pool_character = {
			province = root.location
			limit = { pam_sf_scriptorium_scholar_valid_trigger = yes }
			save_scope_as = scholar
			hidden_effect = {
				change_current_weight = -125
				add_trait = lifestyle_scholar
			}
		}
		if = {
			limit = { capital_county = { any_county_province = { has_holding_type = church_holding } } }
			capital_county = {
				random_county_province = {
					limit = { has_holding_type = church_holding }
					barony = { save_scope_as = scholar_church }
				}
			}
		}
	}

	option = { # Study alongside them - a learned ruler deepens their own scholarship
		name = pam_secular_faith_events.0023.a
		trigger = { learning >= 12 }
		skill = learning
		show_as_unavailable = { always = yes }
		remove_short_term_gold = miniscule_gold_value
		add_courtier = scope:scholar
		add_scholar_trait_or_xp_effect = { VALUE = 50 }
		ai_chance = {
			base = 100
		}
	}

	option = { # Set them to keep the books at a named church - the county prospers for it
		name = pam_secular_faith_events.0023.b
		trigger = { exists = scope:scholar_church }
		remove_short_term_gold = miniscule_gold_value
		scope:scholar = {
			set_location = scope:scholar_church.title_province
		}
		scope:scholar_church.title_province = {
			add_province_modifier = {
				modifier = pam_sf_scriptorium_county_modifier
				years = 10
			}
		}
		add_piety = minor_piety_gain
		ai_chance = {
			base = 100
		}
	}

	option = { # Take them into my own service
		name = pam_secular_faith_events.0023.c
		remove_short_term_gold = miniscule_gold_value
		add_courtier = scope:scholar
		add_legitimacy_effect = { LEGITIMACY = minor_legitimacy_gain }
		add_learning_lifestyle_xp = medium_lifestyle_xp
		ai_chance = {
			base = 100
		}
	}

	option = { # Send them on their way
		name = pam_secular_faith_events.0023.d
		stress_and_fulfillment_impact = {
			generous = minor_stress_impact_gain
			compassionate = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = generous
					has_trait = compassionate
				}
			}
		}
	}
}

##########################################################################################
# 0024 - Into the Cloister (a rival nudged toward holy vows)
##########################################################################################
scripted_trigger pam_sf_cloister_rival_valid_trigger = {
	is_available_adult = yes
	is_ruler = no
	is_courtier_of = root
	has_relation_rival = root
}

pam_secular_faith_events.0024 = {
	type = character_event
	title = pam_secular_faith_events.0024.t
	desc = pam_secular_faith_events.0024.desc
	theme = christian
	override_background = temple

	left_portrait = {
		character = scope:archbishop
		animation = priest_good
		camera = camera_event_very_left
	}
	right_portrait = {
		character = scope:rival_character
		animation = disapproval
	}

	cooldown = { years = 10 }

	trigger = {
		pam_secular_faith_christian_actor_trigger = yes
		exists = capital_county.clerical_region_title.holder
		capital_county.clerical_region_title.holder = {
			this != root
			is_ai = yes
		}
		any_courtier = {
			pam_sf_cloister_rival_valid_trigger = yes
		}
	}

	immediate = {
		capital_county.clerical_region_title = { save_scope_as = archdiocese }
		capital_county.clerical_region_title.holder = { save_scope_as = archbishop }
		random_courtier = {
			limit = { pam_sf_cloister_rival_valid_trigger = yes }
			save_scope_as = rival_character
		}
	}

	option = { # Force them to take the vows
		name = pam_secular_faith_events.0024.a
		add_piety = medium_piety_gain
		scope:rival_character = {
			add_trait = devoted
			add_character_modifier = {
				modifier = pam_sf_humiliated_modifier
				years = 15
			}
			if = {
				limit = {
					can_set_relation_nemesis_trigger = { CHARACTER = root }
				}
				progress_towards_nemesis_effect = {
					REASON = pam_sf_nemesis_forced_to_cloister
					CHARACTER = root
					OPINION = 0
				}
				add_opinion = {
					target = root
					modifier = hate_opinion
					opinion = -30
				}
				if = {
					limit = { is_married = yes }
					every_spouse = { divorce = scope:rival_character }
				}
				if = {
					limit = { exists = betrothed }
					break_betrothal = betrothed
				}
			}
		}
		scope:archbishop = {
			add_courtier = scope:rival_character
			add_opinion = {
				modifier = grateful_opinion
				opinion = 30
				target = root
			}
		}
		stress_and_fulfillment_impact = {
			compassionate = minor_stress_impact_gain
			forgiving = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = compassionate
					has_trait = forgiving
				}
			}
		}
	}

	option = { # Keep them where I can watch them
		name = pam_secular_faith_events.0024.b
		add_prestige = minor_prestige_gain
		ai_chance = {
			base = 100
		}
	}
}

##########################################################################################
# 0025 - Godfather/Godmother (sponsoring a convert's baptism)
##########################################################################################
scripted_trigger pam_sf_baptism_convert_valid_trigger = {
	is_available_ai_adult = yes
	religion != root.religion
	religion != religion:judaism_religion
	NOR = {
		has_relation_rival = root
		has_character_flag = ai_will_not_convert
		culture = {
			has_cultural_tradition = tradition_diasporic
		}
	}
}

pam_secular_faith_events.0025 = {
	type = character_event
	title = pam_secular_faith_events.0025.t
	desc = pam_secular_faith_events.0025.desc
	theme = christian
	override_background = temple

	left_portrait = {
		character = root
		animation = divine_gesture_3
		camera = camera_event_left_to_the_left
	}
	right_portrait = {
		character = scope:converting_char
		animation = prayer_standing
	}

	cooldown = { years = 10 }

	trigger = {
		pam_secular_faith_christian_actor_trigger = yes
		any_courtier = {
			pam_sf_baptism_convert_valid_trigger = yes
		}
	}

	immediate = {
		random_courtier = {
			limit = { pam_sf_baptism_convert_valid_trigger = yes }
			save_scope_as = converting_char
		}
	}

	option = { # Make it a spectacle
		name = pam_secular_faith_events.0025.a
		add_piety = medium_piety_gain
		scope:converting_char = {
			set_character_rite = root.rite
			add_opinion = {
				modifier = pam_sf_godkin_opinion
				target = root
			}
		}
		if = {
			limit = {
				can_set_relation_friend_trigger = { CHARACTER = scope:converting_char }
			}
			set_relation_friend = {
				reason = pam_sf_friend_godparent
				target = scope:converting_char
			}
		}
		stress_and_fulfillment_impact = {
			content = minor_stress_impact_gain
			humble = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = content
					has_trait = humble
				}
			}
		}
	}

	option = { # Secluded ceremony
		name = pam_secular_faith_events.0025.b
		change_spiritual_fulfillment = minor_spiritual_fulfillment_value
		scope:converting_char = {
			set_character_rite = root.rite
			add_opinion = {
				modifier = pam_sf_godkin_opinion
				target = root
				opinion = 15
			}
		}
		if = {
			limit = {
				can_set_relation_friend_trigger = { CHARACTER = scope:converting_char }
			}
			set_relation_friend = {
				reason = pam_sf_friend_godparent
				target = scope:converting_char
			}
		}
		stress_and_fulfillment_impact = {
			arrogant = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				has_trait = arrogant
			}
		}
	}

	option = { # Not interested
		name = pam_secular_faith_events.0025.c
		add_prestige = miniscule_prestige_gain
		stress_and_fulfillment_impact = {
			zealous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				has_trait = zealous
			}
		}
	}
}

##########################################################################################
# 0026 - A Besieged Soul (a courtier's torment / exorcism)
##########################################################################################
scripted_trigger pam_sf_possessed_courtier_valid_trigger = {
	is_available_ai_adult = yes
	trigger_if = {
		limit = { exists = root.cp:councillor_court_chaplain }
		this != root.cp:councillor_court_chaplain
	}
	faith = root.faith
	OR = {
		has_trait = possessed_1
		has_trait = lunatic_1
	}
	NOT = {
		has_character_flag = cured_demons
	}
}

pam_secular_faith_events.0026 = {
	type = character_event
	title = pam_secular_faith_events.0026.t
	desc = pam_secular_faith_events.0026.desc
	theme = christian
	override_background = temple

	left_portrait = {
		character = scope:chaplain
		animation = worry
	}
	right_portrait = {
		character = scope:afflicted
		animation = mental_anguish
		camera = camera_event_right_forward
	}
	widgets = {
		widget = { gui = event_window_widget_vfx_background_double_vision_milder container = foreground_shader_vfx_container }
		widget = { gui = event_window_widget_vfx_left_character_double_vision_milder container = foreground_shader_vfx_container }
		widget = { gui = event_window_widget_vfx_right_character_double_vision_milder container = foreground_shader_vfx_container }
	}

	cooldown = { years = 5 }

	trigger = {
		pam_secular_faith_christian_actor_trigger = yes
		any_courtier = {
			pam_sf_possessed_courtier_valid_trigger = yes
		}
		cp:councillor_court_chaplain ?= {
			is_available_ai_adult = yes
		}
	}

	immediate = {
		random_courtier = {
			limit = { pam_sf_possessed_courtier_valid_trigger = yes }
			weight = {
				base = 1
				modifier = {
					add = 25
					is_close_or_extended_family_of = root
				}
				modifier = {
					add = 25
					OR = {
						has_relation_friend = root
						has_relation_lover = root
					}
				}
			}
			save_scope_as = afflicted
		}
		cp:councillor_court_chaplain = { save_scope_as = chaplain }
		scope:afflicted = {
			if = {
				limit = { NOT = { has_character_modifier = pam_sf_besieged_by_demons_modifier } }
				add_character_modifier = pam_sf_besieged_by_demons_modifier
			}
		}
	}

	option = { # Treat it as an affliction of the body
		name = pam_secular_faith_events.0026.a
		trigger = {
			OR = {
				has_trait = lifestyle_scholar
				has_trait = lifestyle_physician
			}
		}
		scope:afflicted = {
			if = {
				limit = { has_character_modifier = pam_sf_besieged_by_demons_modifier }
				remove_character_modifier = pam_sf_besieged_by_demons_modifier
				add_character_flag = cured_demons
			}
			add_opinion = {
				modifier = grateful_opinion
				opinion = 30
				target = root
			}
		}
		physician_lifestyle_rank_up_effect = yes
		add_scholar_trait_or_xp_effect = { VALUE = 30 }
		stress_and_fulfillment_impact = {
			zealous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = { has_trait = zealous factor = 0 }
		}
	}

	option = { # Preside over the exorcism yourself
		name = pam_secular_faith_events.0026.b
		add_piety = medium_piety_gain
		duel = {
			skill = learning
			value = average_skill_rating
			50 = { # The rite prevails
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				send_interface_toast = {
					type = event_toast_effect_good
					title = pam_sf_exorcism_success_toast
					left_icon = scope:afflicted
					right_icon = root
					change_spiritual_fulfillment = minor_spiritual_fulfillment_value
					scope:afflicted = {
						if = {
							limit = { has_character_modifier = pam_sf_besieged_by_demons_modifier }
							remove_character_modifier = pam_sf_besieged_by_demons_modifier
							add_character_flag = cured_demons
						}
						add_opinion = {
							modifier = grateful_opinion
							opinion = 30
							target = root
						}
					}
					if = {
						limit = { can_add_hook = { target = scope:afflicted type = loyalty_hook } }
						add_hook = {
							type = loyalty_hook
							target = scope:afflicted
						}
					}
				}
				create_character_memory = {
					type = pam_sf_deliverance_memory
					participants = { delivered_soul = scope:afflicted }
				}
			}
			50 = { # The rite fails - the siege holds
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				send_interface_toast = {
					type = event_toast_effect_bad
					title = pam_sf_exorcism_failed_toast
					left_icon = scope:afflicted
					right_icon = root
					increase_wounds_effect = { REASON = fight}
				}
			}
		}
		stress_and_fulfillment_impact = {
			craven = minor_stress_impact_gain
		}
		ai_chance = {
			base = 1
			modifier = { has_trait = craven factor = 0 }
		}
	}

	option = { # Let the chaplain perform it
		name = pam_secular_faith_events.0026.c
		scope:chaplain = {
			add_opinion = {
				modifier = pious_opinion
				opinion = 20
				target = root
			}
			duel = {
				skill = learning
				value = average_skill_rating
				50 = { # The chaplain's rite prevails
					compare_modifier = {
						value = scope:duel_value
						multiplier = 3.5
						min = -49
					}
					root = {
						send_interface_toast = {
							type = event_toast_effect_good
							title = pam_sf_exorcism_success_toast
							left_icon = scope:afflicted
							right_icon = scope:chaplain
							scope:afflicted = {
								if = {
									limit = { has_character_modifier = pam_sf_besieged_by_demons_modifier }
									remove_character_modifier = pam_sf_besieged_by_demons_modifier
									add_character_flag = cured_demons
								}
							}
						}
					}
				}
				50 = { # The chaplain's rite fails - the siege holds
					compare_modifier = {
						value = scope:duel_value
						multiplier = -3.5
						min = -49
					}
					root = {
						send_interface_toast = {
							type = event_toast_effect_bad
							title = pam_sf_exorcism_failed_toast
							left_icon = scope:afflicted
							right_icon = scope:chaplain
							scope:chaplain = {
								increase_wounds_effect = { REASON = fight}
							}
						}
					}
				}
			}
		}
		stress_and_fulfillment_impact = {
			arrogant = minor_stress_impact_gain
		}
		ai_chance = {
			base = 1
			modifier = { has_trait = arrogant factor = 0 }
		}
	}

	option = { # Cast them out
		name = pam_secular_faith_events.0026.d
		scope:afflicted = {
			select_and_move_to_pool_effect = yes
			if = {
				limit = {
					NOT = {
						has_trait = lunatic
					}
				}
				add_trait = lunatic_1
			}
		}
		stress_and_fulfillment_impact = {
			compassionate = minor_stress_impact_gain
		}
		ai_chance = {
			base = 0
			modifier = { has_trait = compassionate factor = 0 }
		}
	}
}

##########################################################################################
# 0027 - Crisis of Faith (low Spiritual Fulfillment)
##########################################################################################

scripted_trigger pam_secular_faith_events_0027_new_tenet_trigger = {
	save_temporary_scope_as = pam_sf_tenet_candidate
	root = {
		NOR = {
			any_personal_tenet = { this = scope:pam_sf_tenet_candidate }
			faith.main_rite = {
				has_tenet_status = {
					tenet = scope:pam_sf_tenet_candidate
					status = prohibited
				}
			}
		}
	}
}

pam_secular_faith_events.0027 = {
	type = character_event
	title = pam_secular_faith_events.0027.t
	desc = pam_secular_faith_events.0027.desc
	theme = christian
	override_background = temple

	left_portrait = {
		character = root
		animation = mental_anguish
		camera = camera_event_kneeling
	}

	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_godray container = foreground_shader_vfx_container }
	}

	cooldown = { years = 10 }

	trigger = {
		pam_secular_faith_clergy_ok_actor_trigger = yes
		OR = {
			religion = religion:catholic_religion
			religion = religion:protestant_religion
			religion = religion:eastern_orthodox_religion
			religion = religion:oriental_orthodox_religion
		}
		spiritual_fulfillment < 0
		any_personal_tenet = { count >= 1 } # The desc names scope:old_tenet
		any_desired_tenet = {
			only_positive = yes
			threshold = 1
			selection_count = 97
			pam_secular_faith_events_0027_new_tenet_trigger = yes
		}
	}

	immediate = {
		random_personal_tenet = { save_scope_as = old_tenet }
		random_desired_tenet = {
			only_positive = yes
			threshold = 1
			selection_count = 97
			limit = {
				pam_secular_faith_events_0027_new_tenet_trigger = yes
			}
			save_scope_as = new_tenet
		}
		random_desired_tenet = {
			only_positive = yes
			threshold = 1
			selection_count = 97
			limit = {
				NOT = { scope:new_tenet ?= this }
				pam_secular_faith_events_0027_new_tenet_trigger = yes
			}
			save_scope_as = forbidden_tenet
		}
	}

	option = { # Realign your faith to your heart
		name = pam_secular_faith_events.0027.a
		force_set_personal_tenet = scope:new_tenet
		ai_chance = {
			base = 100
		}
	}

	option = { # Find meaning in a hidden truth
		name = pam_secular_faith_events.0027.b
		add_internal_flag = dangerous
		trigger = {
			exists = scope:forbidden_tenet
		}
		force_set_personal_tenet = scope:forbidden_tenet
		change_spiritual_fulfillment = 50
		stress_and_fulfillment_impact = {
			zealous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = { has_trait = zealous factor = 0 }
		}
	}

	option = { # Mask it and go through the motions
		name = pam_secular_faith_events.0027.c
		add_intrigue_skill = 1
		stress_and_fulfillment_impact = {
			base = minor_stress_impact_gain
			craven = massive_stress_impact_gain
			sadistic = minor_stress_impact_gain
			callous = minor_stress_impact_gain
			brave = massive_stress_impact_loss
			zealous = medium_stress_impact_loss
		}
		ai_chance = {
			base = 100
			modifier = {
				OR = {
					has_trait = craven
					has_trait = sadistic
					has_trait = callous
					prowess < 10
				}
				factor = 0
			}
		}
	}
}

##########################################################################################
# 0028 - My Soul, at Peace (high Spiritual Fulfillment)
##########################################################################################
scripted_trigger valid_flip_target_trigger = {
	is_available_ai_adult = yes
	highest_held_title_tier >= tier_county
	this != root
	NOR = {
		has_trait = cynical
		has_relation_rival = root
	}
}

# Flip the scoped character's personal tenet to root's scope:old_tenet.
scripted_effect flip_personal_tenet_effect = {
	if = {
		limit = {
			NOT = {
				knows_tenet = scope:old_tenet
			}
		}
		add_known_tenet = scope:old_tenet
		pam_secular_faith_seed_tenet_message_effect = { TENET = scope:old_tenet }
	}
	force_set_personal_tenet = scope:old_tenet
}

pam_secular_faith_events.0028 = {
	type = character_event
	title = pam_secular_faith_events.0028.t
	desc = pam_secular_faith_events.0028.desc
	theme = christian
	override_background = temple
	override_effect_2d = { reference = legend_glow }
	widgets = {
		widget = {
			gui = event_window_widget_vfx_godray
			container = background_shader_vfx_container
		}
	}

	left_portrait = {
		character = root
		animation = divine_ecstasy_kneeling
		camera = camera_event_kneeling
	}

	cooldown = { years = 30 }

	trigger = {
		pam_secular_faith_clergy_ok_actor_trigger = yes
		spiritual_fulfillment >= spiritual_fulfillment_3
		NOT = { has_character_modifier = pam_sf_consolation_modifier }
		any_personal_tenet = { count >= 1 } # The desc and the flip chain both name scope:old_tenet
		OR = {
			any_vassal_or_below = {
				valid_flip_target_trigger = yes
			}
			liege ?= {
				any_vassal_or_below = {
					valid_flip_target_trigger = yes
				}
			}
			location.county.holder = {
				valid_flip_target_trigger = yes
			}
		}
	}

	immediate = {
		random_personal_tenet = { save_scope_as = old_tenet }
		random_desired_tenet = {
			only_positive = yes
			threshold = 1
			selection_count = 97
			limit = {
				save_temporary_scope_as = pam_sf_forbidden_candidate
				NOT = { root = { any_personal_tenet = { this = scope:pam_sf_forbidden_candidate } } }
				root.faith.main_rite = {
					has_tenet_status = {
						tenet = scope:pam_sf_forbidden_candidate
						status = prohibited
					}
				}
			}
			save_scope_as = forbidden_tenet
		}
		random_vassal_or_below = {
			limit = {
				valid_flip_target_trigger = yes
			}
			save_scope_as = own_vassal_flip_1
		}
		random_vassal_or_below = {
			limit = {
				NOT = { scope:own_vassal_flip_1 ?= this } # A first flip target isn't always found
				valid_flip_target_trigger = yes
			}
			save_scope_as = own_vassal_flip_2
		}
		liege ?= {
			random_vassal_or_below = {
				limit = {
					valid_flip_target_trigger = yes
				}
				save_scope_as = liege_vassal_flip_1
			}
			random_vassal_or_below = {
				limit = {
					NOT = { scope:liege_vassal_flip_1 ?= this } # A first flip target isn't always found
					valid_flip_target_trigger = yes
				}
				save_scope_as = liege_vassal_flip_2
			}
		}
		if = {
			limit = {
				location.county.holder = {
					valid_flip_target_trigger = yes
				}
			}
			location.county.holder = {
				save_scope_as = location_flip
			}
		}
	}

	option = { # Propagate the personal tenets
		name = pam_secular_faith_events.0028.a
		add_piety = major_piety_gain
		scope:location_flip ?= {
			flip_personal_tenet_effect = yes
		}
		scope:liege_vassal_flip_1 ?= {
			flip_personal_tenet_effect = yes
		}
		scope:liege_vassal_flip_2 ?= {
			flip_personal_tenet_effect = yes
		}
		scope:own_vassal_flip_1 ?= {
			flip_personal_tenet_effect = yes
		}
		scope:own_vassal_flip_2 ?= {
			flip_personal_tenet_effect = yes
		}
		stress_and_fulfillment_impact = {
			shy = minor_stress_impact_gain
			cynical = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				OR = {
					has_trait = shy
					has_trait = cynical
				}
				factor = 0
			}
		}
	}

	option = { # Follow your true passion
		name = pam_secular_faith_events.0028.b
		trigger = {
			exists = scope:forbidden_tenet
		}
		force_set_personal_tenet = scope:forbidden_tenet
		stress_and_fulfillment_impact = {
			base = major_stress_impact_loss
		}
		ai_chance = {
			base = 100
		}
	}

	option = { # Abide in the peace
		name = pam_secular_faith_events.0028.c
		add_scholar_trait_or_xp_effect = { VALUE = 30 }
		add_character_modifier = {
			modifier = pam_sf_consolation_modifier
		}
		ai_chance = {
			base = 100
		}
	}
}

##########################################################################################
# 0029 - A Visit from the Dead (a dream of the departed)
##########################################################################################
pam_secular_faith_events.0029 = {
	type = character_event
	title = pam_secular_faith_events.0029.t
	desc = pam_secular_faith_events.0029.desc
	theme = christian
	override_background = bedchamber

	left_portrait = {
		character = root
		animation = shock
		outfit_tags = { nightgown }
		camera = camera_event_very_left
	}
	right_portrait = {
		character = scope:departed
		animation = dead
		camera = camera_event_scheme_center_forward
	}
	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 }
		widget = { gui = event_window_widget_vfx_right_character_double_vision_severe container = foreground_shader_vfx_container }
		widget = { gui = event_window_widget_vfx_right_character_flickering_candlelight container = foreground_shader_vfx_container }
	}

	cooldown = { years = 15 }

	trigger = {
		pam_secular_faith_christian_actor_trigger = yes
		any_close_family_member = {
			even_if_dead = yes
			is_alive = no
			age >= 12
		}
	}

	immediate = {
		save_scope_as = root_scope
		random_close_family_member = {
			even_if_dead = yes
			limit = {
				is_alive = no
				age >= 12
			}
			save_scope_as = departed
		}
	}

	option = { # Heed their words
		name = pam_secular_faith_events.0029.a
		change_spiritual_fulfillment = minor_spiritual_fulfillment_value
		add_character_modifier = {
			modifier = pam_sf_grief_solace_modifier
			years = 15
		}
		ai_chance = {
			base = 100
		}
	}

	option = { # Pray for their soul
		name = pam_secular_faith_events.0029.b
		change_spiritual_fulfillment = minor_spiritual_fulfillment_value
		add_character_modifier = {
			modifier = pam_sf_grief_warning_modifier
			years = 15
		}
		ai_chance = {
			base = 100
		}
	}

	option = { # Dismiss it as grief or temptation
		name = pam_secular_faith_events.0029.c
		add_stress = minor_stress_loss
		ai_chance = {
			base = 100
		}
	}
}

##########################################################################################
# 0030 - The Anchorite
##########################################################################################
scripted_trigger pam_sf_anchorite_candidate_valid_trigger = {
	is_available_ai_adult = yes
	has_personality_submissive_trigger = yes
	rite = {
		has_at_least_tenet_status = {
			tenet = tenet_anachoresis
			status = permitted
		}
	}
	ai_zeal >= 50
}

pam_secular_faith_events.0030 = {
	type = character_event
	title = pam_secular_faith_events.0030.t
	desc = pam_secular_faith_events.0030.desc
	theme = christian
	override_background = throne_room

	left_portrait = {
		character = root
		animation = contemplating
	}
	right_portrait = {
		character = scope:would_be_anchorite
		animation = prayer_standing_eyes
	}

	cooldown = { years = 30 }

	trigger = {
		pam_secular_faith_christian_actor_trigger = yes
		rite = {
			has_at_least_tenet_status = {
				tenet = tenet_anachoresis
				status = permitted
			}
		}
		any_courtier = {
			pam_sf_anchorite_candidate_valid_trigger = yes
		}
		any_held_title = {
			tier = tier_county
			any_county_province = {
				has_holding_type = church_holding
				NOT = {
					has_province_modifier = pam_sf_immured_anchorite_modifier
				}
			}
		}
	}

	immediate = {
		random_courtier = {
			limit = { pam_sf_anchorite_candidate_valid_trigger = yes }
			save_scope_as = would_be_anchorite
		}
		random_held_title = {
			limit = {
				tier = tier_county
				any_county_province = { has_holding_type = church_holding }
			}
			save_scope_as = county_scope
			save_scope_as = holy_site_scope
			random_county_province = {
				limit = {
					has_holding_type = church_holding
					NOT = {
						has_province_modifier = pam_sf_immured_anchorite_modifier
					}
				}
				save_scope_as = church_scope
			}
		}
	}

	option = { # Immure them
		name = pam_secular_faith_events.0030.a
		add_piety = medium_piety_gain
		scope:would_be_anchorite = {
			death = { death_reason = death_immurement }
		}
		scope:church_scope = {
			add_province_modifier = {
				modifier = pam_sf_immured_anchorite_modifier
			}
		}
		stress_and_fulfillment_impact = {
			base = minor_stress_impact_gain
			compassionate = medium_stress_impact_gain
			cynical = minor_stress_impact_gain
			callous = medium_stress_impact_loss
			sadistic = medium_stress_impact_loss
		}
		ai_chance = {
			base = 100
			modifier = {
				OR = {
					has_trait = compassionate
					has_trait = cynical
					scope:would_be_anchorite = {
						OR = {
							is_primary_heir_of = root
							has_relation_friend = root
							has_relation_lover = root
						}
					}
				}
				factor = 0
			}
		}
	}

	option = { # Stop them
		name = pam_secular_faith_events.0030.b
		scope:would_be_anchorite = {
			if = {
				limit = {
					NOT = { has_trait = reclusive }
				}
				add_trait = reclusive
			}
		}
		reverse_add_opinion = {
			target = scope:would_be_anchorite
			modifier = disappointed_opinion
			opinion = -15
		}
		ai_chance = {
			base = 100
		}
	}
}

##########################################################################################
# 0031 - An Argument of Scholars
##########################################################################################
scripted_trigger pam_sf_learned_disputant_valid_trigger = {
	is_available_ai_adult = yes
	OR = {
		learning >= high_skill_rating
		is_clergy = yes
	}
	faith = root.faith
	OR = {
		is_clergy = yes
		has_education_learning_trigger = yes
		has_trait = lifestyle_mystic
		has_trait = lifestyle_scholar
		has_trait = theologian
	}
}

pam_secular_faith_events.0031 = {
	type = character_event
	title = pam_secular_faith_events.0031.t
	desc = pam_secular_faith_events.0031.desc
	theme = christian
	override_background = council_chamber

	left_portrait = {
		character = scope:disputant_one
		animation = condemnation
		camera = camera_event_left_away_3_4
	}
	right_portrait = {
		character = scope:disputant_two
		animation = preaching
		camera = camera_event_very_right_fov35
	}

	cooldown = { years = 15 }

	trigger = {
		pam_secular_faith_christian_actor_trigger = yes
		any_courtier = {
			count >= 2
			pam_sf_learned_disputant_valid_trigger = yes
		}
		any_desired_tenet = {
			count >= 2
			only_positive = yes
			threshold = 1
			selection_count = 97
			save_temporary_scope_as = pam_sf_candidate
			NOT = { root = { any_personal_tenet = { this = scope:pam_sf_candidate } } }
			root.faith.main_rite = {
				NOT = {
					has_tenet_status = {
						tenet = scope:pam_sf_candidate
						status = prohibited
					}
				}
			}
		}
	}

	immediate = {
		random_courtier = {
			limit = { pam_sf_learned_disputant_valid_trigger = yes }
			save_scope_as = disputant_one
		}
		random_courtier = {
			limit = {
				pam_sf_learned_disputant_valid_trigger = yes
				NOT = { this = scope:disputant_one }
			}
			save_scope_as = disputant_two
		}
		random_desired_tenet = {
			only_positive = yes
			threshold = 1
			selection_count = 97
			limit = {
				save_temporary_scope_as = pam_sf_candidate
				NOT = { root = { any_personal_tenet = { this = scope:pam_sf_candidate } } }
				root.faith.main_rite = {
					NOT = {
						has_tenet_status = {
							tenet = scope:pam_sf_candidate
							status = prohibited
						}
					}
				}
			}
			save_scope_as = tenet_1
		}
		random_desired_tenet = {
			only_positive = yes
			threshold = 1
			selection_count = 97
			limit = {
				save_temporary_scope_as = pam_sf_candidate
				NOT = { root = { any_personal_tenet = { this = scope:pam_sf_candidate } } }
				root.faith.main_rite = {
					NOT = {
						has_tenet_status = {
							tenet = scope:pam_sf_candidate
							status = prohibited
						}
					}
				}
				this != scope:tenet_1
			}
			save_scope_as = tenet_2
		}
	}

	option = { # Join the debate
		name = pam_secular_faith_events.0031.a
		trigger = {
			has_trait = lifestyle_scholar
		}
		show_as_unavailable = { always = yes }
		add_piety = medium_piety_gain
		add_scholar_trait_or_xp_effect = { VALUE = 30 }
		scope:disputant_one = {
			add_opinion = {
				modifier = humbled_opinion
				opinion = 30
				target = root
			}
		}
		scope:disputant_two = {
			add_opinion = {
				modifier = humbled_opinion
				opinion = 30
				target = root
			}
		}
		ai_chance = {
			base = 100
		}
	}

	option = { # Adopt the first tenet for free
		name = pam_secular_faith_events.0031.b
		scope:disputant_one = {
			add_opinion = {
				modifier = respect_opinion
				opinion = 15
				target = root
			}
		}
		force_set_personal_tenet = scope:tenet_1
		stress_and_fulfillment_impact = {
			fickle = minor_stress_impact_loss
			content = minor_stress_impact_gain
			stubborn = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				OR = {
					has_trait = content
					has_trait = stubborn
				}
				factor = 0
			}
		}
	}

	option = { # Adopt the second tenet for free
		name = pam_secular_faith_events.0031.c
		scope:disputant_two = {
			add_opinion = {
				modifier = respect_opinion
				opinion = 15
				target = root
			}
		}
		force_set_personal_tenet = scope:tenet_2
		stress_and_fulfillment_impact = {
			fickle = minor_stress_impact_loss
			content = minor_stress_impact_gain
			stubborn = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				OR = {
					has_trait = content
					has_trait = stubborn
				}
				factor = 0
			}
		}
	}

	option = { # Enjoy the spirited court
		name = pam_secular_faith_events.0031.d
		add_piety = minor_piety_gain
		ai_chance = {
			base = 100
		}
	}
}

##########################################################################################
# 0032 - The Tempting Hour (a fast tested)
##########################################################################################
pam_secular_faith_events.0032 = {
	type = character_event
	title = pam_secular_faith_events.0032.t
	desc = pam_secular_faith_events.0032.desc_food
	theme = christian
	override_background = bedchamber

	left_portrait = {
		character = root
		animation = mental_anguish
		outfit_tags = { nightgown }
		camera = camera_event_center_close_to_right
	}

	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 }
	}

	cooldown = { years = 10 }

	trigger = {
		pam_secular_faith_landed_actor_trigger = yes
		religion = { is_in_family = rf_abrahamic }
		OR = {
			has_trait = gluttonous
			has_trait = lazy
			has_trait = impatient
			has_trait = lustful
		}
		NOR = {
			has_trait = temperate
			has_trait = inappetetic
		}
	}

	immediate = {
		random_character_trait = {
			limit = {
				OR = {
					this = trait:gluttonous
					this = trait:lazy
					this = trait:impatient
					this = trait:lustful
				}
			}
			save_scope_as = vice_trait
		}
	}

	option = { # Justify urges
		name = pam_secular_faith_events.0032.a
		trigger = {
			has_trait = lifestyle_scholar
		}
		show_as_unavailable = { always = yes }
		change_spiritual_fulfillment = minor_spiritual_fulfillment_loss
		hidden_effect = { # The chung
			change_current_weight = 50
		}
		add_scholar_trait_or_xp_effect = { VALUE = 30 }
		if = {
			limit = {
				NOT = { knows_tenet = tenet_hedonistic }
			}
			add_known_tenet = tenet_hedonistic
			pam_secular_faith_seed_tenet_message_effect = { TENET = tenet:tenet_hedonistic }
		}
		if = {
			limit = {
				NOT = { knows_tenet = tenet_carnal_exaltation }
			}
			add_known_tenet = tenet_carnal_exaltation
			pam_secular_faith_seed_tenet_message_effect = { TENET = tenet:tenet_carnal_exaltation }
		}
		if = {
			limit = {
				NOT = { knows_tenet = tenet_pursuit_of_power }
			}
			add_known_tenet = tenet_pursuit_of_power
			pam_secular_faith_seed_tenet_message_effect = { TENET = tenet:tenet_pursuit_of_power }
		}
		stress_and_fulfillment_impact = {
			content = minor_stress_impact_gain
			patient = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = content
					has_trait = patient
				}
			}
		}
	}

	option = { # Hold fast
		name = pam_secular_faith_events.0032.b
		change_spiritual_fulfillment = medium_spiritual_fulfillment_value
		stress_and_fulfillment_impact = {
			gluttonous = medium_stress_impact_gain
			lazy = minor_stress_impact_gain
			impatient = minor_stress_impact_gain
			content = minor_stress_impact_loss
			patient = minor_stress_impact_loss
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = gluttonous
					has_trait = lazy
					has_trait = impatient
				}
			}
		}
	}

	option = { # Indulge in secret
		name = pam_secular_faith_events.0032.c
		change_spiritual_fulfillment = minor_spiritual_fulfillment_loss
		hidden_effect = { # The chung
			change_current_weight = 50
		}
		stress_and_fulfillment_impact = {
			base = medium_stress_impact_loss
			content = minor_stress_impact_gain
			patient = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = content
					has_trait = patient
				}
			}
		}
	}
}

##########################################################################################
# 0033 - Pillow Sermons (a spouse who believes differently)
##########################################################################################
pam_secular_faith_events.0033 = {
	type = character_event
	title = pam_secular_faith_events.0033.t
	desc = pam_secular_faith_events.0033.desc
	theme = christian
	override_background = bedchamber

	left_portrait = {
		character = root
		animation = admiration
		outfit_tags = { nightgown }
	}
	right_portrait = {
		character = scope:believing_spouse
		animation = preaching_no_book
		camera = camera_event_right_to_the_right
		outfit_tags = { nightgown }
	}

	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 }
	}

	cooldown = { years = 5 }

	trigger = {
		pam_secular_faith_landed_actor_trigger = yes
		primary_spouse ?= {
			is_available_ai_adult = yes
			rite != root.rite
			NOT = {
				has_relation_rival = root
			}
			any_character_tenet = {
				save_temporary_scope_as = tenet_check
				root.primary_spouse = { knows_tenet = scope:tenet_check }
				NOT = {
					root = {
						knows_tenet = scope:tenet_check
					}
				}
			}
		}
	}

	immediate = {
		save_scope_as = root_scope
		primary_spouse = {
			save_scope_as = believing_spouse
			save_scope_as = passive_learn_source
			random_character_tenet = {
				limit = {
					save_temporary_scope_as = tenet_check
					root.primary_spouse = { knows_tenet = scope:tenet_check }
					NOT = {
						root = {
							knows_tenet = scope:tenet_check
						}
					}
				}
				save_scope_as = new_tenet
			}
		}
	}

	option = { # Study the rite
		name = pam_secular_faith_events.0033.a
		trigger = {
			NOT = {
				knows_rite_level = {
					target = scope:believing_spouse.rite
					value >= 100
				}
			}
		}
		add_scholar_trait_or_xp_effect = { VALUE = 5 }
		add_known_tenet = scope:new_tenet
		pam_secular_faith_seed_tenet_message_effect = { TENET = scope:new_tenet }
		add_known_rite = scope:believing_spouse.rite
		send_interface_message = {
			type = msg_passive_learned_rite
			desc = msg_passive_learned_rite_desc
			left_icon = scope:passive_learn_source
			right_icon = scope:passive_learn_source.rite
		}
		ai_chance = {
			base = 100
		}
	}

	option = { # Deepen the bond
		name = pam_secular_faith_events.0033.b
		trigger = {
			can_set_relation_lover_trigger = { CHARACTER = scope:believing_spouse }
		}
		set_relation_lover = {
			target = scope:believing_spouse
			reason = pam_sf_lover_two_faiths
		}
		add_known_tenet = scope:new_tenet
		pam_secular_faith_seed_tenet_message_effect = { TENET = scope:new_tenet }
		ai_chance = {
			base = 100
		}
	}

	option = { # Sleep
		name = pam_secular_faith_events.0033.c
		scope:believing_spouse = {
			add_opinion = {
				modifier = sadness_opinion
				opinion = -10
				target = root
			}
		}
		stress_and_fulfillment_impact = {
			base = minor_stress_impact_loss
			lustful = minor_stress_impact_gain
			compassionate = minor_stress_impact_gain
			humble = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = lustful
					has_trait = compassionate
					has_trait = humble
				}
			}
		}
	}
}

##########################################################################################
# 0034 - The Foundling
##########################################################################################
pam_secular_faith_events.0034 = {
	type = character_event
	title = pam_secular_faith_events.0034.t
	desc = pam_secular_faith_events.0034.desc
	theme = christian
	override_background = temple

	left_portrait = {
		character = root
		animation = worry
	}
	right_portrait = {
		character = scope:chaplain
		animation = newborn
	}
	lower_center_portrait = scope:foundling
	widgets = {
		widget = { gui = event_window_widget_vfx_background_flickering_candlelight_dark container = foreground_shader_vfx_container }
		widget = { gui = event_window_widget_vfx_left_character_flickering_candlelight_dark container = foreground_shader_vfx_container }
		widget = { gui = event_window_widget_vfx_right_character_flickering_candlelight_dark container = foreground_shader_vfx_container }
	}

	cooldown = { years = 5 }

	trigger = {
		pam_secular_faith_landed_actor_trigger = yes
		cp:councillor_court_chaplain ?= {
			is_available_ai_adult = yes
			NOR = {
				has_trait = sadistic
				has_trait = callous
			}
		}
		OR = {
			is_ai = no
			NOT = {
				any_child = {
					is_alive = yes
				}
			}
		}
		faith = {
			faith_has_monasticism_trigger = yes
		}
	}

	immediate = {
		cp:councillor_court_chaplain = { save_scope_as = chaplain }
		if = {
			limit = {
				capital_county.clerical_region_title.holder ?= {
					this != root
					is_ai = yes
				}
			}
			capital_county.clerical_region_title = { save_scope_as = archdiocese }
			capital_county.clerical_region_title.holder = { save_scope_as = archbishop }
		}
		create_character = {
			location = root.capital_province
			age = 0
			faith = root.capital_province.faith
			rite = root.capital_province.rite
			culture = root.capital_province.culture
			dynasty = none
			gender_female_chance = root_faith_dominant_gender_adjusted_female_chance
			save_scope_as = foundling
			after_creation = {
				change_current_weight = -75
				random_list = {
					130 = {
						add_trait = sickly
					}
					10 = {
						add_trait = scarred
					}
					10 = {
						add_trait = one_eyed
					}
					10 = {
						add_trait = albino
					}
					10 = {
						add_trait = scaly
					}
					10 = {
						add_trait = blind
					}
					10 = {
						add_trait = spindly
					}
					10 = {
						add_trait = beauty_bad_1
					}
				}
			}
		}
		scope:foundling = {
			random_character_trait = {
				limit = {
					OR = {
						this = trait:sickly
						this = trait:scarred
						this = trait:one_eyed
						this = trait:albino
						this = trait:scaly
						this = trait:blind
						this = trait:spindly
						this = trait:beauty_bad_1
					}
				}
				save_scope_as = trait_scope
			}
		}
	}

	option = { # Adopt the child
		name = pam_secular_faith_events.0034.a
		trigger = {
			can_be_parent_of = scope:foundling
			exists = house
			NAND = {
				is_clergy = yes
				rite = { rite_has_doctrine = doctrine_clerical_marriage_disallowed }
			}
		}

		add_courtier = scope:foundling

		change_spiritual_fulfillment = medium_spiritual_fulfillment_value

		if = {
			limit = {
				is_male = yes
			}
			scope:foundling = { set_father = root }
		}
		else = {
			scope:foundling = { set_mother = root }
		}
		if = {
			limit = { exists = house }
			scope:foundling = { set_house = root.house }
		}
		set_relation_friend = {
			reason = friend_adopted
			target = scope:foundling
		}
		scope:foundling = {
			if = {
				limit = {
					culture != root.culture
				}
				set_culture = root.culture
			}
			if = {
				limit = {
					rite != root.rite
				}
				set_character_rite = root.rite
			}
		}

		stress_and_fulfillment_impact = {
			compassionate = massive_stress_impact_loss
			cynical = minor_stress_impact_gain
			sadistic = medium_stress_impact_gain
			callous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = cynical
					has_trait = sadistic
					has_trait = callous
				}
			}
		}
	}

	option = { # Place them with the monastery
		name = pam_secular_faith_events.0034.b
		trigger = {
			exists = scope:archbishop
		}
		add_piety = medium_piety_gain
		scope:foundling = {
			add_trait = devoted
			if = {
				limit = {
					rite != scope:archbishop.rite
				}
				set_character_rite = scope:archbishop.rite
			}
		}
		scope:archbishop = {
			add_opinion = {
				target = root
				modifier = pious_opinion
				opinion = 15
			}
			add_courtier = scope:foundling
			if = {
				limit = { num_of_relation_ward < 2 }
				scope:foundling = {
					set_relation_guardian = scope:archbishop
				}
			}
		}
		stress_and_fulfillment_impact = {
			compassionate = minor_stress_impact_loss
			cynical = minor_stress_impact_gain
			sadistic = medium_stress_impact_gain
			callous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = cynical
					has_trait = sadistic
					has_trait = callous
				}
			}
		}
	}

	option = { # Let them stay as a monk
		name = pam_secular_faith_events.0034.c
		add_piety = minor_piety_gain
		add_courtier = scope:foundling
		scope:foundling = {
			add_trait = devoted
			if = {
				limit = {
					rite != scope:chaplain.rite
				}
				set_character_rite = scope:chaplain.rite
			}
		}
		scope:chaplain = {
			if = {
				limit = { num_of_relation_ward < 2 }
				scope:foundling = {
					set_relation_guardian = scope:chaplain
				}
			}
		}
		stress_and_fulfillment_impact = {
			compassionate = minor_stress_impact_loss
			cynical = minor_stress_impact_gain
			sadistic = medium_stress_impact_gain
			callous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = cynical
					has_trait = sadistic
					has_trait = callous
				}
			}
		}
	}

	option = { # Turn them away
		name = pam_secular_faith_events.0034.d
		scope:foundling = {
			death = { death_reason = death_abandonment }
		}
		stress_and_fulfillment_impact = {
			sadistic = massive_stress_impact_loss
			callous = minor_stress_impact_loss
			compassionate = major_stress_impact_gain
			humble = medium_stress_impact_gain
			zealous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			modifier = {
				factor = 0
				OR = {
					has_trait = compassionate
					has_trait = humble
					has_trait = zealous
				}
			}
		}
	}
}

##########################################################################################
# 0035 - The Mortification (a courtier's holy self-destruction)
##########################################################################################
scripted_trigger pam_sf_mortification_sufferer_valid_trigger = {
	is_available_ai_adult = yes
	faith = root.faith
	ai_zeal >= 50
	num_sinful_traits >= 1
	num_virtuous_traits <= 0
	NOR = {
		has_trait = cynical
		has_trait = wounded
	}
}

pam_secular_faith_events.0035 = {
	type = character_event
	title = pam_secular_faith_events.0035.t
	desc = pam_secular_faith_events.0035.desc
	theme = christian
	override_background = corridor_day

	left_portrait = {
		character = root
		animation = worry
	}
	right_portrait = {
		character = scope:sufferer
		animation = self_flagellation
		outfit_tags = { nightgown }
		camera = camera_event_right_forward
	}

	cooldown = { years = 10 }

	trigger = {
		pam_secular_faith_christian_actor_trigger = yes
		rite = {
			has_at_least_tenet_status = {
				tenet = tenet_mortification_of_the_flesh
				status = permitted
			}
		}
		any_courtier = {
			pam_sf_mortification_sufferer_valid_trigger = yes
		}
	}

	immediate = {
		random_courtier = {
			limit = { pam_sf_mortification_sufferer_valid_trigger = yes }
			add_trait = flagellant
			save_scope_as = sufferer
			random_character_trait = {
				limit = {
					save_temporary_scope_as = trait_check
					root.rite = {
						trait_is_sin_rite = scope:trait_check
					}
				}
				save_scope_as = sinful_trait
			}
			increase_wounds_effect = { REASON = whipping }
		}
	}

	option = { # Join them
		name = pam_secular_faith_events.0035.a
		add_scholar_trait_or_xp_effect = { VALUE = 15 }
		if = {
			limit = {
				NOT = {
					has_personal_tenet = tenet_mortification_of_the_flesh
				}
			}
			force_set_personal_tenet = tenet_mortification_of_the_flesh
		}
		add_piety = major_piety_gain
		increase_wounds_effect = { REASON = whipping }
		scope:sufferer = {
			add_piety = major_piety_gain
			change_spiritual_fulfillment = major_spiritual_fulfillment_value
			increase_wounds_effect = { REASON = whipping }
		}
		stress_and_fulfillment_impact = {
			chaste = major_stress_impact_loss
			flagellant = major_stress_impact_loss
			craven = major_stress_impact_gain
			cynical = medium_stress_impact_gain
			lustful = medium_stress_impact_gain
		}
		ai_chance = {
			base = 0
			modifier = {
				add = 100
				OR = {
					has_trait = chaste
					has_trait = flagellant
				}
			}
		}
	}

	option = { # Let them mortify
		name = pam_secular_faith_events.0035.b
		add_piety = minor_piety_gain
		scope:sufferer = {
			add_piety = major_piety_gain
			change_spiritual_fulfillment = major_spiritual_fulfillment_value
			increase_wounds_effect = { REASON = whipping }
		}
		stress_and_fulfillment_impact = {
			compassionate = minor_stress_impact_gain
			cynical = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			modifier = {
				factor = 0
				OR = {
					has_trait = compassionate
					has_trait = cynical
				}
			}
		}
	}

	option = { # Stop them
		name = pam_secular_faith_events.0035.c
		scope:sufferer = {
			add_opinion = {
				target = root
				modifier = impious_opinion
				opinion = -10
			}
			remove_trait = wounded_1
		}
		random = {
			chance = 35
			send_interface_toast = {
				type = event_toast_effect_good
				title = pam_sf_scourge_abandoned_toast
				left_icon = scope:sufferer
				right_icon = root
				scope:sufferer = { remove_trait = flagellant }
			}
		}
		stress_and_fulfillment_impact = {
			compassionate = minor_stress_impact_loss
			chaste = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			modifier = {
				factor = 0
				has_trait = chaste
			}
		}
	}
}

##########################################################################################
# 0036 - Wisdom of the Anchorite
##########################################################################################
scripted_trigger pam_sf_desert_hermit_valid_trigger = {
	is_available_healthy_ai_adult = yes
	has_no_particular_noble_roots_trigger = yes
	root.faith = { has_allowed_gender_for_clergy = prev }
	religion = { is_in_family = rf_abrahamic }
	rite = {
		has_at_least_tenet_status = {
			tenet = tenet_anachoresis
			status = permitted
		}
	}
	ai_zeal >= 25
}

pam_secular_faith_events.0036 = {
	type = character_event
	title = pam_secular_faith_events.0036.t
	desc = pam_secular_faith_events.0036.desc
	theme = christian
	override_background = throne_room

	left_portrait = {
		character = root
		animation = personality_zealous
		camera = camera_event_crowd
	}
	right_portrait = {
		character = scope:hermit
		animation = divine_gesture_4
		outfit_tags = { beggar_rags }
	}

	cooldown = { years = 10 }

	trigger = {
		pam_secular_faith_clergy_ok_actor_trigger = yes
		any_pool_character = {
			province = root.location
			pam_sf_desert_hermit_valid_trigger = yes
		}
		any_realm_county = {
			any_county_province = {
				has_holding = no
			}
		}
	}

	immediate = {
		random_pool_character = {
			province = root.location
			limit = { pam_sf_desert_hermit_valid_trigger = yes }
			save_scope_as = hermit
		}
		hidden_effect = {
			scope:hermit = {
				change_current_weight = -100
				if = {
					limit = { NOT = { has_trait = lifestyle_mystic } }
					add_trait = lifestyle_mystic
					add_trait_xp = {
						trait = lifestyle_mystic
						value = 50
					}
				}
			}
		}
		random_realm_county = {
			limit = {
				any_county_province = {
					has_holding = no
				}
			}
			random_county_province = {
				limit = {
					has_holding = no
				}
				save_scope_as = hermit_location
			}
		}
	}

	option = { # Open yourself to their counsel
		name = pam_secular_faith_events.0036.a
		add_piety = minor_piety_gain
		add_prestige = medium_prestige_loss
		if = {
			limit = {
				NOT = {
					knows_tenet = tenet_anachoresis
				}
			}
			add_known_tenet = tenet_anachoresis
			pam_secular_faith_seed_tenet_message_effect = { TENET = tenet:tenet_anachoresis }
		}
		if = {
			limit = {
				NOT = { has_trait = lifestyle_mystic }
			}
			add_trait = lifestyle_mystic
		}
		else = {
			add_trait_xp = {
				trait = lifestyle_mystic
				value = 50
			}
		}
		hidden_effect = {
			scope:hermit = { move_to_pool_at = scope:hermit_location }
		}
		stress_and_fulfillment_impact = {
			eccentric = minor_stress_impact_loss
			cynical = minor_stress_impact_gain
			arrogant = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			modifier = {
				factor = 0
				OR = {
					has_trait = cynical
					has_trait = arrogant
				}
			}
		}
	}

	option = { # Ask only for their blessing
		name = pam_secular_faith_events.0036.b
		add_piety = minor_piety_gain
		add_prestige = medium_prestige_loss
		if = {
			limit = {
				NOT = {
					knows_tenet = tenet_anachoresis
				}
			}
			add_known_tenet = tenet_anachoresis
			pam_secular_faith_seed_tenet_message_effect = { TENET = tenet:tenet_anachoresis }
		}
		add_scholar_trait_or_xp_effect = { VALUE = 10 }
		hidden_effect = {
			scope:hermit = { move_to_pool_at = scope:hermit_location }
		}
		stress_and_fulfillment_impact = {
			cynical = minor_stress_impact_gain
			arrogant = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			modifier = {
				factor = 0
				OR = {
					has_trait = cynical
					has_trait = arrogant
				}
			}
		}
	}

	option = { # Reject their presumption
		name = pam_secular_faith_events.0036.c
		hidden_effect = {
			scope:hermit = { move_to_pool_at = scope:hermit_location }
		}
		stress_and_fulfillment_impact = {
			humble = minor_stress_impact_gain
			trusting = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			modifier = {
				factor = 0
				OR = {
					has_trait = humble
					has_trait = trusting
				}
			}
		}
	}
}

##########################################################################################
# 0037 - Carnal Revelation (a willing partner and a night of sacred flesh; discover Carnal Exaltation)
##########################################################################################
scripted_trigger pam_sf_carnal_partner_valid_trigger = {
	is_available_ai_adult = yes
	this != root
	NOR = {
		has_trait = chaste
		has_trait = celibate
		has_relation_rival = root
		has_relation_lover = root
	}
	are_characters_sensible_lovers_trigger = { INSTIGATING_LOVER = root TARGET_OF_LOVE = this }
}

pam_secular_faith_events.0037 = {
	type = character_event
	title = pam_secular_faith_events.0037.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:reveler = {
						NOT = {
							exists = liege
						}
					}
				}
				desc = pam_secular_faith_events.0037.desc_wanderer
			}
			triggered_desc = {
				trigger = { always = yes }
				desc = pam_secular_faith_events.0037.desc_normal
			}
		}
		desc = pam_secular_faith_events.0037.desc
	}
	theme = christian
	override_background = bedchamber

	left_portrait = {
		character = root
		animation = love
	}
	right_portrait = {
		character = scope:reveler
		triggered_animation = {
			trigger = {
				is_female = yes
			}
			animation = fanning_coyly
		}
		animation = flirtation_left
	}
	widgets = {
		widget = { gui = event_window_widget_vfx_background_flickering_candlelight_dark container = foreground_shader_vfx_container }
		widget = { gui = event_window_widget_vfx_left_character_flickering_candlelight_dark container = foreground_shader_vfx_container }
		widget = { gui = event_window_widget_vfx_right_character_flickering_candlelight_dark container = foreground_shader_vfx_container }
	}

	cooldown = { years = 10 }

	weight_multiplier = {
		base = 1
		modifier = {
			factor = 10
			any_courtier = {
				pam_sf_carnal_partner_valid_trigger = yes
				OR = {
					has_trait = lustful
					has_trait = seducer
					has_trait = deviant
					has_trait = eccentric
					has_trait = rakish
				}
			}
		}
	}

	trigger = {
		pam_secular_faith_landed_actor_trigger = yes
		NOR = {
			has_trait = chaste
			has_trait = celibate
			knows_tenet = tenet_carnal_exaltation
		}
		OR = {
			any_courtier = { pam_sf_carnal_partner_valid_trigger = yes }
			any_pool_character = {
				province = root.location
				pam_sf_carnal_partner_valid_trigger = yes
			}
		}
	}

	immediate = {
		# Any sensible lover may catch the eye, but a carnal bent makes a partner far likelier.
		every_courtier = {
			limit = { pam_sf_carnal_partner_valid_trigger = yes }
			add_to_list = carnal_partner_list
		}
		every_pool_character = {
			province = root.location
			limit = { pam_sf_carnal_partner_valid_trigger = yes }
			add_to_list = carnal_partner_list
		}
		random_in_list = {
			list = carnal_partner_list
			weight = {
				base = 1
				modifier = { add = 10 has_trait = lustful }
				modifier = { add = 10 has_trait = seducer }
				modifier = { add = 10 has_trait = rakish }
				modifier = { add = 5 has_trait = eccentric }
				modifier = { add = 10 has_trait = deviant }
				modifier = {
					add = 5
					is_of_major_interest_to_root_trigger = yes
				}
				modifier = {
					add = 5
					is_of_minor_interest_to_root_trigger = yes
				}
			}
			save_scope_as = reveler
			add_character_flag = is_naked
		}
	}

	option = { # Give in to the night
		name = pam_secular_faith_events.0037.a
		add_known_tenet = tenet_carnal_exaltation
		pam_secular_faith_seed_tenet_message_effect = { TENET = tenet:tenet_carnal_exaltation }
		change_spiritual_fulfillment = minor_spiritual_fulfillment_value
		set_relation_lover = {
			target = scope:reveler
			reason = pam_sf_lover_carnal_revelation
		}
		had_sex_with_effect = {
			CHARACTER = scope:reveler
			PREGNANCY_CHANCE = pregnancy_chance
		}
		ai_chance = {
			base = 100
		}
	}

	option = { # Deny the flesh
		name = pam_secular_faith_events.0037.b
		add_piety = minor_piety_gain
		stress_and_fulfillment_impact = {
			lustful = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = { has_trait = lustful factor = 0 }
		}
	}

	after = {
		scope:reveler = { remove_character_flag = is_naked }
	}
}

##########################################################################################
# 0038 - A Taste of Paradise (discover Hedonism)
##########################################################################################
scripted_trigger appropriate_hedonist_trigger = {
	is_available_ai_adult = yes
	faith = root.faith
	OR = {
		has_trait = gluttonous
		has_trait = drunkard
		has_trait = comfort_eater
	}
	NOR = {
		has_trait = temperate
		has_relation_rival = root
	}
}

pam_secular_faith_events.0038 = {
	type = character_event
	title = pam_secular_faith_events.0038.t
	desc = pam_secular_faith_events.0038.desc
	theme = christian
	override_background = feast

	left_portrait = {
		character = root
		animation = drink_goblet
		camera = camera_event_very_left
	}
	right_portrait = {
		character = scope:reveler
		animation = wedding_drunk
	}

	cooldown = { years = 10 }

	trigger = {
		pam_secular_faith_landed_actor_trigger = yes
		NOT = { knows_tenet = tenet_hedonistic }
		any_courtier = {
			appropriate_hedonist_trigger = yes
		}
	}

	immediate = {
		random_courtier = {
			limit = {
				appropriate_hedonist_trigger = yes
			}
			save_scope_as = reveler
		}
	}

	option = { # A true epiphany
		name = pam_secular_faith_events.0038.a
		trigger = {
			OR = {
				has_trait = gluttonous
				has_trait = drunkard
				has_trait = comfort_eater
			}
		}
		add_known_tenet = tenet_hedonistic
		pam_secular_faith_seed_tenet_message_effect = { TENET = tenet:tenet_hedonistic }
		add_character_modifier = {
			modifier = pam_sf_free_feast_modifier
			years = 5
		}
		change_spiritual_fulfillment = major_spiritual_fulfillment_value
		mystic_lifestyle_rank_up_effect = yes
		ai_chance = {
			base = 100
		}
	}

	option = { # Savor the idea - and set a table to match
		name = pam_secular_faith_events.0038.b
		add_known_tenet = tenet_hedonistic
		pam_secular_faith_seed_tenet_message_effect = { TENET = tenet:tenet_hedonistic }
		add_character_modifier = {
			modifier = pam_sf_free_feast_modifier
			years = 5
		}
		stress_and_fulfillment_impact = {
			base = minor_stress_loss
			temperate = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = { has_trait = temperate factor = 0 }
		}
	}

	option = { # Dismiss it as decadence
		name = pam_secular_faith_events.0038.c
		add_piety = minor_piety_gain
		stress_and_fulfillment_impact = {
			gluttonous = minor_stress_impact_gain
			drunkard = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = gluttonous
					has_trait = drunkard
				}
			}
		}
	}
}

##########################################################################################
# 0039 - A Prayer in the Dark (a devout spymaster uncovers a secret at prayer; discover Sacred Shadows)
##########################################################################################
scripted_trigger pam_sf_secret_keeper_valid_trigger = {
	is_available_ai_adult = yes
	faith = root.faith
	this != root
	any_secret = {
		NOT = { is_known_by = root }
	}
	this != root.cp:councillor_spymaster
}

pam_secular_faith_events.0039 = {
	type = character_event
	title = pam_secular_faith_events.0039.t
	desc = pam_secular_faith_events.0039.desc
	theme = christian
	override_background = corridor_night
	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 = interested
	}
	right_portrait = {
		character = scope:spymaster_scope
		animation = spymaster
	}
	lower_center_portrait = scope:secret_keeper

	cooldown = { years = 10 }

	trigger = {
		pam_secular_faith_landed_actor_trigger = yes
		NOT = { knows_tenet = tenet_sacred_shadows }
		cp:councillor_spymaster ?= {
			is_available_ai_adult = yes
			faith = root.faith
			NOR = {
				has_relation_rival = root
				has_trait = cynical
			}
			OR = {
				has_trait = eccentric
				has_trait = zealous
				has_trait = humble
				has_trait = theologian
				has_trait = lifestyle_scholar
				is_clergy = yes
				ai_zeal >= 0
				piety_level >= 2
			}
		}
		OR = {
			any_courtier = { pam_sf_secret_keeper_valid_trigger = yes }
			any_vassal = { pam_sf_secret_keeper_valid_trigger = yes }
			liege ?= { any_vassal = { pam_sf_secret_keeper_valid_trigger = yes } }
		}
	}

	immediate = {
		cp:councillor_spymaster = { save_scope_as = spymaster_scope }
		every_courtier = {
			limit = { pam_sf_secret_keeper_valid_trigger = yes }
			add_to_list = secret_keeper_list
		}
		every_vassal = {
			limit = { pam_sf_secret_keeper_valid_trigger = yes }
			add_to_list = secret_keeper_list
		}
		liege ?= {
			every_vassal = {
				limit = { pam_sf_secret_keeper_valid_trigger = yes }
				add_to_list = secret_keeper_list
			}
		}
		random_in_list = {
			list = secret_keeper_list
			# A fellow ruler's secret is juicier leverage than a courtier's.
			weight = {
				base = 1
				modifier = { add = 2 is_ruler = yes }
			}
			save_scope_as = secret_keeper
		}
		scope:secret_keeper = {
			random_secret = {
				limit = { NOT = { is_known_by = root } }
				save_scope_as = the_secret
			}
		}
	}

	option = { # The god does work in shadow
		name = pam_secular_faith_events.0039.a
		add_known_tenet = tenet_sacred_shadows
		pam_secular_faith_seed_tenet_message_effect = { TENET = tenet:tenet_sacred_shadows }
		scope:the_secret = { reveal_to = root }
		reverse_add_opinion = {
			target = scope:spymaster_scope
			modifier = pious_opinion
			opinion = 20
		}
		stress_and_fulfillment_impact = {
			honest = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = { has_trait = honest factor = 0 }
		}
	}

	option = { # A useful trick, but no miracle
		name = pam_secular_faith_events.0039.b
		scope:the_secret = { reveal_to = root }
		add_piety = minor_piety_gain
		stress_and_fulfillment_impact = {
			deceitful = minor_stress_impact_gain
			paranoid = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = deceitful
					has_trait = paranoid
				}
			}
		}
	}
}

##########################################################################################
# 0040 - Flesh of the Faithful (a learned courtier's account of ancient ritual cannibalism)
##########################################################################################

scripted_trigger appropriate_scholar_trigger = {
	is_available_ai_adult = yes
	root.faith = { has_allowed_gender_for_clergy = prev }
	ai_rationality <= 0
	OR = {
		has_trait = lifestyle_scholar
		has_trait = lifestyle_mystic
		has_trait = theologian
		learning >= 12
	}
	NOT = {
		has_trait = blind
	}
}

pam_secular_faith_events.0040 = {
	type = character_event
	title = pam_secular_faith_events.0040.t
	desc = pam_secular_faith_events.0040.desc
	theme = christian
	override_background = feast
	widgets = {
		widget = { gui = event_window_widget_vfx_background_flickering_candlelight_dark container = foreground_shader_vfx_container }
		widget = { gui = event_window_widget_vfx_left_character_flickering_candlelight_dark container = foreground_shader_vfx_container }
		widget = { gui = event_window_widget_vfx_right_character_flickering_candlelight_dark container = foreground_shader_vfx_container }
	}

	left_portrait = {
		character = root
		animation = drink_goblet
		camera = camera_event_very_left
	}
	right_portrait = {
		character = scope:scholar
		animation = reading
		camera = camera_event_very_right_far
	}

	cooldown = { years = 15 }

	trigger = {
		pam_secular_faith_landed_actor_trigger = yes
		NOT = { knows_tenet = tenet_ritual_cannibalism }
		any_courtier = {
			appropriate_scholar_trigger = yes
		}
	}

	immediate = {
		random_courtier = {
			limit = {
				appropriate_scholar_trigger = yes
			}
			weight = {
				base = 1
				modifier = {
					add = learning
				}
				modifier = {
					add = 5
					is_clergy = yes
				}
			}
			save_scope_as = scholar
		}
	}

	option = { # Eat the scholar
		name = pam_secular_faith_events.0040.a
		trait = cannibal
		trigger = {
			is_cannibal_trigger = yes
		}
		add_known_tenet = tenet_ritual_cannibalism
		pam_secular_faith_seed_tenet_message_effect = { TENET = tenet:tenet_ritual_cannibalism }
		add_character_modifier = {
			modifier = best_meal_of_my_life_modifier
			years = 15
		}

		unknown_murder_effect = {
			VICTIM = scope:scholar
			MURDERER = root
			REASON = death_eaten
		}

		stress_and_fulfillment_impact = {
			base = massive_stress_impact_loss
			compassionate = massive_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = { has_trait = compassionate factor = 0 }
		}
	}

	option = { # Study it as the ancients did
		name = pam_secular_faith_events.0040.b
		add_known_tenet = tenet_ritual_cannibalism
		pam_secular_faith_seed_tenet_message_effect = { TENET = tenet:tenet_ritual_cannibalism }
		add_scholar_trait_or_xp_effect = { VALUE = 20 }
		stress_and_fulfillment_impact = {
			base = minor_stress_gain
			compassionate = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = { has_trait = compassionate factor = 0 }
		}
	}

	option = { # A barbarous heresy, nothing more
		name = pam_secular_faith_events.0040.c
		add_piety = minor_piety_gain
		stress_and_fulfillment_impact = {
			sadistic = minor_stress_impact_gain
			gluttonous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				OR = {
					has_trait = sadistic
					has_trait = gluttonous
				}
				factor = 0
			}
		}
	}
}

##########################################################################################
# 0042 - The Road Made Easy (a clergy sponsor offers to fund a pilgrimage)
##########################################################################################
scripted_trigger pam_sf_pilgrimage_sponsor_valid_trigger = {
	is_available_ai_adult = yes
	this != root
	faith = root.faith
	treasury_or_gold >= root.medium_gold_value
	OR = {
		opinion = { target = root value >= 50 }
		has_relation_friend = root
		has_relation_lover = root
		has_trait = loyal
		has_trait = trusting
		has_trait = generous
		ai_greed <= -50
	}
	NOR = {
		has_relation_rival = root
		has_trait = disloyal
		has_trait = paranoid
		has_trait = greedy
		has_trait = arrogant
	}
}

pam_secular_faith_events.0042 = {
	type = character_event
	title = pam_secular_faith_events.0042.t
	desc = pam_secular_faith_events.0042.desc
	theme = christian
	override_background = garden

	left_portrait = {
		character = root
		animation = priest_good
		camera = camera_event_very_left
	}
	right_portrait = {
		character = scope:sponsor_character
		animation = divine_gesture_4
		camera = camera_event_right_to_the_right
	}

	cooldown = { years = 10 }

	trigger = {
		pam_secular_faith_christian_actor_trigger = yes
		NOR = {
			has_character_modifier = pam_sf_pilgrimage_funded_modifier
			rite = { rite_has_doctrine = doctrine_pilgrimage_forbidden }
		}
		OR = {
			cp:councillor_court_chaplain ?= { pam_sf_pilgrimage_sponsor_valid_trigger = yes }
			any_vassal = {
				government_has_flag = government_is_theocracy
				pam_sf_pilgrimage_sponsor_valid_trigger = yes
			}
			liege ?= {
				any_vassal = {
					government_has_flag = government_is_theocracy
					pam_sf_pilgrimage_sponsor_valid_trigger = yes
				}
			}
			capital_county.clerical_region_title.holder ?= { pam_sf_pilgrimage_sponsor_valid_trigger = yes }
		}
	}

	immediate = {
		if = {
			limit = { cp:councillor_court_chaplain ?= { pam_sf_pilgrimage_sponsor_valid_trigger = yes } }
			cp:councillor_court_chaplain = { add_to_list = sponsor_list }
		}
		if = {
			limit = {
				capital_county.clerical_region_title.holder ?= { pam_sf_pilgrimage_sponsor_valid_trigger = yes }
			}
			capital_county.clerical_region_title.holder = { add_to_list = sponsor_list }
		}
		every_vassal = {
			limit = {
				government_has_flag = government_is_theocracy
				pam_sf_pilgrimage_sponsor_valid_trigger = yes
			}
			add_to_list = sponsor_list
		}
		liege ?= {
			every_vassal = {
				limit = {
					government_has_flag = government_is_theocracy
					pam_sf_pilgrimage_sponsor_valid_trigger = yes
				}
				add_to_list = sponsor_list
			}
		}
		random_in_list = {
			list = sponsor_list
			weight = {
				base = 1
				modifier = {
					add = 10
					is_ruler = yes
				}
			}
			save_scope_as = sponsor_character
		}
	}

	option = { # Accept the gift and walk the road
		name = pam_secular_faith_events.0042.a
		custom_tooltip = pam_sf_pilgrimage_sponsor_tt
		add_character_modifier = {
			modifier = pam_sf_pilgrimage_funded_modifier
			years = 5
		}
		set_variable = {
			name = pam_sf_pilgrimage_sponsor
			value = scope:sponsor_character
			years = 7
		}
		ai_chance = {
			base = 100
		}
	}

	option = { # Pocket the gold instead
		name = pam_secular_faith_events.0042.b
		add_internal_flag = dangerous
		scope:sponsor_character = {
			pay_treasury_or_gold = {
				target = root
				value = root.medium_gold_value
			}
			add_opinion = {
				modifier = theft_opinion
				target = root
			}
		}
		stress_and_fulfillment_impact = {
			just = medium_stress_impact_gain
			honest = medium_stress_impact_gain
			generous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 0
			modifier = {
				add = 100
				OR = {
					has_trait = greedy
					treasury_or_gold <= 0
				}
			}
			modifier = {
				factor = 0
				OR = {
					has_trait = just
					has_trait = honest
					has_trait = generous
				}
			}
		}
	}

	option = { # Decline gracefully
		name = pam_secular_faith_events.0042.c
		add_piety = miniscule_piety_gain
		reverse_add_opinion = {
			target = scope:sponsor_character
			modifier = respect_opinion
			opinion = 10
		}
		ai_chance = {
			base = 100
		}
	}
}

##########################################################################################
# 0043 - A Pilgrim's Welcome (realm priest proclaims your completed pilgrimage: capital opinion + development)
##########################################################################################
pam_secular_faith_events.0043 = {
	type = character_event
	title = pam_secular_faith_events.0043.t
	desc = pam_secular_faith_events.0043.desc
	theme = christian
	override_background = temple
	widgets = {
		widget = {
			gui = event_window_widget_vfx_godray
			container = background_shader_vfx_container
		}
	}

	left_portrait = {
		character = scope:holy_man
		animation = preaching
		camera = camera_event_left_to_the_left
	}
	right_portrait = {
		character = root
		animation = prayer_standing
	}

	cooldown = { years = 10 }

	trigger = {
		pam_secular_faith_christian_actor_trigger = yes
		exists = capital_county
		is_landed = yes
		cp:councillor_court_chaplain ?= {
			is_available_ai_adult = yes
			ai_zeal >= 0
			NOT = {
				has_relation_rival = root
			}
		}
		NOR = {
			has_character_modifier = pam_sf_promised_acclaim_modifier
			rite = { rite_has_doctrine = doctrine_pilgrimage_forbidden }
		}
	}

	immediate = {
		cp:councillor_court_chaplain = { save_scope_as = holy_man }
		capital_county = { save_scope_as = capital_county }
	}

	option = { # Resolve to make the journey
		name = pam_secular_faith_events.0043.a
		add_character_modifier = {
			modifier = pam_sf_promised_acclaim_modifier
			years = 10
		}
		ai_chance = {
			base = 100
		}
	}

	option = { # Let it pass
		name = pam_secular_faith_events.0043.b
		add_prestige = miniscule_prestige_gain
		stress_and_fulfillment_impact = {
			humble = minor_stress_impact_gain
			zealous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = humble
					has_trait = zealous
				}
			}
		}
	}
}

##########################################################################################
# 0044 - The Ear of the Clergy (clerical-interaction acceptance boost)
##########################################################################################
pam_secular_faith_events.0044 = {
	type = character_event
	title = pam_secular_faith_events.0044.t
	desc = pam_secular_faith_events.0044.desc
	theme = christian
	override_background = temple_church

	left_portrait = {
		character = scope:friendly_bishop
		animation = divine_gesture_1
	}
	right_portrait = {
		character = root
		animation = prayer_standing_eyes
	}

	cooldown = { years = 10 }

	trigger = {
		pam_secular_faith_christian_actor_trigger = yes
		pam_clergy_interactions_faith_trigger = yes
		NOT = { has_character_modifier = pam_sf_ear_of_clergy_modifier }
		cp:councillor_court_chaplain ?= {
			is_available_ai_adult = yes
			OR = {
				opinion = { target = root value >= 50 }
				has_relation_friend = root
				has_relation_lover = root
				has_trait = loyal
				has_trait = trusting
				has_trait = content
			}
			NOR = {
				has_relation_rival = root
				has_trait = arrogant
				has_trait = paranoid
			}
		}
	}

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

	option = { # Press the Church's favor
		name = pam_secular_faith_events.0044.a
		add_character_modifier = {
			modifier = pam_sf_ear_of_clergy_modifier
			years = 5
		}
		ai_chance = {
			base = 100
		}
	}

	option = { # Take it as a simple blessing
		name = pam_secular_faith_events.0044.b
		add_piety = minor_piety_gain
		reverse_add_opinion = {
			target = scope:friendly_bishop
			modifier = happy_opinion
			opinion = 20
		}
		ai_chance = {
			base = 100
		}
	}
}

##########################################################################################
# 0045 - Epiphany (temporary faith/rite creation cost discount)
##########################################################################################
pam_secular_faith_events.0045 = {
	type = character_event
	title = pam_secular_faith_events.0045.t
	desc = pam_secular_faith_events.0045.desc
	theme = christian
	override_background = garden

	left_portrait = {
		character = root
		animation = divine_ecstasy
		camera = camera_event_table_left_forward
	}

	cooldown = { years = 100 }

	widget = { gui = event_window_widget_vfx_godray container = foreground_shader_vfx_container }

	trigger = {
		pam_secular_faith_landed_actor_trigger = yes
		piety >= 500
		OR = {
			learning >= 16
			has_trait = lifestyle_scholar
			has_trait = lifestyle_mystic
			government_has_flag = government_is_theocracy
		}
	}

	immediate = {
	}

	option = { # Press the advantage
		name = pam_secular_faith_events.0045.a
		add_character_modifier = {
			modifier = pam_sf_doctrine_clarity_modifier
			years = 3
		}
		if = {
			limit = {
				cp:councillor_court_chaplain ?= { is_theocratic_lessee = yes }
				can_add_hook = { target = cp:councillor_court_chaplain type = favor_hook }
			}
			add_hook = {
				type = favor_hook
				target = cp:councillor_court_chaplain
			}
		}
		add_scholar_trait_or_xp_effect = { VALUE = 30 }
		ai_chance = {
			base = 100
		}
	}

	option = { # Simply enjoy the clarity
		name = pam_secular_faith_events.0045.b
		change_spiritual_fulfillment = major_spiritual_fulfillment_value
		ai_chance = {
			base = 100
		}
	}
}

##########################################################################################
# 0046 - Shared Conviction
##########################################################################################
scripted_trigger valid_share_target_trigger = {
	is_available_ai_adult = yes
	ai_zeal >= 0
	any_personal_tenet = {
		save_temporary_scope_as = tenet
		NOT = {
			root = {
				any_personal_tenet = {
					this = scope:tenet
				}
			}
		}
	}
}

pam_secular_faith_events.0046 = {
	type = character_event
	title = pam_secular_faith_events.0046.t
	desc = pam_secular_faith_events.0046.desc
	theme = christian
	override_background = sitting_room

	left_portrait = {
		character = root
		animation = admiration
	}
	right_portrait = {
		character = scope:intimate
		animation = divine_ecstasy
		camera = camera_event_right_wedding
	}
	widgets = {
		widget = { gui = event_window_widget_vfx_background_flickering_candlelight container = foreground_shader_vfx_container }
		widget = { gui = event_window_widget_vfx_left_character_flickering_candlelight container = foreground_shader_vfx_container }
		widget = { gui = event_window_widget_vfx_right_character_flickering_candlelight container = foreground_shader_vfx_container }
	}

	cooldown = { years = 10 }

	trigger = {
		pam_secular_faith_christian_actor_trigger = yes
		OR = {
			any_spouse = {
				valid_share_target_trigger = yes
			}
			any_relation = {
				type = friend
				valid_share_target_trigger = yes
			}
			any_relation = {
				type = lover
				valid_share_target_trigger = yes
			}
			any_close_family_member = {
				valid_share_target_trigger = yes
			}
		}
	}

	immediate = {
		save_scope_as = root_scope
		every_spouse = {
			limit = {
				valid_share_target_trigger = yes
			}
			add_to_list = intimate_list
		}
		every_relation = {
			type = friend
			limit = {
				valid_share_target_trigger = yes
			}
			add_to_list = intimate_list
		}
		every_relation = {
			type = lover
			limit = {
				valid_share_target_trigger = yes
			}
			add_to_list = intimate_list
		}
		every_close_family_member = {
			limit = {
				valid_share_target_trigger = yes
			}
			add_to_list = intimate_list
		}

		random_in_list = {
			list = intimate_list
			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 = intimate
		}

		scope:intimate = {
			random_personal_tenet = {
				limit = {
					save_temporary_scope_as = tenet_check
					NOT = {
						root = {
							any_personal_tenet = {
								this = scope:tenet_check
							}
						}
					}
				}
				save_scope_as = shared_tenet
			}
		}
	}

	option = { # Take up their conviction
		name = pam_secular_faith_events.0046.a
		trigger = {
			OR = {
				can_set_relation_friend_trigger = { CHARACTER = scope:intimate }
				AND = {
					has_relation_friend = scope:intimate
					can_set_relation_best_friend_trigger = { CHARACTER = scope:intimate }
				}
			}
		}
		if = {
			limit = {
				NOT = {
					knows_tenet = scope:shared_tenet
				}
			}
			add_known_tenet = scope:shared_tenet
			pam_secular_faith_seed_tenet_message_effect = { TENET = scope:shared_tenet }
		}
		force_set_personal_tenet = scope:shared_tenet
		if = {
			limit = {
				has_relation_friend = scope:intimate
				can_set_relation_best_friend_trigger = { CHARACTER = scope:intimate }
			}
			set_relation_best_friend = {
				target = scope:intimate
				reason = pam_sf_best_friend_shared_conviction
			}
		}
		else = {
			set_relation_friend = {
				target = scope:intimate
				reason = pam_sf_friend_shared_conviction
			}
		}
		reverse_add_opinion = {
			modifier = pam_sf_shared_conviction_opinion
			target = scope:intimate
		}
		ai_chance = {
			base = 100
		}
	}

	option = { # Take it, and deepen the bond
		name = pam_secular_faith_events.0046.b
		trigger = {
			are_characters_sensible_lovers_trigger = { INSTIGATING_LOVER = scope:root_scope TARGET_OF_LOVE = scope:intimate }
			OR = {
				can_set_relation_lover_trigger = { CHARACTER = scope:intimate }
				AND = {
					has_relation_lover = scope:intimate
					can_set_relation_soulmate_trigger = { CHARACTER = scope:intimate }
				}
			}
		}
		if = {
			limit = {
				NOT = {
					knows_tenet = scope:shared_tenet
				}
			}
			add_known_tenet = scope:shared_tenet
			pam_secular_faith_seed_tenet_message_effect = { TENET = scope:shared_tenet }
		}
		force_set_personal_tenet = scope:shared_tenet
		if = {
			limit = {
				has_relation_lover = scope:intimate
				can_set_relation_soulmate_trigger = { CHARACTER = scope:intimate }
			}
			set_relation_soulmate = {
				target = scope:intimate
				reason = pam_sf_soulmate_shared_conviction
			}
		}
		else = {
			set_relation_lover = {
				target = scope:intimate
				reason = pam_sf_lover_shared_conviction
			}
		}
		reverse_add_opinion = {
			modifier = pam_sf_shared_conviction_opinion
			target = scope:intimate
		}
		ai_chance = {
			base = 100
		}
	}

	option = { # Admire it, but keep your own
		name = pam_secular_faith_events.0046.c
		if = {
			limit = {
				NOT = {
					knows_tenet = scope:shared_tenet
				}
			}
			add_known_tenet = scope:shared_tenet
			pam_secular_faith_seed_tenet_message_effect = { TENET = scope:shared_tenet }
		}
		reverse_add_opinion = {
			target = scope:intimate
			modifier = friendliness_opinion
			opinion = 10
		}
		ai_chance = {
			base = 100
		}
	}
}

##########################################################################################
# 0047 - Priestly Devotion (puppet your realm priest for free)
##########################################################################################
pam_secular_faith_events.0047 = {
	type = character_event
	title = pam_secular_faith_events.0047.t
	desc = pam_secular_faith_events.0047.desc
	theme = christian
	override_background = temple

	left_portrait = {
		character = root
		animation = interested
	}
	right_portrait = {
		character = scope:chaplain
		animation = prayer_crossing
	}

	cooldown = { years = 10 }

	trigger = {
		pam_secular_faith_christian_actor_trigger = yes
		has_theological_agent_puppet_trigger = no
		cp:councillor_court_chaplain ?= {
			save_temporary_scope_as = puppet
			is_available_ai_adult = yes
			OR = {
				opinion = { target = root value >= 50 }
				has_relation_friend = root
				has_relation_lover = root
				has_trait = trusting
				has_trait = content
				has_trait = compassionate
				has_trait = forgiving
				has_trait = craven
				has_trait = humble
				has_trait = fickle
				has_trait = loyal
			}
			NOR = {
				has_relation_rival = root
				has_trait = arrogant
				has_trait = paranoid
			}
		}
	}

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

	option = { # Accept his devotion
		name = pam_secular_faith_events.0047.a
		if = {
			limit = {
				can_add_hook = {
					type = loyalty_hook
					target = scope:chaplain
				}
			}
			add_hook = {
				type = loyalty_hook
				target = scope:chaplain
			}
		}
		reverse_add_opinion = {
			target = scope:chaplain
			modifier = pious_opinion
			opinion = 20
		}
		ai_chance = {
			base = 100
		}
	}

	option = { # Keep it informal
		name = pam_secular_faith_events.0047.b
		add_piety = medium_piety_gain
		reverse_add_opinion = {
			target = scope:chaplain
			modifier = pious_opinion
			opinion = 20
		}
		ai_chance = {
			base = 10
		}
	}
}

##########################################################################################
# 0048 - Demonic Dreams (a tormenting dream)
##########################################################################################
pam_secular_faith_events.0048 = {
	type = character_event
	title = pam_secular_faith_events.0048.t
	desc = pam_secular_faith_events.0048.desc
	theme = christian
	override_background = bedchamber
	widgets = {
		widget = { gui = event_window_widget_vfx_background_night_scene container = foreground_shader_vfx_container }
		widget = { gui = event_window_widget_vfx_left_character_double_vision_severe container = foreground_shader_vfx_container }
		widget = { gui = event_window_widget_vfx_right_character_double_vision_severe 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 }
		widget = { gui = event_window_widget_vfx_fog container = foreground_shader_vfx_container }
	}

	left_portrait = {
		character = root
		animation = paranoia
		camera = camera_event_very_left_lean_down
		outfit_tags = { nightgown }
	}

	right_portrait = {
		character = scope:demon
		animation = dancing
		camera = camera_event_very_right_far
		hide_info = yes
	}

	cooldown = { years = 30 }

	trigger = {
		pam_secular_faith_christian_actor_trigger = yes
		NOR = {
			has_character_modifier = pam_sf_demon_torment_modifier
			rite = { rite_has_doctrine = doctrine_pilgrimage_forbidden }
		}
	}

	immediate = {
		hidden_effect_new_object = {
			create_character = {
				location = root.capital_province
				template = generic_peasant_character
				faith = root.faith
				rite = root.rite
				culture = root.culture
				gender_female_chance = 0
				trait = smallpox
				trait = bubonic_plague
				trait = scaly
				trait = measles
				trait = scarred
				trait = beauty_bad_3
				trait = physique_bad_3
				trait = clouded_eyes
				trait = giant
				trait = leper
				save_scope_as = demon
				after_creation = {
					add_character_flag = created
					change_current_weight = -500
					add_character_flag = bald_head
					add_character_flag = is_naked
					add_character_flag = random_beard
				}
			}
		}
	}

	option = { # Study the dream
		name = pam_secular_faith_events.0048.a
		trigger = {
			has_trait = lifestyle_scholar
		}
		show_as_unavailable = { always = yes }
		add_character_modifier = pam_sf_demon_torment_modifier
		custom_tooltip = pam_sf_demon_torment_modifier_tt
		add_scholar_trait_or_xp_effect = { VALUE = 30 }
		ai_chance = {
			base = 100
		}
	}

	option = { # Ignore it
		name = pam_secular_faith_events.0048.b
		trigger = {
			has_trait = cynical
		}
		show_as_unavailable = { always = yes }
		add_stress = minor_stress_loss
		ai_chance = {
			base = 100
		}
	}

	option = { # Resolve to make amends
		name = pam_secular_faith_events.0048.c
		change_spiritual_fulfillment = major_spiritual_fulfillment_loss
		add_character_modifier = pam_sf_demon_torment_modifier
		custom_tooltip = pam_sf_demon_torment_modifier_tt
		ai_chance = {
			base = 1
		}
	}

	after = {
		scope:demon ?= { silent_disappearance_effect = yes }
	}
}

##########################################################################################
# 0049 - Celestial Hierarchy
##########################################################################################
scripted_trigger appropriate_lustful_priest_trigger = {
	faith = root.faith
	is_available_ai_adult = yes
	might_cheat_on_every_partner_trigger = yes
	OR = {
		any_secret = {
			type = secret_deviant
			NOT = { is_known_by = root }
		}
		NOT = {
			any_secret = {
				type = secret_deviant
			}
		}
	}
	OR = {
		has_trait = lustful
		has_trait = rakish
		has_trait = seducer
	}
	NOR = {
		has_trait = deviant # otherwise nothing to give
		has_trait = chaste
		has_trait = celibate
		has_sexuality = asexual
	}
}

pam_secular_faith_events.0049 = {
	type = character_event
	title = pam_secular_faith_events.0049.t
	desc = pam_secular_faith_events.0049.desc
	theme = christian
	override_background = temple

	left_portrait = {
		character = scope:lustful_priest
		animation = divine_ecstasy
		camera = camera_event_center_pointing_left
	}

	right_portrait = {
		character = scope:prostitute
		animation = whipping
		camera = camera_event_very_right_fov35
	}

	cooldown = { years = 20 }

	trigger = {
		pam_secular_faith_christian_actor_trigger = yes
		rite = {
			has_at_least_tenet_status = {
				tenet = tenet_celestial_hierarchy
				status = known
			}
		}
		NOR = {
			rite = { rite_has_parameter = deviancy_accepted }
			knows_tenet = tenet_carnal_exaltation
			rite = {
				has_at_least_tenet_status = {
					tenet = tenet_carnal_exaltation
					status = permitted
				}
			}
		}
		OR = {
			any_vassal = {
				government_has_flag = government_is_theocracy
				appropriate_lustful_priest_trigger = yes
			}
			cp:councillor_court_chaplain ?= {
				appropriate_lustful_priest_trigger = yes
			}
		}
	}

	immediate = {
		random_vassal = {
			limit = {
				government_has_flag = government_is_theocracy
				appropriate_lustful_priest_trigger = yes
			}
			save_scope_as = lustful_priest
			save_scope_as = attraction_check
			add_character_flag = is_naked
		}
		if = {
			limit = {
				NOT = {
					exists = scope:lustful_priest
				}
			}
			cp:councillor_court_chaplain = {
				save_scope_as = lustful_priest
				save_scope_as = attraction_check
				add_character_flag = is_naked
			}
		}
		scope:lustful_priest = {
			if = {
				limit = {
					NOT = {
						any_secret = {
							type = secret_deviant
						}
					}
				}
				hidden_effect = {
					give_deviant_secret_or_trait_effect = yes
				}
			}
			random_secret = {
				type = secret_deviant
				limit = {
					NOT = { is_known_by = root }
				}
				save_scope_as = lustful_priest_secret
			}
		}
		hidden_effect_new_object = {
			create_character = {
				location = root.capital_province
				template = ep3_prostitute_character
				gender_female_chance = scope_attraction_based_female_chance
				faith = root.capital_county.faith
				rite = root.capital_county.rite
				culture = root.capital_county.culture
				save_scope_as = prostitute
				after_creation = {
					add_character_flag = created
					add_character_flag = pope_hat
					add_character_flag = is_naked
				}
			}
			scope:prostitute = {
				random_list = {
					10 = {
						set_sexuality = bisexual
					}
					5 = {
						trigger = {
							OR = {
								AND = {
									is_female = yes
									scope:lustful_priest = { is_female = yes }
								}
								AND = {
									is_male = yes
									scope:lustful_priest = { is_male = yes }
								}
							}
						}
						set_sexuality = homosexual
					}
					10 = {
						trigger = {
							OR = {
								AND = {
									is_female = no
									scope:lustful_priest = { is_female = yes }
								}
								AND = {
									is_male = no
									scope:lustful_priest = { is_male = yes }
								}
							}
						}
						set_sexuality = heterosexual
					}
				}
			}
		}
	}

	option = { # Study them, you little freak
		name = pam_secular_faith_events.0049.a
		add_scholar_trait_or_xp_effect = { VALUE = 10 }
		scope:lustful_priest_secret ?= {
			reveal_to = root
		}
		add_known_tenet = tenet_carnal_exaltation
		pam_secular_faith_seed_tenet_message_effect = { TENET = tenet:tenet_carnal_exaltation }
		ai_chance = {
			base = 100
		}
	}

	option = { # Join them
		name = pam_secular_faith_events.0049.b
		scope:lustful_priest_secret ?= {
			reveal_to = root
		}
		had_sex_with_effect = {
			CHARACTER = scope:lustful_priest
			PREGNANCY_CHANCE = pregnancy_chance
		}
		had_sex_with_effect = {
			CHARACTER = scope:prostitute
			PREGNANCY_CHANCE = pregnancy_chance
		}
		if = {
			limit = {
				can_set_relation_potential_lover_trigger = { CHARACTER = scope:lustful_priest }
			}
			set_relation_potential_lover = scope:lustful_priest
		}
		if = {
			limit = {
				can_set_relation_potential_lover_trigger = { CHARACTER = scope:prostitute }
			}
			set_relation_potential_lover = scope:prostitute
		}
		add_courtier = scope:prostitute
		hidden_effect = {
			scope:prostitute = { remove_character_flag = created }
		}
		create_character_memory = {
			type = had_a_threesome_memory
			participants = {
				partner_1 = scope:lustful_priest
				partner_2 = scope:prostitute
			}
		}
		stress_and_fulfillment_impact = {
			lustful = massive_stress_impact_loss
			chaste = massive_stress_impact_gain
			celibate = massive_stress_impact_gain
		}
		ai_chance = {
			base = 5
			modifier = {
				might_cheat_on_every_partner_trigger = no
				factor = 0
			}
			modifier = {
				OR = {
					has_trait = chaste
					has_trait = celibate
				}
				factor = 0
			}
		}
	}

	option = { # Learn the secret
		name = pam_secular_faith_events.0049.c
		trigger = {
			exists = scope:lustful_priest_secret
		}
		scope:lustful_priest_secret = {
			reveal_to = root
		}
		add_piety = minor_piety_gain
		ai_chance = {
			base = 100
		}
	}

	after = {
		scope:lustful_priest = {
			remove_character_flag = is_naked
		}
		scope:prostitute = {
			remove_character_flag = is_naked
			remove_character_flag = pope_hat
			silent_disappearance_ai_if_created_effect = yes
		}
	}
}

##########################################################################################
# 0050 - Confession (the ruler lusts after their own court chaplain)
##########################################################################################
pam_secular_faith_events.0050 = {
	type = character_event
	title = pam_secular_faith_events.0050.t
	desc = pam_secular_faith_events.0050.desc
	theme = christian
	override_background = temple

	left_portrait = {
		character = root
		animation = prayer
		camera = camera_event_kneeling
	}
	right_portrait = {
		character = scope:chaplain
		animation = divine_gesture_3
		camera = camera_event_right_away_3_4_more_right
	}
	widgets = {
		widget = { gui = event_window_widget_vfx_background_flickering_candlelight_dark container = foreground_shader_vfx_container }
		widget = { gui = event_window_widget_vfx_left_character_flickering_candlelight_dark container = foreground_shader_vfx_container }
		widget = { gui = event_window_widget_vfx_right_character_flickering_candlelight_dark container = foreground_shader_vfx_container }
	}

	cooldown = { years = 10 }

	trigger = {
		pam_secular_faith_christian_actor_trigger = yes
		rite = {
			has_at_least_tenet_status = {
				tenet = tenet_confession
				status = permitted
			}
		}
		cp:councillor_court_chaplain ?= {
			pam_sf_carnal_partner_valid_trigger = yes
		}
		OR = {
			has_trait = lustful
			has_trait = rakish
			has_trait = seducer
			cp:councillor_court_chaplain ?= {
				OR = {
					has_trait = lustful
					has_trait = rakish
					has_trait = seducer
				}
			}
		}
	}

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

	option = { # ...is there space for two in your booth?
		name = pam_secular_faith_events.0050.a
		set_relation_lover = {
			target = scope:chaplain
			reason = pam_sf_lover_confessional
		}
		had_sex_with_effect = {
			CHARACTER = scope:chaplain
			PREGNANCY_CHANCE = pregnancy_chance
		}
		stress_and_fulfillment_impact = {
			base = minor_stress_impact_loss
			lustful = minor_stress_impact_loss
		}
		ai_chance = {
			base = 100
		}
	}

	option = { # Forgive me, for I have impure thoughts.
		name = pam_secular_faith_events.0050.b
		change_spiritual_fulfillment = minor_spiritual_fulfillment_value
		stress_and_fulfillment_impact = {
			base = minor_stress_impact_gain
			lustful = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = { has_trait = lustful factor = 0 }
		}
	}
}

##########################################################################################
# 0051 - The Lord your God
##########################################################################################
pam_secular_faith_events.0051 = {
	type = character_event
	title = pam_secular_faith_events.0051.t
	desc = pam_secular_faith_events.0051.desc
	theme = christian
	override_background = temple
	widgets = {
		widget = { gui = event_window_widget_vfx_background_double_vision_severe container = foreground_shader_vfx_container }
		widget = { gui = event_window_widget_vfx_left_character_double_vision_severe container = foreground_shader_vfx_container }
	}

	left_portrait = {
		character = root
		animation = mental_anguish
		camera = camera_head_designer_up
	}

	cooldown = { years = 50 }

	trigger = {
		pam_secular_faith_christian_actor_trigger = yes
		OR = {
			has_trait = lunatic
			has_trait = possessed
			has_trait = eccentric
			has_trait = withering_mind
		}
		NOR = {
			has_character_modifier = pam_sf_voice_of_jesus_modifier
			has_character_modifier = pam_sf_stroke_of_god_modifier
		}
	}

	option = { # I will... obey...
		name = pam_secular_faith_events.0051.a
		add_internal_flag = dangerous
		flavor = pam_sf_lord_your_god_tt
		custom_tooltip = pam_sf_lord_your_god_effect_tt
		change_spiritual_fulfillment = 100
		hidden_effect = {
			random_list = {
				10 = {
					send_interface_toast = {
						type = event_toast_effect_good
						title = pam_sf_voice_of_jesus_toast
						left_icon = root
						add_character_modifier = {
							modifier = pam_sf_voice_of_jesus_modifier
							years = 15
						}
					}
				}
				80 = {
					send_interface_toast = {
						type = event_toast_effect_bad
						title = pam_sf_stroke_of_god_toast
						left_icon = root
						add_character_modifier = {
							modifier = pam_sf_stroke_of_god_modifier
							years = 5
						}
					}
				}
				9 = {
					if = {
						limit = {
							NOT = {
								has_trait = withering_mind
							}
						}
						add_trait = withering_mind
					}
					else = {
						add_trait_xp = { trait = withering_mind track = withering_mind value = 10 }
					}
				}
				1 = {
					death = { death_reason = death_apoplexy }
				}
			}
		}
	}
}

##########################################################################################
# 0052 - After You're Gone (an old ruler settles where they will lie; pays off at their funeral)
##########################################################################################
pam_secular_faith_events.0052 = {
	type = character_event
	title = pam_secular_faith_events.0052.t
	desc = pam_secular_faith_events.0052.desc
	theme = christian
	override_background = temple_church

	left_portrait = {
		character = root
		animation = contemplating
	}
	right_portrait = {
		character = scope:chaplain
		animation = divine_gesture_3
	}

	trigger = {
		pam_secular_faith_christian_actor_trigger = yes
		has_dlc_feature = legends_of_the_dead
		is_old_character = yes
		NOT = { has_character_flag = pam_sf_tomb_planned }
		exists = dynasty
		exists = primary_heir
		rite = {
			NOR = {
				rite_has_parameter = cremation_funeral
				rite_has_parameter = sky_burials_active
			}
		}
		cp:councillor_court_chaplain ?= {
			is_available_ai_adult = yes
		}
		capital_county ?= {
			any_county_province = { has_holding_type = church_holding }
		}
	}

	immediate = {
		add_character_flag = pam_sf_tomb_planned
		cp:councillor_court_chaplain = { save_scope_as = chaplain }
		capital_county = {
			random_county_province = {
				limit = { has_holding_type = church_holding }
				barony = { save_scope_as = resting_church }
			}
		}
	}

	option = { # Commission a proud effigy in stone - unveiled at your funeral
		name = pam_secular_faith_events.0052.a
		remove_short_term_gold = minor_gold_value
		change_spiritual_fulfillment = minor_spiritual_fulfillment_value
		custom_tooltip = pam_sf_effigy_planned_tt
		hidden_effect = {
			dynasty = {
				add_to_variable_list = {
					name = pam_sf_planned_effigies
					target = root
				}
			}
		}
		stress_and_fulfillment_impact = {
			humble = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = { has_trait = humble factor = 0 }
		}
	}

	option = { # Ask to be buried in the plain cowl - hallows your funeral
		name = pam_secular_faith_events.0052.b
		add_prestige = minor_prestige_loss
		change_spiritual_fulfillment = minor_spiritual_fulfillment_value
		custom_tooltip = pam_sf_cowl_burial_planned_tt
		hidden_effect = {
			dynasty = {
				add_to_variable_list = {
					name = pam_sf_planned_cowl_burials
					target = root
				}
			}
		}
		stress_and_fulfillment_impact = {
			arrogant = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = { has_trait = arrogant factor = 0 }
		}
	}

	option = { # Wave the question away
		name = pam_secular_faith_events.0052.c
		stress_and_fulfillment_impact = {
			humble = minor_stress_impact_gain
			zealous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = humble
					has_trait = zealous
				}
			}
		}
	}
}

##########################################################################################
# 0053 - The Saint Goes Forth (a held relic is borne in procession)
##########################################################################################
pam_secular_faith_events.0053 = {
	type = character_event
	title = pam_secular_faith_events.0053.t
	desc = pam_secular_faith_events.0053.desc
	theme = christian
	override_background = temple
	override_effect_2d = { reference = smoke }
	widgets = {
		widget = {
			gui = event_window_widget_vfx_godray
			container = background_shader_vfx_container
		}
	}

	left_portrait = {
		character = root
		animation = prayer_standing
		camera = camera_event_crowd
	}
	right_portrait = {
		character = scope:chaplain
		animation = thurible
		camera = camera_event_right_forward
	}
	artifact = {
        target = scope:procession_relic
        position = lower_center_portrait
    }

	cooldown = { years = 15 }

	trigger = {
		pam_secular_faith_christian_actor_trigger = yes
		exists = capital_county
		cp:councillor_court_chaplain ?= {
			is_available_ai_adult = yes
		}
		any_character_artifact = {
			is_holy_relic_for = root.faith
		}
	}

	immediate = {
		cp:councillor_court_chaplain = { save_scope_as = chaplain }
		random_character_artifact = {
			limit = {
			is_holy_relic_for = root.faith
			}
			save_scope_as = procession_relic
		}
		capital_province = { barony = { save_scope_as = loc_province } }
	}

	option = { # Carry the reliquary through the town yourself - the crowd may harm the relic
		name = pam_secular_faith_events.0053.a
		custom_tooltip = pam_sf_procession_gamble_tt
		add_piety = major_piety_gain
		capital_county = {
			add_county_modifier = {
				modifier = pam_sf_relic_procession_county_modifier
				years = 10
			}
		}
		hidden_effect = {
			random = {
				chance = 25
				send_interface_toast = {
					type = event_toast_effect_bad
					title = pam_sf_relic_jostled_toast
					left_icon = root
					right_icon = scope:procession_relic
					scope:procession_relic = {
						add_durability = {
							value = artifact_durability
							multiply = -0.25
						}
					}
				}
			}
		}
		stress_and_fulfillment_impact = {
			shy = minor_stress_impact_gain
			paranoid = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = shy
					has_trait = paranoid
				}
			}
		}
	}

	option = { # Keep vigil before the relic alone
		name = pam_secular_faith_events.0053.b
		change_spiritual_fulfillment = minor_spiritual_fulfillment_value
		stress_and_fulfillment_impact = {
			gregarious = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = { has_trait = gregarious factor = 0 }
		}
	}

	option = { # The bones stay in their vault, tended and safe
		name = pam_secular_faith_events.0053.c
		scope:procession_relic = {
			add_durability = 10
		}
		scope:chaplain = {
			add_opinion = {
				target = root
				modifier = upset_opinion
				opinion = -10
			}
		}
		stress_and_fulfillment_impact = {
			zealous = minor_stress_impact_gain
			paranoid = minor_stress_impact_loss
		}
		ai_chance = {
			base = 100
			modifier = { has_trait = zealous factor = 0 }
		}
	}
}

##########################################################################################
# 0054 - The Basin and the Towel (the ruler washes the feet of the poor)
##########################################################################################
scripted_trigger pam_sf_maundy_pauper_valid_trigger = {
	is_available_healthy_ai_adult = yes
	has_no_particular_noble_roots_trigger = yes
	faith = root.faith
}

pam_secular_faith_events.0054 = {
	type = character_event
	title = pam_secular_faith_events.0054.t
	desc = pam_secular_faith_events.0054.desc
	theme = christian
	override_background = temple

	left_portrait = {
		character = root
		animation = situla
		camera = camera_event_left_pointing_right
	}
	right_portrait = {
		character = scope:pauper
		animation = worry
		camera = camera_event_very_right_far
	}

	cooldown = { years = 10 }

	trigger = {
		pam_secular_faith_christian_actor_trigger = yes
		any_pool_character = {
			province = root.location
			pam_sf_maundy_pauper_valid_trigger = yes
		}
	}

	immediate = {
		random_pool_character = {
			province = root.location
			limit = { pam_sf_maundy_pauper_valid_trigger = yes }
			save_scope_as = pauper
			hidden_effect = {
				add_character_flag = peasant_outfit
				add_character_flag = no_hat
			}
		}
	}

	option = { # Clean the feet with your tongue
		name = pam_secular_faith_events.0054.deviant
		trigger = {
			has_trait = deviant
		}
		add_prestige = massive_prestige_loss
		change_spiritual_fulfillment = major_spiritual_fulfillment_value
		add_stress = -300
		add_character_modifier = {
			modifier = best_meal_of_my_life_modifier
			years = 15
		}
		reverse_add_opinion = {
			target = scope:pauper
			modifier = absolutely_horrified_opinion
		}
		every_courtier = {
			add_opinion = {
				target = root
				modifier = absolutely_horrified_opinion
			}
		}
		ai_chance = {
			base = 100
			modifier = { has_trait = arrogant factor = 0 }
		}
	}

	option = { # Kneel and wash their feet before the court
		name = pam_secular_faith_events.0054.a
		custom_tooltip = pam_sf_odorous_feet_tt
		add_prestige = minor_prestige_loss
		add_piety = medium_piety_gain
		add_legitimacy_effect = { LEGITIMACY = minor_legitimacy_gain }
		hidden_effect = {
			random = {
				chance = 25
				send_interface_toast = {
					type = event_toast_effect_bad
					title = pam_sf_odorous_feet_toast
					left_icon = root
					right_icon = scope:pauper
					add_character_modifier = {
						modifier = pam_sf_lingering_stench_modifier
						years = 2
					}
				}
			}
		}
		stress_and_fulfillment_impact = {
			humble = minor_stress_impact_loss
			arrogant = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = { has_trait = arrogant factor = 0 }
		}
	}

	option = { # Kiss the feet as well, as the saints did - the deeper the bow, the sharper the smell
		name = pam_secular_faith_events.0054.b
		custom_tooltip = pam_sf_odorous_feet_tt
		add_prestige = minor_prestige_loss
		add_piety = medium_piety_gain
		change_spiritual_fulfillment = medium_spiritual_fulfillment_value
		hidden_effect = {
			random = {
				chance = 50
				send_interface_toast = {
					type = event_toast_effect_bad
					title = pam_sf_odorous_feet_toast
					left_icon = root
					right_icon = scope:pauper
					add_character_modifier = {
						modifier = pam_sf_lingering_stench_modifier
						years = 2
					}
				}
			}
		}
		stress_and_fulfillment_impact = {
			humble = minor_stress_impact_loss
			zealous = minor_stress_impact_loss
		}
		ai_chance = {
			base = 0
			modifier = {
				add = 100
				OR = {
					has_trait = humble
					has_trait = zealous
				}
			}
		}
	}

	option = { # Think better of it and call the ritual off
		name = pam_secular_faith_events.0054.c
		stress_and_fulfillment_impact = {
			humble = minor_stress_impact_gain
			zealous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 25
			modifier = {
				factor = 0
				OR = {
					has_trait = humble
					has_trait = zealous
				}
			}
		}
	}
}

##########################################################################################
# 0055 - A Voice of Bronze (a newly recast church bell is baptized)
##########################################################################################
pam_secular_faith_events.0055 = {
	type = character_event
	title = pam_secular_faith_events.0055.t
	desc = pam_secular_faith_events.0055.desc
	theme = christian
	override_background = courtyard

	left_portrait = {
		character = root
		animation = interested
		camera = camera_event_left_away_3_4
	}
	right_portrait = {
		character = scope:chaplain
		animation = situla
		camera = camera_event_right_away
	}

	cooldown = { years = 50 }

	trigger = {
		pam_secular_faith_christian_actor_trigger = yes
		cp:councillor_court_chaplain ?= {
			is_available_ai_adult = yes
		}
		capital_county ?= {
			any_county_province = { has_holding_type = church_holding }
		}
	}

	immediate = {
		cp:councillor_court_chaplain = { save_scope_as = chaplain }
		capital_county = {
			random_county_province = {
				limit = { has_holding_type = church_holding }
				barony = { save_scope_as = bell_church }
			}
		}
	}

	option = { # Scholar: bronze is bronze, and the capitularies agree
		name = pam_secular_faith_events.0055.b
		trigger = {
			has_trait = lifestyle_scholar
		}
		show_as_unavailable = { always = yes }
		add_scholar_trait_or_xp_effect = { VALUE = 30 }
		scope:chaplain = {
			add_opinion = {
				target = root
				modifier = upset_opinion
				opinion = -25
			}
		}
		ai_chance = {
			base = 100
		}
	}

	option = { # Baptize the bell and name it
		name = pam_secular_faith_events.0055.a
		add_piety = minor_piety_gain
		capital_county = {
			add_county_modifier = {
				modifier = pam_sf_blessed_bell_county_modifier
				years = 25
			}
		}
		stress_and_fulfillment_impact = {
			cynical = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = { has_trait = cynical factor = 0 }
		}
	}

	option = { # A plain blessing, then let it ring
		name = pam_secular_faith_events.0055.c
		change_spiritual_fulfillment = minor_spiritual_fulfillment_value
		stress_and_fulfillment_impact = {
			zealous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = { has_trait = zealous factor = 0 }
		}
	}
}

##########################################################################################
# 0056 - A Sparrow in the Hall (Bede's sparrow flies through the evening meal)
##########################################################################################
pam_secular_faith_events.0056 = {
	type = character_event
	title = pam_secular_faith_events.0056.t
	desc = pam_secular_faith_events.0056.desc
	theme = christian
	override_background = feast
	widgets = {
		widget = { gui = event_window_widget_vfx_background_flickering_candlelight_dark container = foreground_shader_vfx_container }
		widget = { gui = event_window_widget_vfx_left_character_flickering_candlelight_dark container = foreground_shader_vfx_container }
		widget = { gui = event_window_widget_vfx_right_character_flickering_candlelight_dark container = foreground_shader_vfx_container }
	}

	left_portrait = {
		character = root
		animation = drink_goblet
		camera = camera_event_very_left
	}
	right_portrait = {
		character = scope:chaplain
		animation = divine_gesture_4
		camera = camera_event_very_right_far
	}

	cooldown = { years = 30 }

	trigger = {
		pam_secular_faith_christian_actor_trigger = yes
		drinks_alcohol_trigger = yes
		character_capital_has_winter_trigger = yes
		capital_province = { geographical_region = world_europe }
		cp:councillor_court_chaplain ?= {
			is_available_ai_adult = yes
		}
	}

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

	option = { # Scholar: Bede wrote the same, almost to the word
		name = pam_secular_faith_events.0056.scholar
		trigger = {
			has_trait = lifestyle_scholar
		}
		show_as_unavailable = { always = yes }
		reverse_add_opinion = {
			target = scope:chaplain
			modifier = impressed_opinion
			opinion = 30
		}
		add_scholar_trait_or_xp_effect = { VALUE = 20 }
		ai_chance = {
			base = 100
		}
	}

	option = { # Take the sparrow's flight to heart
		name = pam_secular_faith_events.0056.a
		change_spiritual_fulfillment = minor_spiritual_fulfillment_value
		stress_and_fulfillment_impact = {
			base = minor_stress_loss
			cynical = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = { has_trait = cynical factor = 0 }
		}
	}

	option = { # It was a bird
		name = pam_secular_faith_events.0056.b
		if = {
			limit = {
				has_royal_court = yes
			}
			change_current_court_grandeur = minor_court_grandeur_gain
		}
		add_prestige = miniscule_prestige_gain
		stress_and_fulfillment_impact = {
			zealous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = { has_trait = zealous factor = 0 }
		}
	}
}

##########################################################################################
# 0057 - The Church Ale (the parish brews to pay for the church roof)
##########################################################################################
pam_secular_faith_events.0057 = {
	type = character_event
	title = pam_secular_faith_events.0057.t
	desc = pam_secular_faith_events.0057.desc
	theme = christian
	override_background = holy_site_generic_scope

	left_portrait = {
		character = root
		animation = interested
		camera = camera_event_very_left
	}
	right_portrait = {
		character = scope:chaplain
		animation = drink
		camera = camera_event_right_forward
	}

	cooldown = { years = 15 }

	trigger = {
		pam_secular_faith_christian_actor_trigger = yes
		cp:councillor_court_chaplain ?= {
			is_available_ai_adult = yes
		}
		# A monks' brewery somewhere in the domain does the brewing.
		any_held_title = {
			tier = tier_county
			any_county_province = {
				has_holding_type = church_holding
				has_building_or_higher = breweries_01
			}
		}
	}

	immediate = {
		cp:councillor_court_chaplain = { save_scope_as = chaplain }
		random_held_title = {
			limit = {
				tier = tier_county
				any_county_province = {
					has_holding_type = church_holding
					has_building_or_higher = breweries_01
				}
			}
			save_scope_as = ale_county
			save_scope_as = holy_site_scope
			random_county_province = {
				limit = {
					has_holding_type = church_holding
					has_building_or_higher = breweries_01
				}
				barony = { save_scope_as = ale_church }
			}
		}
	}

	option = { # Drink with the parish - the brew is strong
		name = pam_secular_faith_events.0057.a
		flavor = pam_sf_church_ale_gamble_tt
		scope:ale_county = {
			add_county_modifier = {
				modifier = pam_sf_church_ale_county_modifier
				years = 10
			}
		}
		hidden_effect = {
			random = {
				chance = 35
				send_interface_toast = {
					type = event_toast_effect_bad
					title = pam_sf_church_ale_toast
					left_icon = root
					add_character_modifier = {
						modifier = legend_hangover_modifier
						months = 6
					}
				}
			}
		}
		stress_and_fulfillment_impact = {
			gregarious = minor_stress_impact_loss
			temperate = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = { has_trait = temperate factor = 0 }
		}
	}

	option = { # Pay for the roof yourself, no revel needed
		name = pam_secular_faith_events.0057.b
		remove_short_term_gold = minor_gold_value
		add_piety = medium_piety_gain
		stress_and_fulfillment_impact = {
			greedy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = { has_trait = greedy factor = 0 }
		}
	}

	option = { # Forbid drink on holy ground
		name = pam_secular_faith_events.0057.c
		add_piety = minor_piety_gain
		reverse_add_opinion = {
			modifier = annoyed_opinion
			target = scope:chaplain
			opinion = -10
		}
		stress_and_fulfillment_impact = {
			gregarious = minor_stress_impact_gain
			drunkard = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = gregarious
					has_trait = drunkard
				}
			}
		}
	}
}

##########################################################################################
# 0058 - Quid Mus Sumit? (a mouse has eaten of the reserved Host)
##########################################################################################
pam_secular_faith_events.0058 = {
	type = character_event
	title = pam_secular_faith_events.0058.t
	desc = pam_secular_faith_events.0058.desc
	theme = christian
	override_background = temple
	widgets = {
		widget = { gui = event_window_widget_vfx_background_flickering_candlelight container = foreground_shader_vfx_container }
		widget = { gui = event_window_widget_vfx_left_character_flickering_candlelight container = foreground_shader_vfx_container }
		widget = { gui = event_window_widget_vfx_right_character_flickering_candlelight container = foreground_shader_vfx_container }
	}

	left_portrait = {
		character = root
		animation = contemplating
		camera = camera_event_left_to_the_left
	}
	right_portrait = {
		character = scope:chaplain
		animation = worry
	}

	cooldown = { years = 30 }

	trigger = {
		pam_secular_faith_christian_actor_trigger = yes
		rite = {
			has_at_least_tenet_status = {
				tenet = tenet_communion
				status = permitted
			}
		}
		cp:councillor_court_chaplain ?= {
			is_available_ai_adult = yes
		}
	}

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

	option = { # Scholar: the mouse ate bread, and nothing more
		name = pam_secular_faith_events.0058.scholar
		trigger = {
			has_trait = lifestyle_scholar
		}
		show_as_unavailable = { always = yes }
		add_piety = medium_piety_gain
		add_scholar_trait_or_xp_effect = { VALUE = 20 }
		scope:chaplain = {
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = 15
			}
		}
		ai_chance = {
			base = 100
		}
	}

	option = { # Blow the negligence out of proportion and drive the chaplain from office
		name = pam_secular_faith_events.0058.mean
		trigger = {
			learning >= 12
		}
		show_as_unavailable = { always = yes }
		add_piety = minor_piety_loss
		fire_councillor = scope:chaplain
		scope:chaplain = {
			select_and_move_to_pool_effect = yes
			add_opinion = {
				target = root
				modifier = hate_opinion
				opinion = -30
			}
		}
		stress_and_fulfillment_impact = {
			compassionate = medium_stress_impact_gain
			humble = medium_stress_impact_gain
		}
		ai_chance = {
			base = 25
			modifier = {
				factor = 0
				OR = {
					has_trait = compassionate
					has_trait = humble
					has_trait = just
				}
			}
		}
	}

	option = { # Buy a pyx with a better lock
		name = pam_secular_faith_events.0058.a
		remove_short_term_gold = miniscule_gold_value
		add_piety = minor_piety_gain
		stress_and_fulfillment_impact = {
			greedy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = { has_trait = greedy factor = 0 }
		}
	}

	option = { # Laugh in the poor man's face
		name = pam_secular_faith_events.0058.b
		add_stress = minor_stress_loss
		scope:chaplain = {
			add_opinion = {
				target = root
				modifier = upset_opinion
				opinion = -10
			}
		}
		stress_and_fulfillment_impact = {
			zealous = minor_stress_impact_gain
			compassionate = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = zealous
					has_trait = compassionate
				}
			}
		}
	}
}

##########################################################################################
# 0059 - The Lord's Day (the chaplain bars the hunt on the day of rest)
##########################################################################################
pam_secular_faith_events.0059 = {
	type = character_event
	title = pam_secular_faith_events.0059.t
	desc = pam_secular_faith_events.0059.desc
	theme = christian
	override_background = courtyard

	left_portrait = {
		character = root
		animation = horse_archer_idle
		camera = camera_event_horse_left
	}
	right_portrait = {
		character = scope:chaplain
		animation = condemnation
		camera = camera_event_very_right_fov35
	}

	cooldown = { years = 10 }

	trigger = {
		pam_secular_faith_christian_actor_trigger = yes
		is_at_war = no
		OR = {
			is_clergy = no
			has_trait = lifestyle_hunter
		}
		cp:councillor_court_chaplain ?= {
			is_available_ai_adult = yes
		}
		# The sighted game must have somewhere in the domain to be.
		any_held_title = {
			tier = tier_county
			hunt_activity_recent_hunt_sighting_trigger = no
		}
	}

	immediate = {
		cp:councillor_court_chaplain = { save_scope_as = chaplain }
		hidden_effect = {
			every_held_title = {
				limit = {
					tier = tier_county
					hunt_activity_recent_hunt_sighting_trigger = no
				}
				add_to_list = sighting_counties
			}
			random_in_list = {
				list = sighting_counties
				weight = {
					base = 1
					hunt_activity_sighting_county_modifier = yes
				}
				save_scope_as = sighting_county
				random_county_province = {
					weight = {
						base = 1
						hunt_activity_sighting_terrain_modifier = yes
						hunt_activity_sighting_building_modifier = { PROVINCE = this }
						hunt_activity_game_building_modifier = { PROVINCE = this }
					}
					save_scope_as = sighting_province
				}
			}
			scope:sighting_county = {
				hunt_activity_standard_game_effect = { PROVINCE = scope:sighting_province HUNTER = root }
				hunt_create_sighting_effect = {
					TYPE = standard
					ANIMAL = var:animal_type
					OWNER = root
				}
			}
		}
	}

	option = { # Ride on regardless
		name = pam_secular_faith_events.0059.b
		add_prestige = minor_prestige_gain
		scope:chaplain = {
			add_opinion = {
				target = root
				modifier = impious_opinion
				opinion = -20
			}
		}
		scope:sighting_county = {
			show_as_tooltip = {
				add_county_modifier = hunt_sighting_standard_modifier
			}
		}
		stress_and_fulfillment_impact = {
			zealous = minor_stress_impact_gain
			humble = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = zealous
					has_trait = humble
				}
			}
		}
	}

	option = { # Unsaddle and hear mass
		name = pam_secular_faith_events.0059.a
		add_piety = minor_piety_gain
		scope:chaplain = {
			add_opinion = {
				target = root
				modifier = pious_opinion
				opinion = 20
			}
		}
		hidden_effect = {
			scope:sighting_county = {
				hunt_remove_sighting_effect = yes
				remove_variable = recent_sighting
			}
		}
		stress_and_fulfillment_impact = {
			humble = minor_stress_impact_loss
			impatient = minor_stress_impact_gain
			arrogant = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = impatient
					has_trait = arrogant
				}
			}
		}
	}
}

##########################################################################################
# 0060 - A Life Unburdened (A beggar is happier than you)
##########################################################################################
pam_secular_faith_events.0060 = {
	type = character_event
	title = pam_secular_faith_events.0060.t
	desc = pam_secular_faith_events.0060.desc
	theme = faith
	override_background = { reference = market }
	override_effect_2d = { reference = rain }

	left_portrait = {
		character = root
		animation = jockey_idle
		camera = camera_event_horse_left
	}
	right_portrait = {
		character = scope:hermit
		animation = dancing
		camera = camera_event_center_close_to_right
		hide_info = yes
	}

	cooldown = { years = 10 }

	trigger = {
		pam_secular_faith_clergy_ok_actor_trigger = yes
		spiritual_fulfillment < 0
		is_in_debt = yes
		NOT = {
			any_personal_tenet = {
				pam_poverty_tenets_trigger = yes
			}
		}
		exists = location.county.faith
		location = {
			NOR = {
				terrain = desert
				terrain = desert_mountains
				terrain = drylands
				terrain = oasis
			}
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = -0.5
			OR = { 
				has_trait = greedy
				has_trait = cynical
				has_trait = arrogant
				has_trait = gluttonous
			}
		}
		modifier = {
			add = 1
			OR = { 
				has_trait = generous
				has_trait = zealous
				has_trait = improvident
				has_trait = content
				has_trait = humble
				has_trait = temperate
			}
		}
	}

	immediate = {
		create_character = {
			location = root.location
			template = generic_peasant_character
			faith = root.location.county.faith
			rite = root.location.county.rite
			culture = root.location.county.culture
			save_scope_as = hermit			
		}
		random_tenet = {
			limit = {
				pam_poverty_tenets_trigger = yes
			}
			save_scope_as = tenet_pick
		}
	}

	option = { # Add a personal tenet of poverty to your faith, or replace an existing one
		name = pam_secular_faith_events.0060.a
		change_spiritual_fulfillment = major_spiritual_fulfillment_value
		force_set_personal_tenet = scope:tenet_pick
		stress_and_fulfillment_impact = {
			greedy = major_stress_impact_gain
			cynical = major_stress_impact_gain
			generous = medium_stress_impact_loss
			zealous = medium_stress_impact_loss
			improvident = medium_stress_impact_loss
			content = medium_stress_impact_loss
			humble = medium_stress_impact_loss
			temperate = medium_stress_impact_loss
		}
		ai_chance = {
			base = 20
			ai_value_modifier = {
				ai_greed = -1
				ai_zeal = 1
			}
			modifier = { 
				factor = 0
				OR = {
					has_trait = greedy
					has_trait = cynical
				}
			}
		}
	}

	option = { # Get back to work
		name = pam_secular_faith_events.0060.b
		change_spiritual_fulfillment = medium_spiritual_fulfillment_loss
		add_character_modifier = {
			modifier = pam_sf_grinding_modifier
			years = 5
		}
		stress_and_fulfillment_impact = {
			generous = minor_stress_impact_gain
			zealous = minor_stress_impact_gain
			content = medium_stress_impact_gain
			humble = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 1
				ai_zeal = -1
			}
			modifier = { 
				factor = 0
				OR = {
					has_trait = zealous
					has_trait = content
					has_trait = humble
					has_trait = generous
				}
			}
		}
	}

	option = { # Opt out
		name = pam_secular_faith_events.0060.c
		add_prestige = miniscule_prestige_gain
		ai_chance = {
			base = 100
		}
	}

	after = {
		scope:hermit = {
			silent_disappearance_ai_if_created_effect = yes
		}
	}
}
