namespace = learning_theology

namespace = learning_theology_special

##################################################

# Learning Theology Lifestyle events

	# 1301			- Realm Priest Needs Books, by Linnéa Thimrén
	# 2020			- Flatter Bishop, by Mathilda Bjarnehed
	# 3002			- Age of the World
	# 3003			- The Number of Spheres
	# 3011			- Worship in the same church (theology friend), by Linnéa Thimrén
	# 3021			- Send fan mail to religious head, by Linnéa Thimrén
	# 3031			- Deal with province of different faith, by Linnéa Thimrén
	# 3051			- Passion Play drama, by James Beaumont

#Special Learning Theology Lifestyle events

	# 1001			- Finding old text
	# 1101 			- Traveling Rabbi

##################################################

##################################################
# Your realm priest asks for books
# by Linnéa Thimrén
##################################################
learning_theology.1301 = {
	type = character_event
	title = learning_theology.1301.t
	desc = {
		desc = learning_theology.1301.desc_opening
		first_valid = {
			triggered_desc = {
				trigger = {
					faith = { OR = { religion_tag = eastern_orthodox_religion religion_tag = catholic_religion religion_tag = protestant_religion } }
				}
				desc = learning_theology.1301.desc_regula_pastoralis
			}
			desc = learning_theology.1301.desc
		}
		desc = learning_theology.1301.desc_ending
	}
	theme = learning_theology_focus
	left_portrait = {
		character = root
		animation = interested
	}
	right_portrait = {
		character = scope:bishop
		animation = beg
	}

	trigger = {
		NOT = {
			has_character_flag = had_event_learning_theology_1301
		}
		exists = cp:councillor_court_chaplain
		can_add_hook = {
		  	type = favor_hook
		 	target = cp:councillor_court_chaplain
		}
	}

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

	immediate = {
		add_character_flag = {
			flag = had_event_learning_theology_1301
			years = 5
		}
		cp:councillor_court_chaplain = {
			save_scope_as = bishop
		}
	}

	option = { #Give the book to the scholar
		name = learning_theology.1301.a
		remove_short_term_gold = medium_gold_value
		add_learning_lifestyle_xp = miniscule_lifestyle_xp
		add_hook = {
  			target = scope:bishop
  			type = favor_hook
 		}
 		ai_chance = {
 			base = 50
 		}
	}

	option = { #Take the book for yourself
		name = learning_theology.1301.b
		remove_short_term_gold = medium_gold_value
		add_learning_lifestyle_xp = minor_lifestyle_xp
		add_learning_skill = 1
		scope:bishop = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -15
			}
		}
		ai_chance = {
			base = 50
		}
	}

	option = { #nah
		name = learning_theology.1301.c
		scope:bishop = {
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = -10
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_greed = 0.5
			}
		}
	}
}


##################################################
# Flatter your court chaplain with some bible verses
# by Mathilda Bjarnehed
##################################################

learning_theology.2020 = { #by Mathilda Bjarnehed
	type = character_event
	title = learning_theology.2020.t
	desc = learning_theology.2020.desc

	theme = learning_theology_focus
	left_portrait = {
		character = root
		animation = page_flipping
	}
	right_portrait = {
		character = scope:court_chaplain
		animation = personality_callous
	}

	trigger = {
		root.religion = { is_in_family = rf_abrahamic }
		any_learning_councillor = {
			is_available_ai = yes
		}
		faith = { #Matches learning_theology_2020_randomize_virtue_options_effect, to make sure you can get at least 1 option
			calc_true_if = {
				amount >= 2
				trait_is_virtue = brave
				trait_is_virtue = just
				trait_is_virtue = temperate
				trait_is_virtue = chaste
				trait_is_virtue = compassionate
				trait_is_virtue = honest
				trait_is_virtue = forgiving
				trait_is_virtue = wrathful
				trait_is_virtue = vengeful
				trait_is_virtue = content
				trait_is_virtue = patient
				trait_is_virtue = calm
				trait_is_virtue = humble
				trait_is_virtue = diligent
				trait_is_virtue = generous
			}
		}
	}

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

	immediate = {
		random_learning_councillor = {
			save_scope_as = court_chaplain
		}

		#Randomize virtue texts (try to get 3)
		learning_theology_2020_randomize_virtue_options_effect = yes
		learning_theology_2020_randomize_virtue_options_effect = yes
		if = {
			limit = { learning >= high_skill_rating }
			learning_theology_2020_randomize_virtue_options_effect = yes
		}
		else = {
			learning_theology_2020_randomize_bad_virtue_options_effect = yes
		}
	}

	# brave
	option = {
		trigger = { has_character_flag = virtue_brave }
		name = learning_theology.2020.brave
		save_scope_value_as = { name = virtue_choice value = flag:brave }
	}

	# just
	option = {
		trigger = { has_character_flag = virtue_just }
		name = learning_theology.2020.just
		save_scope_value_as = { name = virtue_choice value = flag:just }
	}

	# temperate
	option = {
		trigger = { has_character_flag = virtue_temperate }
		name = learning_theology.2020.temperate
		save_scope_value_as = { name = virtue_choice value = flag:temperate }
	}

	# chaste
	option = {
		trigger = { has_character_flag = virtue_chaste }
		name = learning_theology.2020.chaste
		save_scope_value_as = { name = virtue_choice value = flag:chaste }
	}

	# compassionate
	option = {
		trigger = { has_character_flag = virtue_compassionate }
		name = learning_theology.2020.compassionate
		save_scope_value_as = { name = virtue_choice value = flag:compassionate }
	}

	# honest
	option = {
		trigger = { has_character_flag = virtue_honest }
		name = learning_theology.2020.honest
		save_scope_value_as = { name = virtue_choice value = flag:honest }
	}


	# forgiving
	option = {
		trigger = { has_character_flag = virtue_forgiving }
		name = learning_theology.2020.forgiving
		save_scope_value_as = { name = virtue_choice value = flag:forgiving }
	}


	# wrathful
	option = {
		trigger = { has_character_flag = virtue_wrathful }
		name = learning_theology.2020.wrathful
		save_scope_value_as = { name = virtue_choice value = flag:wrathful }
	}


	# vengeful
	option = {
		trigger = { has_character_flag = virtue_vengeful }
		name = learning_theology.2020.vengeful
		save_scope_value_as = { name = virtue_choice value = flag:vengeful }
	}

	# content
	option = {
		trigger = { has_character_flag = virtue_content }
		name = learning_theology.2020.content
		save_scope_value_as = { name = virtue_choice value = flag:content }
	}

	# patient
	option = {
		trigger = { has_character_flag = virtue_patient }
		name = learning_theology.2020.patient
		save_scope_value_as = { name = virtue_choice value = flag:patient }
	}

	# calm
	option = {
		trigger = { has_character_flag = virtue_calm }
		name = learning_theology.2020.calm
		save_scope_value_as = { name = virtue_choice value = flag:calm }
	}

	# humble
	option = {
		trigger = { has_character_flag = virtue_humble }
		name = learning_theology.2020.humble
		save_scope_value_as = { name = virtue_choice value = flag:humble }
	}

	# diligent
	option = {
		trigger = { has_character_flag = virtue_diligent }
		name = learning_theology.2020.diligent
		save_scope_value_as = { name = virtue_choice value = flag:diligent }
	}

	# generous
	option = {
		trigger = { has_character_flag = virtue_generous }
		name = learning_theology.2020.generous
		save_scope_value_as = { name = virtue_choice value = flag:generous }
	}

	# greedy
	option = {
		trigger = { has_character_flag = virtue_greedy }
		name = learning_theology.2020.greedy
		save_scope_value_as = { name = virtue_choice value = flag:greedy }
	}

	# lustful
	option = {
		trigger = { has_character_flag = virtue_lustful }
		name = learning_theology.2020.lustful
		save_scope_value_as = { name = virtue_choice value = flag:lustful }
	}

	# ambitious
	option = {
		trigger = { has_character_flag = virtue_ambitious }
		name = learning_theology.2020.ambitious
		save_scope_value_as = { name = virtue_choice value = flag:ambitious }
	}

	# gluttonous
	option = {
		trigger = { has_character_flag = virtue_gluttonous }
		name = learning_theology.2020.gluttonous
		save_scope_value_as = { name = virtue_choice value = flag:gluttonous }
	}


	after = {
		learning_theology_2020_tooltip_effect = yes
		hidden_effect = {
			#(These effects must match learning_theology_2020_tooltip_effect)
			if = {
				limit = { exists = scope:virtue_choice }

				#HIDDEN SUPERBAD OUTCOME
				if = {
					limit = {
						#That's not a virtue!
						OR = {
							AND = {
								faith = { NOT = { trait_is_virtue = brave } }
								scope:virtue_choice = flag:brave
							}
							AND = {
								faith = { NOT = { trait_is_virtue = just } }
								scope:virtue_choice = flag:just
							}
							AND = {
								faith = { NOT = { trait_is_virtue = temperate } }
								scope:virtue_choice = flag:temperate
							}
							AND = {
								faith = { NOT = { trait_is_virtue = chaste } }
								scope:virtue_choice = flag:chaste
							}
							AND = {
								faith = { NOT = { trait_is_virtue = compassionate } }
								scope:virtue_choice = flag:compassionate
							}
							AND = {
								faith = { NOT = { trait_is_virtue = honest } }
								scope:virtue_choice = flag:honest
							}
							AND = {
								faith = { NOT = { trait_is_virtue = forgiving } }
								scope:virtue_choice = flag:forgiving
							}
							AND = {
								faith = { NOT = { trait_is_virtue = wrathful } }
								scope:virtue_choice = flag:wrathful
							}
							AND = {
								faith = { NOT = { trait_is_virtue = vengeful } }
								scope:virtue_choice = flag:vengeful
							}
							AND = {
								faith = { NOT = { trait_is_virtue = content } }
								scope:virtue_choice = flag:content
							}
							AND = {
								faith = { NOT = { trait_is_virtue = patient } }
								scope:virtue_choice = flag:patient
							}
							AND = {
								faith = { NOT = { trait_is_virtue = calm } }
								scope:virtue_choice = flag:calm
							}
							AND = {
								faith = { NOT = { trait_is_virtue = humble } }
								scope:virtue_choice = flag:humble
							}
							AND = {
								faith = { NOT = { trait_is_virtue = diligent } }
								scope:virtue_choice = flag:diligent
							}
							AND = {
								faith = { NOT = { trait_is_virtue = generous } }
								scope:virtue_choice = flag:generous
							}
							AND = {
								faith = { NOT = { trait_is_virtue = greedy } }
								scope:virtue_choice = flag:greedy
							}
							AND = {
								faith = { NOT = { trait_is_virtue = lustful } }
								scope:virtue_choice = flag:lustful
							}
							AND = {
								faith = { NOT = { trait_is_virtue = ambitious } }
								scope:virtue_choice = flag:ambitious
							}
							AND = {
								faith = { NOT = { trait_is_virtue = gluttonous } }
								scope:virtue_choice = flag:gluttonous
							}
						}
					}
					trigger_event = {
						id = learning_theology.2021
						days = 2
					}
				}
				else_if = {
					limit = {
						OR = {
							#They have the trait
							AND = {
								scope:court_chaplain = { has_trait = brave }
								scope:virtue_choice = flag:brave
							}
							AND = {
								scope:court_chaplain = { has_trait = just }
								scope:virtue_choice = flag:just
							}
							AND = {
								scope:court_chaplain = { has_trait = temperate }
								scope:virtue_choice = flag:temperate
							}
							AND = {
								scope:court_chaplain = { has_trait = chaste }
								scope:virtue_choice = flag:chaste
							}
							AND = {
								scope:court_chaplain = { has_trait = compassionate }
								scope:virtue_choice = flag:compassionate
							}
							AND = {
								scope:court_chaplain = { has_trait = honest }
								scope:virtue_choice = flag:honest
							}
							AND = {
								scope:court_chaplain = { has_trait = forgiving }
								scope:virtue_choice = flag:forgiving
							}
							AND = {
								scope:court_chaplain = { has_trait = wrathful }
								scope:virtue_choice = flag:wrathful
							}
							AND = {
								scope:court_chaplain = { has_trait = vengeful }
								scope:virtue_choice = flag:vengeful
							}
							AND = {
								scope:court_chaplain = { has_trait = content }
								scope:virtue_choice = flag:content
							}
							AND = {
								scope:court_chaplain = { has_trait = patient }
								scope:virtue_choice = flag:patient
							}
							AND = {
								scope:court_chaplain = { has_trait = calm }
								scope:virtue_choice = flag:calm
							}
							AND = {
								scope:court_chaplain = { has_trait = humble }
								scope:virtue_choice = flag:humble
							}
							AND = {
								scope:court_chaplain = { has_trait = diligent }
								scope:virtue_choice = flag:diligent
							}
							AND = {
								scope:court_chaplain = { has_trait = generous }
								scope:virtue_choice = flag:generous
							}
							#Matching ai value
							AND = {
								scope:court_chaplain = { ai_boldness >= medium_positive_ai_value }
								OR = {
									scope:virtue_choice = flag:brave
									scope:virtue_choice = flag:wrathful
								}
							}
							AND = {
								scope:court_chaplain = { ai_honor >= medium_positive_ai_value }
								OR = {
									scope:virtue_choice = flag:just
									scope:virtue_choice = flag:honest
								}
							}
							AND = {
								scope:court_chaplain = { ai_greed <= medium_negative_ai_value }
								OR = {
									scope:virtue_choice = flag:temperate
									scope:virtue_choice = flag:chaste
									scope:virtue_choice = flag:content
									scope:virtue_choice = flag:humble
									scope:virtue_choice = flag:generous
								}
							}
							AND = {
								scope:court_chaplain = { ai_compassion >= medium_positive_ai_value }
								OR = {
									scope:virtue_choice = flag:compassionate
									scope:virtue_choice = flag:generous
								}
							}
							AND = {
								scope:court_chaplain = { ai_vengefulness <= medium_negative_ai_value }
								scope:virtue_choice = flag:forgiving
							}
							AND = {
								scope:court_chaplain = { ai_vengefulness >= medium_positive_ai_value }
								scope:virtue_choice = flag:vengeful
							}
							AND = {
								scope:court_chaplain = { ai_energy <= medium_negative_ai_value }
								OR = {
									scope:virtue_choice = flag:content
									scope:virtue_choice = flag:patient
									scope:virtue_choice = flag:humble
								}
							}
							AND = {
								scope:court_chaplain = { ai_rationality <= medium_negative_ai_value }
								OR = {
									scope:virtue_choice = flag:patient
									scope:virtue_choice = flag:calm
								}
							}
							AND = {
								scope:court_chaplain = { ai_boldness <= medium_negative_ai_value }
								scope:virtue_choice = flag:calm
							}
							AND = {
								scope:court_chaplain = { ai_energy >= medium_positive_ai_value }
								OR = {
									scope:virtue_choice = flag:brave
									scope:virtue_choice = flag:diligent
								}
							}
						}
					}
					send_interface_toast = {
						title = learning_theology.2020.success.desc
						left_icon = scope:court_chaplain
						add_piety = medium_piety_gain
						add_learning_lifestyle_xp = minor_lifestyle_xp
						reverse_add_opinion = {
							target = scope:court_chaplain
							modifier = kindness_opinion
							opinion = 30
						}
					}
				}
				#BAD OUTCOME
				else_if = {
					limit = {
						#They have the opposite trait
						OR = {
							AND = {
								scope:court_chaplain = { has_trait = craven }
								scope:virtue_choice = flag:brave
							}
							AND = {
								scope:court_chaplain = { has_trait = arbitrary }
								scope:virtue_choice = flag:just
							}
							AND = {
								scope:court_chaplain = { has_trait = gluttonous }
								scope:virtue_choice = flag:temperate
							}
							AND = {
								scope:court_chaplain = { has_trait = lustful }
								scope:virtue_choice = flag:chaste
							}
							AND = {
								scope:court_chaplain = {
									OR = {
										has_trait = callous
										has_trait = sadistic
									}
								}
								scope:virtue_choice = flag:compassionate
							}
							AND = {
								scope:court_chaplain = { has_trait = deceitful }
								scope:virtue_choice = flag:honest
							}
							AND = {
								scope:court_chaplain = { has_trait = vengeful }
								scope:virtue_choice = flag:forgiving
							}
							AND = {
								scope:court_chaplain = { has_trait = calm }
								scope:virtue_choice = flag:wrathful
							}
							AND = {
								scope:court_chaplain = { has_trait = forgiving }
								scope:virtue_choice = flag:vengeful
							}
							AND = {
								scope:court_chaplain = { has_trait = ambitious }
								scope:virtue_choice = flag:content
							}
							AND = {
								scope:court_chaplain = { has_trait = impatient }
								scope:virtue_choice = flag:patient
							}
							AND = {
								scope:court_chaplain = { has_trait = wrathful }
								scope:virtue_choice = flag:calm
							}
							AND = {
								scope:court_chaplain = { has_trait = arrogant }
								scope:virtue_choice = flag:humble
							}
							AND = {
								scope:court_chaplain = { has_trait = lazy }
								scope:virtue_choice = flag:diligent
							}
							AND = {
								scope:court_chaplain = { has_trait = greedy }
								scope:virtue_choice = flag:generous
							}
						}
					}
					send_interface_toast = {
						title = learning_theology.2020.failure.desc
						left_icon = scope:court_chaplain
						reverse_add_opinion = {
							target = scope:court_chaplain
							modifier = insulted_opinion
							opinion = -15
						}
					}
				}
				#NEUTRAL OUTCOME
				else = {
					send_interface_toast = {
						title = learning_theology.2020.neutral.desc
						left_icon = scope:court_chaplain
						add_piety = medium_piety_gain
					}
				}
			}
		}
		remove_character_flag = virtue_brave
		remove_character_flag = virtue_just
		remove_character_flag = virtue_temperate
		remove_character_flag = virtue_chaste
		remove_character_flag = virtue_compassionate
		remove_character_flag = virtue_honest
		remove_character_flag = virtue_forgiving
		remove_character_flag = virtue_wrathful
		remove_character_flag = virtue_vengeful
		remove_character_flag = virtue_content
		remove_character_flag = virtue_patient
		remove_character_flag = virtue_calm
		remove_character_flag = virtue_humble
		remove_character_flag = virtue_diligent
		remove_character_flag = virtue_generous
		remove_character_flag = virtue_greedy
		remove_character_flag = virtue_lustful
		remove_character_flag = virtue_ambitious
		remove_character_flag = virtue_gluttonous
	}
}

#What, that's not even a virtue!
learning_theology.2021 = { #by Mathilda Bjarnehed
	type = character_event
	title = learning_theology.2020.t
	desc = learning_theology.2021.desc

	theme = learning_theology_focus
	left_portrait = {
		character = root
		animation = shame
	}
	right_portrait = {
		character = scope:court_chaplain
		animation = personality_vengeful
	}


	option = {
		name = learning_theology.2021.a

		reverse_add_opinion = {
			target = scope:court_chaplain
			modifier = impious_opinion
			opinion = -15
		}
		add_piety = minor_piety_loss
	}
}

#Determine the age of the world
# by Petter Vilberg
learning_theology.3002 = {
	type = character_event
	title = learning_theology.3002.t
	desc = learning_theology.3002.desc

	theme = learning_theology_focus
	left_portrait = {
		character = root
		animation = page_flipping
	}
	right_portrait = {
		character = scope:chaplain
		animation = disapproval
	}

	trigger = {
		NOT = { has_character_flag = had_event_learning_theology_3002 }
		faith = {
			OR = {
				religion = religion:hinduism_religion
				religion = religion:buddhism_religion
				religion = religion:jainism_religion
				religion = religion:zoroastrianism_religion
				OR = { religion = religion:eastern_orthodox_religion religion = religion:catholic_religion religion = religion:protestant_religion }
				religion = religion:islam_religion
			}
		}
		OR = {
			exists = cp:councillor_court_chaplain
			employs_court_position = camp_priest_camp_officer
		}
	}

	weight_multiplier = {
		base = 1
		downweight_for_focus_modifier = { FOCUS = learning_medicine_focus }
	}

	immediate = {
		add_character_flag = {
			flag = had_event_learning_theology_3002
			years = 20
		}
		cp:councillor_court_chaplain ?= {
			save_scope_as = chaplain
		}
		if = {
			limit = {
				NOT = { exists = scope:chaplain }
			}
			random_court_position_holder = {
				type = camp_priest_camp_officer
				save_scope_as = chaplain
			}
		}
	}

	option = { #People deserve to know the truth!
		name = learning_theology.3002.a
		add_learning_lifestyle_xp = minor_lifestyle_xp
		add_prestige = medium_prestige_gain
		add_piety = minor_piety_loss
		scope:chaplain = {
			add_opinion = {
				target = root
				modifier = refusal_opinion
				opinion = -15
			}
		}
		cynical_progression_effect = yes
	}

	option = { #The church knows best
		name = learning_theology.3002.b
		add_learning_lifestyle_xp = miniscule_lifestyle_xp
		add_piety = major_piety_gain
		add_prestige = minor_prestige_loss
		zealous_progression_effect = yes
		scope:chaplain = {
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = 10
			}
		}
	}

	option = {
		name = learning_theology.3002.c
		add_learning_lifestyle_xp = medium_lifestyle_xp
	}
}

#Determine the number of spheres in the heavens
# by Petter Vilberg
learning_theology.3003 = {
	type = character_event
	title = learning_theology.3003.t
	desc = learning_theology.3003.desc

	theme = learning_theology_focus
	left_portrait = {
		character = root
		animation = survey
	}
	right_portrait = {
		character = scope:chaplain
		animation = disapproval
	}

	trigger = {
		root.religion = { is_in_family = rf_abrahamic }
		NOT = { has_character_flag = had_event_learning_theology_3003 }
		NOR = {
			has_character_modifier = scholarship_astrological_insights_modifier
			has_character_modifier = scholarship_down_to_earth_modifier
		}
		OR = {
			exists = cp:councillor_court_chaplain
			employs_court_position = camp_priest_camp_officer
		}
	}

	weight_multiplier = {
		base = 1
		downweight_for_focus_modifier = { FOCUS = learning_medicine_focus }
	}

	immediate = {
		add_character_flag = {
			flag = had_event_learning_theology_3003
			years = 5
		}
		cp:councillor_court_chaplain ?= {
			save_scope_as = chaplain
		}
		if = {
			limit = {
				NOT = { exists = scope:chaplain }
			}
			random_court_position_holder = {
				type = camp_priest_camp_officer
				save_scope_as = chaplain
			}
		}
	}

	option = { #Answers about the world lie in the heavens
		name = learning_theology.3003.a
		add_learning_lifestyle_xp = minor_lifestyle_xp
		add_character_modifier = {
			modifier = scholarship_astrological_insights_modifier
			years = 10
		}
		scope:chaplain = {
			add_opinion = {
				target = root
				modifier = impious_opinion
				opinion = -10
			}
		}
		cynical_progression_effect = yes
	}

	option = { #Focus on earthly matters
		name = learning_theology.3003.b
		add_learning_lifestyle_xp = miniscule_lifestyle_xp
		add_piety = major_piety_gain
		add_character_modifier = {
			modifier = scholarship_down_to_earth_modifier
			years = 10
		}
		scope:chaplain = {
			add_opinion = {
				target = root
				modifier = pious_opinion
				opinion = 15
			}
		}
		zealous_progression_effect = yes
	}
}


##################################################
# Worship in the same church (theology friend)
# by Linnéa Thimrén
##################################################

scripted_trigger learning_theology_3011_building_trigger = {
	faith = root.faith
	OR = { #To check that you CAN build the next lvl of the building
		AND = {
			root.culture = {
				has_innovation = innovation_manorialism
			}
			has_building = temple_01
		}
		AND = {
			root.culture = {
				has_innovation = innovation_windmills
			}
			has_building = temple_02
		}
		AND = {
			root.culture = {
				has_innovation = innovation_cranes
			}
			has_building = temple_03
		}
	}
}

learning_theology.3011 = {
	type = character_event
	title = learning_theology.3011.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					has_relation_friend = scope:believer
				}
				desc = learning_theology.3011.desc_friend
			}
			desc = learning_theology.3011.desc
		}
		desc = learning_theology.3011.ending
	}

	theme = learning_theology_focus
	left_portrait = {
		character = root
		animation = stunned
	}
	right_portrait = {
		character = scope:believer
		animation = debating
	}

	trigger = {
		is_ai = no # Develops the world a tad too fast
		NOT = {
			has_character_flag = had_event_learning_theology_3011
		}
		OR = {
			any_realm_province = {
				learning_theology_3011_building_trigger = yes
			}
			domicile ?= {
				domicile_location = {
					learning_theology_3011_building_trigger = yes
				}
			}
		}
	}

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

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

		random_realm_province = {
			limit = {
				learning_theology_3011_building_trigger = yes
			}
			weight = { #More likely if it's your province
				base = 100
				modifier = {
					add = 200
					province_owner = root
				}
				modifier = {
					add = 500
					this = root.capital_province
				}
			}
			save_scope_as = temple_county
		}
		if = {
			limit = {
				NOT = { exists = scope:temple_county }
			}
			domicile ?= {
				domicile_location = {
					save_scope_as = temple_county
				}
			}
		}

		#Find a believer (potential friend)
		if = {
			limit = {
				NOT = {
					any_relation = {
						type = friend
						lifestyle_friend_trigger = { CHARACTER = root FOCUS = learning_theology_focus }
					}
				}
			}
			potential_lifestyle_friend_saving_effect = { FOCUS = learning_theology_focus SCOPE_NAME = believer }
		}
		else = {
			random_relation = {
				type = friend
				limit = {
					lifestyle_friend_trigger = { CHARACTER = root FOCUS = learning_theology_focus }
				}
				save_scope_as = believer
			}
		}
	}

	option = { #Convince them to invest in the church
		name = {
			trigger = { has_relation_friend = scope:believer }
			text = learning_theology.3011.a_friend
		}
		name = {
			trigger = { NOT = { has_relation_friend = scope:believer } }
			text = learning_theology.3011.a
		}
		if = {
			limit = {
				has_relation_friend = scope:believer
			}
			theology_3011_a_success_effect = yes
		}
		else = {
			duel = {
				skill = learning
				value = 10
				10 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = 2
					}
					modifier = {
						add = {
							value = scope:believer.learning
							subtract = average_skill_rating
							multiply = 2
							min = 10 #Guaranteed help
						}
					}
					desc = learning_theology.3011.a.success
					send_interface_toast = {
						title = learning_theology.3011.a.success
						left_icon = scope:believer
						theology_3011_a_success_effect = yes
					}
				}
				10 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = -2
					}
					modifier = {
						add = {
							value = scope:believer.learning
							subtract = average_skill_rating
							multiply = -2
							max = 0 #They shouldn't make this worse
						}
					}
					desc = learning_theology.3011.a.failure
					send_interface_toast = {
						title = learning_theology.3011.a.failure
						left_icon = scope:believer
						theology_3011_a_failure_effect = yes
					}
				}
			}
		}
		ai_chance = {
			base = 50
		}
	}

	option = { #nah
		name = learning_theology.3011.b
		add_gold = minor_gold_value
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_greed = 2
			}
		}
	}
	
	after = {
		scope:believer = {
			silent_disappearance_ai_if_created_effect = yes
		}
	}
}


##################################################
# Send fan mail to religious head
# by Linnéa Thimrén
##################################################

learning_theology.3021 = {
	type = character_event
	title = learning_theology.3021.t
	desc = {
		desc = learning_theology.3021.desc_opening
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:believer
				}
				desc = learning_theology.3021.desc_friend
			}
			desc = learning_theology.3021.desc
		}
		desc = {
			first_valid = {
				triggered_desc = {
					trigger = {
						faith = {
							OR = { religion_tag = eastern_orthodox_religion religion_tag = catholic_religion religion_tag = protestant_religion }
						}
					}
					desc = learning_theology.3021.desc_christian
				}
				desc = learning_theology.3021.desc_other
			}
		}
	}

	theme = learning_theology_focus
	left_portrait = {
		character = root
		animation = writing
	}
	right_portrait = {
		character = scope:compliment_receiver
		animation = personality_zealous
	}
	lower_right_portrait = scope:believer

	trigger = {
		NOT = {
			has_character_flag = had_event_learning_theology_3021
		}
		exists = faith.religious_head
		faith.religious_head = {
			this != root
		}
	}

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

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

		#Do I have a friend?
		if = {
			limit = {
				any_relation = {
					type = friend
					this != faith.religious_head
					lifestyle_friend_trigger = { CHARACTER = root FOCUS = learning_theology_focus }
				}
			}
			random_relation = {
				type = friend
				limit = {
					this != faith.religious_head
					lifestyle_friend_trigger = { CHARACTER = root FOCUS = learning_theology_focus }
				}
				save_scope_as = believer
			}
		}

		faith.religious_head = {
			save_scope_as = compliment_receiver
		}

		if = {
			limit = { #Only give a good option if you have a friend!
				exists = scope:believer
			}
			randomize_good_available_compliment_effect = { COMPLIMENT_RECEIVER = scope:compliment_receiver }
		}
		else = {
			#Randomize 3 compliment types
			randomize_available_compliment_effect = { COMPLIMENT_RECEIVER = scope:compliment_receiver }
			randomize_available_compliment_effect = { COMPLIMENT_RECEIVER = scope:compliment_receiver }
			randomize_good_available_compliment_effect = { COMPLIMENT_RECEIVER = scope:compliment_receiver }
		}
	}

	#Compassionate
	option = {
		trigger = { has_character_flag = available_compliment_compassionate }
		name = diplomacy_majesty.0004.compassionate
		flavor = {
			first_valid = {
				triggered_desc = {
					trigger = {
						exists = scope:believer
					}
					desc = learning_theology.3021.success.tt
				}
				desc = diplomacy_majesty.0004.compliment.tt #Explanation of what outcome is based on
			}
		}

		hidden_effect = {
			scope:compliment_receiver = { evaluate_compliment_effect = { COMPLIMENT_TYPE = compassionate COMPLIMENT_GIVER = root } }
		}
		learning_theology_3021_outcome_effect = yes #Mus be in every options but fallback for tooltip reasons
		ai_chance = {
			base = 50
		}
	}

	#bold
	option = {
		trigger = { has_character_flag = available_compliment_bold }
		name = diplomacy_majesty.0004.bold
		flavor = {
			first_valid = {
				triggered_desc = {
					trigger = {
						exists = scope:believer
					}
					desc = learning_theology.3021.success.tt
				}
				desc = diplomacy_majesty.0004.compliment.tt #Explanation of what outcome is based on
			}
		}

		hidden_effect = {
			scope:compliment_receiver = { evaluate_compliment_effect = { COMPLIMENT_TYPE = bold COMPLIMENT_GIVER = root } }
		}
		learning_theology_3021_outcome_effect = yes #Mus be in every options but fallback for tooltip reasons
		ai_chance = {
			base = 50
		}
	}

	#honorable
	option = {
		trigger = { has_character_flag = available_compliment_honorable }
		name = diplomacy_majesty.0004.honorable
		flavor = {
			first_valid = {
				triggered_desc = {
					trigger = {
						exists = scope:believer
					}
					desc = learning_theology.3021.success.tt
				}
				desc = diplomacy_majesty.0004.compliment.tt #Explanation of what outcome is based on
			}
		}

		hidden_effect = {
			scope:compliment_receiver = { evaluate_compliment_effect = { COMPLIMENT_TYPE = honorable COMPLIMENT_GIVER = root } }
		}
		learning_theology_3021_outcome_effect = yes #Mus be in every options but fallback for tooltip reasons
		ai_chance = {
			base = 50
		}
	}

	#greed
	option = {
		trigger = { has_character_flag = available_compliment_greedy }
		name = diplomacy_majesty.0004.greed
		flavor = {
			first_valid = {
				triggered_desc = {
					trigger = {
						exists = scope:believer
					}
					desc = learning_theology.3021.success.tt
				}
				desc = diplomacy_majesty.0004.compliment.tt #Explanation of what outcome is based on
			}
		}

		hidden_effect = {
			scope:compliment_receiver = { evaluate_compliment_effect = { COMPLIMENT_TYPE = greed COMPLIMENT_GIVER = root } }
		}
		learning_theology_3021_outcome_effect = yes #Mus be in every options but fallback for tooltip reasons
		ai_chance = {
			base = 50
		}
	}

	#rational
	option = {
		trigger = { has_character_flag = available_compliment_rational }
		name = diplomacy_majesty.0004.rational
		flavor = {
			first_valid = {
				triggered_desc = {
					trigger = {
						exists = scope:believer
					}
					desc = learning_theology.3021.success.tt
				}
				desc = diplomacy_majesty.0004.compliment.tt #Explanation of what outcome is based on
			}
		}

		hidden_effect = {
			scope:compliment_receiver = { evaluate_compliment_effect = { COMPLIMENT_TYPE = rational COMPLIMENT_GIVER = root } }
		}
		learning_theology_3021_outcome_effect = yes #Mus be in every options but fallback for tooltip reasons
		ai_chance = {
			base = 50
		}
	}

	#zealous
	option = {
		trigger = { has_character_flag = available_compliment_zealous }
		name = diplomacy_majesty.0004.zealous
		flavor = {
			first_valid = {
				triggered_desc = {
					trigger = {
						exists = scope:believer
					}
					desc = learning_theology.3021.success.tt
				}
				desc = diplomacy_majesty.0004.compliment.tt #Explanation of what outcome is based on
			}
		}

		hidden_effect = {
			scope:compliment_receiver = { evaluate_compliment_effect = { COMPLIMENT_TYPE = zealous COMPLIMENT_GIVER = root } }
		}
		learning_theology_3021_outcome_effect = yes #Mus be in every options but fallback for tooltip reasons
		ai_chance = {
			base = 50
		}
	}

	#energetic
	option = {
		trigger = { has_character_flag = available_compliment_energetic }
		name = diplomacy_majesty.0004.energetic
		flavor = {
			first_valid = {
				triggered_desc = {
					trigger = {
						exists = scope:believer
					}
					desc = learning_theology.3021.success.tt
				}
				desc = diplomacy_majesty.0004.compliment.tt #Explanation of what outcome is based on
			}
		}

		hidden_effect = {
			scope:compliment_receiver = { evaluate_compliment_effect = { COMPLIMENT_TYPE = energetic COMPLIMENT_GIVER = root } }
		}
		learning_theology_3021_outcome_effect = yes #Mus be in every options but fallback for tooltip reasons
		ai_chance = {
			base = 50
		}
	}

	#forgiving
	option = {
		trigger = { has_character_flag = available_compliment_forgiving }
		name = diplomacy_majesty.0004.forgiving
		flavor = {
			first_valid = {
				triggered_desc = {
					trigger = {
						exists = scope:believer
					}
					desc = learning_theology.3021.success.tt
				}
				desc = diplomacy_majesty.0004.compliment.tt #Explanation of what outcome is based on
			}
		}

		hidden_effect = {
			scope:compliment_receiver = { evaluate_compliment_effect = { COMPLIMENT_TYPE = forgiving COMPLIMENT_GIVER = root } }
		}
		learning_theology_3021_outcome_effect = yes #Mus be in every options but fallback for tooltip reasons
		ai_chance = {
			base = 50
		}
	}

	#beautiful
	option = {
		trigger = { has_character_flag = available_compliment_beautiful }
		name = diplomacy_majesty.0004.beautiful
		flavor = {
			first_valid = {
				triggered_desc = {
					trigger = {
						exists = scope:believer
					}
					desc = learning_theology.3021.success.tt
				}
				desc = diplomacy_majesty.0004.compliment.tt #Explanation of what outcome is based on
			}
		}

		hidden_effect = {
			scope:compliment_receiver = { evaluate_compliment_effect = { COMPLIMENT_TYPE = beautiful COMPLIMENT_GIVER = root } }
		}
		learning_theology_3021_outcome_effect = yes #Mus be in every options but fallback for tooltip reasons
		ai_chance = {
			base = 50
		}
	}

	#strong
	option = {
		trigger = { has_character_flag = available_compliment_strong }
		name = diplomacy_majesty.0004.strong
		flavor = {
			first_valid = {
				triggered_desc = {
					trigger = {
						exists = scope:believer
					}
					desc = learning_theology.3021.success.tt
				}
				desc = diplomacy_majesty.0004.compliment.tt #Explanation of what outcome is based on
			}
		}

		hidden_effect = {
			scope:compliment_receiver = { evaluate_compliment_effect = { COMPLIMENT_TYPE = strong COMPLIMENT_GIVER = root } }
		}
		learning_theology_3021_outcome_effect = yes #Mus be in every options but fallback for tooltip reasons
		ai_chance = {
			base = 50
		}
	}

	#extroverted
	option = {
		trigger = { has_character_flag = available_compliment_extroverted }
		name = diplomacy_majesty.0004.extroverted
		flavor = {
			first_valid = {
				triggered_desc = {
					trigger = {
						exists = scope:believer
					}
					desc = learning_theology.3021.success.tt
				}
				desc = diplomacy_majesty.0004.compliment.tt #Explanation of what outcome is based on
			}
		}

		hidden_effect = {
			scope:compliment_receiver = { evaluate_compliment_effect = { COMPLIMENT_TYPE = extroverted COMPLIMENT_GIVER = root } }
		}
		learning_theology_3021_outcome_effect = yes #Mus be in every options but fallback for tooltip reasons
		ai_chance = {
			base = 50
		}
	}

	#dominant
	option = {
		trigger = { has_character_flag = available_compliment_dominant }
		name = diplomacy_majesty.0004.dominant
		flavor = {
			first_valid = {
				triggered_desc = {
					trigger = {
						exists = scope:believer
					}
					desc = learning_theology.3021.success.tt
				}
				desc = diplomacy_majesty.0004.compliment.tt #Explanation of what outcome is based on
			}
		}

		hidden_effect = {
			scope:compliment_receiver = { evaluate_compliment_effect = { COMPLIMENT_TYPE = dominant COMPLIMENT_GIVER = root } }
		}
		learning_theology_3021_outcome_effect = yes #Mus be in every options but fallback for tooltip reasons
		ai_chance = {
			base = 50
		}
	}

	option = { #Nah
		name = learning_theology.3021.b
		add_piety = medium_piety_gain
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_greed = 0.75
			}
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_zeal = 10
			}
		}
	}

	after = {
		clear_available_compliments_effect = yes
	}
}


#It was well received!
learning_theology.3022 = {
	type = letter_event
	opening = {
		desc = learning_theology.3022.opening
	}
	desc = learning_theology.3022.desc
	sender = scope:compliment_receiver

	immediate = {
		save_scope_as = letter_receiver
		if = {
			limit = {
				scope:compliment_receiver = { is_alive = yes }
			}
			theology_3021_a_success_effect = yes
		}
		hidden_effect = {
			if = {
				limit = {
					has_royal_court = yes
					NOT = {
						has_character_flag = got_scroll_artifact
					}
				}
				scope:compliment_receiver = {
					create_artifact_pedestal_religious_head_letter_effect = { OWNER = scope:compliment_receiver }
				}
				add_character_flag = {
					flag = got_scroll_artifact
					years = 30
				}
			}
		}
	}

	option = {
		name = learning_theology.3022.a
		if = {
			limit = {
				exists = scope:newly_created_artifact
			}
			scope:newly_created_artifact = {
				set_owner = root
			}
		}
	}
}


#It fell flat
learning_theology.3023 = {
	type = letter_event
	opening = {
		desc = learning_theology.3023.opening
	}
	desc = learning_theology.3023.desc
	sender = scope:compliment_receiver

	immediate = {
		add_diplomacy_lifestyle_xp = minor_lifestyle_xp
	}

	option = {
		name = learning_theology.3023.a
	}
}

#It was not well received
learning_theology.3024 = {
	type = letter_event
	opening = {
		desc = learning_theology.3024.opening
	}
	desc = learning_theology.3024.desc
	sender = scope:compliment_receiver

	immediate = {
		if = {
			limit = {
				scope:compliment_receiver = { is_alive = yes }
			}
			theology_3021_a_failure_effect = yes
		}
	}

	option = {
		name = learning_theology.3024.a
	}
}


##################################################
# Deal with province of different faith
# by Linnéa Thimrén
##################################################
scripted_trigger learning_theology_3031_province_trigger = {
	religion != root.religion
	faith = {
		faith_hostility_level = {
		target = root.faith
		value >= faith_hostile_level
		}
	}
}

learning_theology.3031 = {
	type = character_event
	title = learning_theology.3031.t
	desc = {
		desc = learning_theology.3031.desc_opening
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:bishop
				}
				desc = learning_theology.3031.desc_bishop
			}
			desc = learning_theology.3031.desc
		}
	}

	theme = learning_theology_focus
	left_portrait = {
		character = root
		animation = personality_cynical
	}
	right_portrait = {
		character = scope:bishop
		animation = dismissal
		trigger = { exists = scope:bishop }
	}

	trigger = {
		NOT = {
			has_character_flag = had_event_learning_theology_3031
		}
		any_sub_realm_county = {
			learning_theology_3031_province_trigger = yes
		}
	}

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

	immediate = {
		add_character_flag = {
			flag = had_event_learning_theology_3031
			years = 5
		}
		random_sub_realm_county = {
			limit = {
				learning_theology_3031_province_trigger = yes
			}
			save_scope_as = county
		}
		if = {
			limit = {
				exists = cp:councillor_court_chaplain
			}
			cp:councillor_court_chaplain = {
				save_scope_as = bishop
			}
		}
	}

	option = { #Leave them be
		name = learning_theology.3031.a
		scope:county = {
			add_county_modifier = {
				modifier = modifier_religious_understanding_modifier
				years = 25
			}
		}
		if = {
			limit = {
				exists = scope:bishop
			}
			scope:bishop = {
				add_opinion = {
					target = root
					modifier = respect_opinion
					opinion = -5
				}
			}
		}
		stress_impact = {
			zealous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = 0.75
			}
		}
	}

	option = { #Force conversion
		name = {
			text = {
				first_valid = {
					# Praying is part of faith
					triggered_desc = {
						trigger = { religion != religion:confucianism_religion }
						desc = learning_theology.3031.b
					}
					# They're Confucian
					desc = learning_theology.3031.b_confucian
				}			
			}
		}
		if = {
			limit = {
				exists = root.cp:councillor_court_chaplain
				root.cp:councillor_court_chaplain = {
					is_performing_council_task = task_conversion
				}
				scope:county = {
					is_target_of_council_task = task_conversion
				}
			}
			custom_tooltip = learning_theology.3031.b_tt
		}
		else = {
			custom_tooltip = learning_theology.3031.b_tt2
		}
		scope:county = {
			set_variable = {
				name = learning_encouraged_conversion
				years = 30
			}
		}
		if = {
			limit = {
				exists = scope:bishop
			}
			scope:bishop = {
				add_opinion = {
					target = root
					modifier = respect_opinion
					opinion = 10
				}
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_zeal = 0.75
			}
		}
	}
}


#################################
# Study Mysticism - Chain
# by Petter Vilberg
#################################
learning_theology.3041 = {
	type = character_event
	title = learning_theology.3041.t
	desc = learning_theology.3041.desc
	theme = learning_theology_focus
	left_portrait = {
		character = root
		animation = personality_cynical
	}

	trigger = {
		NOT = { has_trait = lifestyle_mystic }
		NOT = {
			has_character_flag = had_event_learning_theology_3041
		}
	}

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

	immediate = {
		add_character_flag = {
			flag = had_event_learning_theology_3041
			years = 10
		}
	}

	option = { # Some practical experience would be useful...
		name = learning_theology.3041.a
		custom_tooltip = learning_theology.3041.a.tt
		trigger_event = {
			id = learning_theology.3042
			days = 10
		}
		ai_chance = {
			base = 50
		}
	}

	option = { # Dive deeper into the books
		name = learning_theology.3041.b
		custom_tooltip = learning_theology.3041.b.tt
		trigger_event = {
			id = learning_theology.3044
			days = 10
		}
		ai_chance = {
			base = 50
		}
	}
}

# Practical experiments
learning_theology.3042 = {
	type = character_event
	title = learning_theology.3041.t
	desc = learning_theology.3042.desc
	theme = learning_theology_focus
	left_portrait = {
		character = root
		animation = delirium
	}

	option = { # This is what I have been looking for
		name = learning_theology.3042.a
		custom_tooltip = learning_theology.3042.a.tt
		hidden_effect = {
			random_list = {
				80 = {
					trigger_event = {
						id = learning_theology.3043
						days = 10
					}
				}
				20 = {
					trigger_event = {
						id = learning_theology.3045
						days = 10
					}
				}
			}
		}
		ai_chance = {
			base = 100
		}
	}

	option = { # Worth noting down for the future
		name = learning_theology.3042.b
		add_learning_lifestyle_xp = medium_lifestyle_xp
		ai_chance = {
			base = 0
		}
	}
}

# Results
learning_theology.3043 = {
	type = character_event
	title = learning_theology.3041.t
	desc = learning_theology.3043.desc
	theme = learning_theology_focus
	left_portrait = {
		character = root
		animation = personality_content
	}
	
	option = { # This is what I have been looking for
		name = learning_theology.3043.a
		add_trait = lifestyle_mystic
		stress_impact = {
			lazy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
		}
	}

	option = { # I feel nothing, but it's very relaxing
		name = learning_theology.3043.b
		add_stress = major_stress_loss
		add_character_modifier = {
			modifier = introspective_rest_modifier
			years = 5
		}
		stress_impact = {
			diligent = medium_stress_impact_gain
			zealous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 0
			compare_modifier = {
				value = stress
			}
		}
	}
}

# Theoretical study of Mysticism
learning_theology.3044 = {
	type = character_event
	title = learning_theology.3041.t
	desc = learning_theology.3044.desc
	theme = learning_theology_focus
	left_portrait = {
		character = root
		animation = happiness
	}

	option = { # This is what I have been looking for
		name = learning_theology.3044.a
		add_learning_skill = 1
		add_learning_lifestyle_perk_points = 1
		ai_chance = {
			base = 80
		}
	}

	option = { # No, I want the trait after all
		name = learning_theology.3044.b
		custom_tooltip = learning_theology.3041.b.tt
		trigger_event = {
			id = learning_theology.3042
			days = 10
		}
		ai_chance = {
			base = 20
		}
	}
}

# Things go a little wrong
learning_theology.3045 = {
	type = character_event
	title = learning_theology.3041.t
	desc = learning_theology.3045.desc
	theme = learning_theology_focus
	left_portrait = {
		character = root
		animation = personality_cynical
	}

	option = { # I have to recapture the feeling!
		name = learning_theology.3045.a
		add_learning_lifestyle_xp = medium_lifestyle_xp
		add_character_modifier = {
			modifier = theology_dangerous_habits_modifier
			years = 5
		}
		hidden_effect = {
			random = {
				chance = 30
				trigger_event = {
					id = learning_theology.3046
					days = { 365 730 }
				}
			}
		}
	}

	option = { # A little prayer to make up for it
		name = learning_theology.3045.b
		trigger = {
			OR = {
				has_trait = zealous
				has_trait = fickle
				has_trait = diligent
			}
		}
		trait = zealous
		trait = fickle
		trait = diligent
		add_piety = medium_piety_gain
		stress_impact = {
			stubborn = medium_stress_impact_gain
		}
	}
}

# Chance to finally figure it out
learning_theology.3046 = {
	type = character_event
	title = learning_theology.3041.t
	desc = learning_theology.3046.desc
	theme = learning_theology_focus
	left_portrait = {
		character = root
		animation = personality_cynical
	}

	trigger = {
		NOR = {
			has_trait = lifestyle_mystic
			has_trait = lunatic
		}
		is_available = yes
		has_character_modifier = theology_dangerous_habits_modifier
	}

	option = { # Let's see where it leads
		name = learning_theology.3046.a
		random_list = {
			70 = {
				desc = learning_theology.3046.a.success
				compare_modifier = {
					value = learning
					multiplier = 2
				}
				custom_tooltip = learning_theology.3046.a.success.tt
				trigger_event = {
					id = learning_theology.3043
					days = 5
				}
			}
			30 = {
				desc = learning_theology.3046.a.failure
				custom_tooltip = learning_theology.3046.a.failure.tt
				hidden_effect = {
					trigger_event = {
						id = learning_theology.3047
						days = 5
					}
				}
			}
		}
		ai_chance = {
			base = 100
			modifier = {
				add = 500
				has_trait = stubborn
			}
		}
	}

	option = { # It is time to give up
		name = learning_theology.3046.b
		add_stress = medium_stress_loss
		ai_chance = {
			base = 100
			modifier = {
				add = 300
				has_trait = fickle
			}
		}
	}

	after = {
		remove_character_modifier = theology_dangerous_habits_modifier
	}
}


# Your quest drives you mad
learning_theology.3047 = {
	type = character_event
	title = learning_theology.3041.t
	desc = learning_theology.3047.desc
	theme = learning_theology_focus
	left_portrait = {
		character = root
		animation = manic
	}

	trigger = {
		NOT = {
			has_trait = lunatic
		}
	}

	option = { # This is what I have been looking for
		name = learning_theology.3047.a
		add_trait = lunatic_1
	}
}



### END Mysticism chain

#################################
# Passion Play drama - Chain
# by James Beaumont
#################################
# Should I go see the play?
learning_theology.3051 = {
	type = character_event
	title = learning_theology.3051.t
	desc = {
		desc = learning_theology.3051.desc.intro
		random_valid = {
			triggered_desc = {
				trigger = {
					scope:passion_playwright = {
						has_character_flag = passion_flag
					}
				}
				desc = learning_theology.3051.desc.passion
			}
			triggered_desc = {
				trigger = {
					scope:passion_playwright = {
						has_character_flag = nights_flag
					}
				}
				desc = learning_theology.3051.desc.arabian_nights
			}
			triggered_desc = {
				trigger = {
					scope:passion_playwright = {
						has_character_flag = inferno_flag
					}
				}
				desc = learning_theology.3051.desc.inferno
			}
			triggered_desc = {
				trigger = {
					scope:passion_playwright = {
						has_character_flag = ravenway_flag
					}
				}
				desc = learning_theology.3051.desc.my_immortal
			}
		}
		desc = learning_theology.3051.desc.outro
	}
	theme = learning_theology_focus
	left_portrait = {
		character = root
		animation = admiration
	}
	right_portrait = {
		character = scope:passion_playwright
		animation = personality_honorable
	}

	trigger = {
		NOT = {
			has_character_flag = had_event_learning_theology_3051
		}
		root.religion = { is_in_family = rf_abrahamic }
		any_pool_character = {
			province = root.capital_province
			# Standard sanity check
			is_available_ai_adult = yes
			# Character doesn't still have any lingering flags from a previous event
			NOT = { has_character_flag = has_been_passion_playwright_flag }
			# Character is at least your religion
			religion = root.religion
		}
	}

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

	immediate = {
		add_character_flag = {
			flag = had_event_learning_theology_3051
			years = 10
		}
		random_pool_character = {
			province = capital_province
			limit = {
				# Standard sanity check
				is_available_ai_adult = yes
				# Character doesn't still have any lingering flags from a previous event
				NOT = { has_character_flag = has_been_passion_playwright_flag }
				# Character is at least your religion
				religion = root.religion
			}
			weight = {
				base = 1
				modifier = { # Faith is the same as Root
					faith = root.faith
					add = 20
				}
				modifier = { # Characters of this gender generally take part in religious activities
					can_be_clergy_due_to_gender_trigger = yes
					add = 20
				}
				modifier = { # Likes religion
					has_trait = zealous
					add = 5
				}
				modifier = { # Good at writing
					has_trait = lifestyle_poet
					add = 2
				}
				modifier = {
					has_trait = journaller
					add = 2
				}
			}
			add_character_flag = {
				flag = has_been_passion_playwright_flag
				years = 5
			}
			save_scope_as = passion_playwright
			random_list = {
				99 = {
					random_list = {
						10 = {
							# For loc
							add_character_flag = {
								flag = passion_flag
								years = 5
							}
						}
						10 = {
							add_character_flag = {
								flag = nights_flag
								years = 5
							}
						}
						10 = {
							add_character_flag = {
								flag = inferno_flag
								years = 5
							}
						}
					}
				}
				1 = {
					add_character_flag = {
						flag = ravenway_flag
						years = 5
					}
					random_list = {
						10 = {
							# For loc
							add_character_flag = {
								flag = trait_intellect_good_1_flag
								years = 5
							}
						}
						10 = {
							add_character_flag = {
								flag = trait_intellect_good_2_flag
								years = 5
							}
						}
						10 = {
							add_character_flag = {
								flag = trait_intellect_good_3_flag
								years = 5
							}
						}
						10 = {
							add_character_flag = {
								flag = trait_physique_good_1_flag
								years = 5
							}
						}
						10 = {
							add_character_flag = {
								flag = trait_physique_good_2_flag
								years = 5
							}
						}
						10 = {
							add_character_flag = {
								flag = trait_physique_good_3_flag
								years = 5
							}
						}
						10 = {
							add_character_flag = {
								flag = trait_fecund_flag
								years = 5
							}
						}
						10 = {
							add_character_flag = {
								flag = trait_pure_blooded_flag
								years = 5
							}
						}
						10 = {
							add_character_flag = {
								flag = trait_beauty_good_1_flag
								years = 5
							}
						}
						10 = {
							trigger = {
								is_attracted_to_women = yes
							}
							add_character_flag = {
								flag = trait_beauty_good_2_female_flag
								years = 5
							}
						}
						10 = {
							trigger = {
								is_attracted_to_men = yes
							}
							add_character_flag = {
								flag = trait_beauty_good_2_male_flag
								years = 5
							}
						}
						10 = {
							add_character_flag = {
								flag = trait_beauty_good_3_flag
								years = 5
							}
						}
					}
				}
			}
		}
	}

	option = { # Let's go see it
		name = learning_theology.3051.a
		custom_tooltip = {
			text = learning_lifestyle_experience_gain_indication
			if = {
				limit = {
					scope:passion_playwright = {
						has_character_flag = ravenway_flag
					}
				}
				trigger_event = {
					id = learning_theology.3053
					days = 10
				}
			}
			else = {
				trigger_event = {
					id = learning_theology.3052
					days = 10
				}
			}
		}
		ai_chance = {
			base = 50
		}
	}

	option = { # Nah, I don't want this one
		name = learning_theology.3051.b
		stress_impact = {
			gregarious = minor_stress_impact_gain
			zealous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 0
		}
	}
}

# Normal outcome
learning_theology.3052 = {
	type = character_event
	title = {
		random_valid = {
			triggered_desc = {
				trigger = {
					scope:passion_playwright = {
						has_character_flag = passion_flag
					}
				}
				desc = learning_theology.3051.passion
			}
			triggered_desc = {
				trigger = {
					scope:passion_playwright = {
						has_character_flag = nights_flag
					}
				}
				desc = learning_theology.3051.arabian_nights
			}
			triggered_desc = {
				trigger = {
					scope:passion_playwright = {
						has_character_flag = inferno_flag
					}
				}
				desc = learning_theology.3051.inferno
			}
			triggered_desc = {
				trigger = {
					scope:passion_playwright = {
						has_character_flag = ravenway_flag
					}
				}
				desc = learning_theology.3051.my_immortal
			}
		}
	}
	trigger = {
		scope:passion_playwright = {
			is_alive = yes
		}
	}
	desc = learning_theology.3052.desc
	theme = learning_theology_focus
	left_portrait = {
		character = root
		animation = admiration
	}
	right_portrait = {
		character = scope:passion_playwright
		animation = personality_honorable
	}

	option = { # Teach me your ways!
		name = learning_theology.3052.a
		pay_short_term_gold = {
			target = scope:passion_playwright
			gold = minor_gold_value
		}
		add_piety = minor_piety_gain
		add_learning_lifestyle_xp = minor_lifestyle_xp
		stress_impact = {
			zealous = minor_stress_impact_loss
			arrogant = medium_stress_impact_gain
			ambitious = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_zeal = 2
				ai_compassion = 2
			}
		}
	}

	option = { # Nah, I can write it better
		name = learning_theology.3052.b
		custom_tooltip = {
			text = learning_lifestyle_rank_up_indication
			trigger_event = {
				id = learning_theology.3054
				days = 10
			}
		}
		show_as_tooltip = {
			duel = {
				skill = learning
				target = scope:passion_playwright
			}
		}
		stress_impact = {
			journaller = minor_stress_impact_loss # You find writing relaxing
			arrogant = minor_stress_impact_loss
			content = minor_stress_impact_gain
			lazy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_boldness = 2
				ai_sociability = 2
			}
		}
	}
}

# My Immortal outcome
learning_theology.3053 = {
	type = character_event
	title = learning_theology.3051.desc.my_immortal
	desc = learning_theology.3053.desc
	theme = learning_theology_focus
	left_portrait = {
		character = root
		animation = disbelief
	}
	right_portrait = {
		character = scope:passion_playwright
		animation = flirtation_left
	}
	trigger = {
		scope:passion_playwright = {
			is_alive = yes
		}
	}

	option = { # Boo!
		name = learning_theology.3053.a
		add_piety = minor_piety_gain
		stress_impact = {
			deviant = medium_stress_impact_gain
			lustful = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50
		}
	}

	option = { # I'll do it better
		name = learning_theology.3053.b
		custom_tooltip = {
			text = learning_lifestyle_rank_up_indication
			trigger_event = {
				id = learning_theology.3054
				days = 10
			}
		}
		show_as_tooltip = {
			duel = {
				skill = learning
				target = scope:passion_playwright
			}
		}
		stress_impact = {
			journaller = minor_stress_impact_loss # You find writing relaxing
			arrogant = minor_stress_impact_loss
			content = minor_stress_impact_gain
			lazy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50
		}
	}

	option = { # I liked the horny fanfiction
		trigger = {
			OR = {
				has_trait = deviant
				has_trait = lustful
			}
		}
		name = learning_theology.3053.c
		add_piety = minor_piety_loss
		add_courtier = scope:passion_playwright
		set_relation_friend = { reason = friend_passion_play target = scope:passion_playwright }
		stress_impact = {
			deviant = minor_stress_impact_loss
			lustful = minor_stress_impact_loss
			chaste = minor_stress_impact_gain
		}
		ai_chance = { # This is for player memes
			base = 0
		}
	}
}

scripted_trigger 3054_suitable_actor_trigger = {
	NOT = { this = scope:passion_playwright }
	is_available_ai_adult = yes
}

# Deciding on a lead actor
learning_theology.3054 = {
	type = character_event
	title = learning_theology.3054.t
	desc = {
		desc = learning_theology.3054.desc.intro
		random_valid = {
			triggered_desc = {
				trigger = {
					scope:passion_playwright = {
						NOT = { has_character_flag = passion_flag }
					}
				}
				desc = learning_theology.3051.passion
			}
			triggered_desc = {
				trigger = {
					scope:passion_playwright = {
						NOT = { has_character_flag = nights_flag }
					}
				}
				desc = learning_theology.3051.arabian_nights
			}
			triggered_desc = {
				trigger = {
					scope:passion_playwright = {
						NOT = { has_character_flag = inferno_flag }
					}
				}
				desc = learning_theology.3051.inferno
			}
		}
		desc = learning_theology.3054.desc.outro
	}
	theme = learning_theology_focus
	left_portrait = {
		character = root
		animation = personality_honorable
	}
	lower_left_portrait = {
		character = scope:family_actor
	}
	lower_center_portrait = {
		character = scope:random_actor
	}
	lower_right_portrait = {
		character = scope:passion_playwright
	}


	immediate = {
		hidden_effect = {
			duel = {
				skill = learning
				target = scope:passion_playwright
				60 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = 3.5
						min = -49
					}
					root = {
						add_character_flag = {
							flag = superior_passion_play_flag
							years = 5
						}
					}
				}
				# Your writing was not as good as the Playwright
				40 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = -3.5
						min = -49
					}
					root = {
						add_character_flag = {
							flag = inferior_passion_play_flag
							years = 5
						}
					}
				}
			}
			random_courtier_or_guest = {
				limit = {
					3054_suitable_actor_trigger = yes
					is_close_family_of = root
				}
				weight = {
					base = 1
					modifier = { # Faith is the same as Root
						faith = root.faith
						add = 20
					}
					modifier = { # Characters of this gender generally take part in religious activities
						can_be_clergy_due_to_gender_trigger = yes
						add = 20
					}
					modifier = { # Likes religion
						has_trait = zealous
						add = 5
					}
					modifier = { # Good at writing
						has_trait = gregarious
						add = 2
					}
					modifier = {
						has_trait = ambitious
						add = 2
					}
				}
				save_scope_as = family_actor
			}
			random_courtier_or_guest = {
				limit = {
					3054_suitable_actor_trigger = yes
					NOT = { is_close_family_of = root }
				}
				weight = {
					base = 1
					modifier = { # Faith is the same as Root
						faith = root.faith
						add = 20
					}
					modifier = { # Characters of this gender generally take part in religious activities
						can_be_clergy_due_to_gender_trigger = yes
						add = 20
					}
					modifier = { # Likes religion
						has_trait = zealous
						add = 5
					}
					modifier = { # Good at writing
						has_trait = gregarious
						add = 2
					}
					modifier = {
						has_trait = ambitious
						add = 2
					}
				}
				save_scope_as = random_actor
			}
		}
	}

	option = { # Myself, of course!
		name = learning_theology.3054.a
		show_as_tooltip = {
			duel = {
				skill = diplomacy
				target = scope:passion_playwright
			}
		}
		custom_tooltip = {
			text = learning_theology.3054.a.tt
			save_scope_as = lead_actor
		}

		stress_impact = {
			shy = medium_stress_impact_gain
			humble = medium_stress_impact_gain
			arrogant = minor_stress_impact_loss
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = 2
				ai_sociability = 2
			}
			modifier = {
				add = 20
				# I am a good actor
				root.diplomacy >= scope:passion_playwright.diplomacy
			}
			modifier = {
				factor = 0.5
				# I'm a bad actor
				root.diplomacy < scope:passion_playwright.diplomacy
			}
		}
	}

	option = { # My close family member
		name = learning_theology.3054.b
		trigger = {
			exists = scope:family_actor
		}
		show_as_tooltip = {
			duel = {
				skill = diplomacy
				target = scope:passion_playwright
			}
		}
		custom_tooltip = {
			text = learning_theology.3054.b.tt
			scope:family_actor = { save_scope_as = lead_actor }
		}
		reverse_add_opinion = {
			modifier = flattered_opinion
			opinion = 15
			target = scope:family_actor
		}
		stress_impact = {
			arrogant = medium_stress_impact_gain
			ambitious = medium_stress_impact_gain
			family_first = minor_stress_impact_loss
		}
		ai_chance = {
			base = 50
			modifier = {
				factor = 2
				has_trait = family_first
			}
			modifier = {
				add = 50
				# I am a bad actor
				root.diplomacy < scope:passion_playwright.diplomacy
				# My family member is a good actor
				scope:family_actor.diplomacy >= scope:passion_playwright.diplomacy
			}
		}
	}

	option = { # Random dude
		name = learning_theology.3054.c
		trigger = {
			exists = scope:random_actor
		}
		show_as_tooltip = {
			duel = {
				skill = diplomacy
				target = scope:passion_playwright
			}
		}
		custom_tooltip = {
			text = learning_theology.3054.c.tt
			scope:random_actor = { save_scope_as = lead_actor }
		}
		reverse_add_opinion = {
			modifier = flattered_opinion
			opinion = 15
			target = scope:random_actor
		}
		if = {
			limit = {
				scope:random_actor = { NOT = { is_courtier_of = root } }
			}
			pay_short_term_gold = {
				target = scope:random_actor
				gold = minor_gold_value
			}
			add_courtier = scope:random_actor
		}
		stress_impact = {
			arrogant = medium_stress_impact_gain
			ambitious = medium_stress_impact_gain
		}
		ai_chance = {
			base = 20
			modifier = {
				add = 80
				# I am a bad actor
				root.diplomacy < scope:passion_playwright.diplomacy
				# My family member is a bad actor
				exists = scope:family_actor
				scope:family_actor.diplomacy < scope:passion_playwright.diplomacy
				# This random courtier is a good actor
				scope:random_actor.diplomacy >= scope:passion_playwright.diplomacy
			}
		}
	}

	after = {
		trigger_event = {
			id = learning_theology.3055
			days = 10
		}
	}
}

# Final outcome
learning_theology.3055 = {
	type = character_event
	title = learning_theology.3055.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					NOT = { scope:lead_actor = root }
				}
				desc = learning_theology.3055.desc.intro.hired_actor
			}
			desc = learning_theology.3055.desc.intro.solo		
		}
		first_valid = {
			#Hired, victory
			triggered_desc = {
				trigger = {
					NOT = { scope:lead_actor = root }
					has_character_flag = superior_passion_play_flag
					has_character_flag = superior_acting_flag
				}
				desc = learning_theology.3055.desc.victory.hired_actor
			}
			#Hired, defeat writing
			triggered_desc = {
				trigger = {
					NOT = { scope:lead_actor = root }
					has_character_flag = inferior_passion_play_flag
					has_character_flag = superior_acting_flag
				}
				desc = learning_theology.3055.desc.defeat_writing.hired_actor
			}
			#Hired, defeat acting
			triggered_desc = {
				trigger = {
					NOT = { scope:lead_actor = root }
					has_character_flag = inferior_acting_flag
				}
				desc = learning_theology.3055.desc.defeat_acting.hired_actor
			}
			#Solo, win
			triggered_desc = {
				trigger = {
					has_character_flag = superior_passion_play_flag
					has_character_flag = superior_acting_flag
				}
				desc = learning_theology.3055.desc.victory.solo
			}
			#Solo, defeat writing
			triggered_desc = {
				trigger = {
					has_character_flag = inferior_passion_play_flag
					has_character_flag = superior_acting_flag
				}
				desc = learning_theology.3055.desc.defeat_writing.solo
			}
			#Solo, defeat acting
			triggered_desc = {
				trigger = {
					has_character_flag = inferior_acting_flag
				}
				desc = learning_theology.3055.desc.defeat_acting.solo
			}	
		}
		first_valid = {
			#Victory
			triggered_desc = {
				trigger = {
					has_character_flag = superior_acting_flag
					has_character_flag = superior_passion_play_flag
				}
				desc = learning_theology.3055.desc.victory_outro
			}
			#Hired, defeat
			triggered_desc = {
				trigger = {
					NOT = { scope:lead_actor = root }
					OR = {
						has_character_flag = inferior_acting_flag
						has_character_flag = inferior_passion_play_flag
					}
				}
				desc = learning_theology.3055.desc.defeat_outro.hired_actor
			}
			#Defeat
			triggered_desc = {
				trigger = {
					OR = {
						has_character_flag = inferior_acting_flag
						has_character_flag = inferior_passion_play_flag
					}
				}
				desc = learning_theology.3055.desc.defeat_outro.solo
			}	
		}
	}
	theme = learning_theology_focus
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = {
				has_character_flag = superior_acting_flag
				has_character_flag = superior_passion_play_flag
			}
			animation = happiness
		}
		triggered_animation = {
			trigger = {
				scope:lead_actor != root
				has_character_flag = inferior_acting_flag
			}
			animation = anger
		}
		animation = disbelief
	}
	right_portrait = {
		trigger = { 
			NOT = { scope:lead_actor = root }
		}
		character = scope:lead_actor
		triggered_animation = {
			trigger = {
				root = {
					OR = {
						has_character_flag = inferior_acting_flag
						has_character_flag = inferior_passion_play_flag
					}
				}
			}
			animation = shame
		}
		animation = storyteller
	}
	lower_right_portrait = {
		character = scope:passion_playwright
	}

	immediate = {
		hidden_effect = {
			scope:lead_actor = {
				duel = {
					skill = diplomacy
					target = scope:passion_playwright
					60 = {
						compare_modifier = {
							value = scope:duel_value
							multiplier = 3.5
							min = -49
						}
						root = {
							add_character_flag = {
								flag = superior_acting_flag
								years = 5
							}
						}
					}
					# Your writing was not as good as the Playwright
					40 = {
						compare_modifier = {
							value = scope:duel_value
							multiplier = -3.5
							min = -49
						}
						root = {
							add_character_flag = {
								flag = inferior_acting_flag
								years = 5
							}
						}
					}
				}
			}
		}
	}

	option = { # I made the better play
		trigger = {
			root = {
				has_character_flag = superior_passion_play_flag
				has_character_flag = superior_acting_flag
			}
		}
		name = learning_theology.3055.a
		add_learning_lifestyle_perk_points = 1
		add_piety = medium_piety_gain
		# Give prestige for
		if = {
			limit = {
				scope:lead_actor = root
			}
			add_prestige = medium_prestige_gain
		}
		else = {
			add_prestige = minor_prestige_gain
		}
		ai_chance = {
			base = 50
		}
	}

	option = { # I failed at making a better play
		name = learning_theology.3055.b
		trigger = {
			root = {
				OR = {
					has_character_flag = inferior_passion_play_flag
					has_character_flag = inferior_acting_flag
				}
			}
		}
		add_piety = minor_piety_loss
		add_stress = medium_stress_impact_gain
		ai_chance = {
			base = 50
		}
	}

	after = {
		root = {
			if = {
				limit = {
					has_character_flag = superior_passion_play_flag
				}
				remove_character_flag = superior_passion_play_flag
			}
			if = {
				limit = {
					has_character_flag = superior_acting_flag
				}
				remove_character_flag = superior_acting_flag
			}
			if = {
				limit = {
					has_character_flag = inferior_passion_play_flag
				}
				remove_character_flag = inferior_passion_play_flag
			}
			if = {
				limit = {
					has_character_flag = inferior_acting_flag
				}
				remove_character_flag = inferior_acting_flag
			}
		}
	}
}


################################################################################################################################
################################################################################################################################

##################################################
# Find old text
# by Linnéa Thimrén & Flavio Verna
##################################################

learning_theology_special.1001 = {
	type = character_event
	title = learning_theology_special.1001.t
	desc = learning_theology_special.1001.desc
	theme = learning_theology_focus
	left_portrait = {
		character = root
		animation = stressed_teacher
	}
	right_portrait = {
		character = scope:portrait
		animation = thinking
		trigger = {
			exists = scope:portrait
			scope:portrait != root
		}
	}

	trigger = {
		is_ai = no
		OR = {
			has_focus = learning_theology_focus
			has_focus = learning_adventurer_focus
			has_realm_law = camp_purpose_scholars
		}
		NOT = { has_character_flag = had_learning_theology_special_1001_this_lifetime }
		faith = {
			NOR = {
				exists = var:variable_changed_doctrine_learning_theology_special_1001
				has_doctrine_parameter = unreformed
			}
		}
		OR = {
			exists = cp:councillor_court_chaplain
			AND = {
				exists = faith.religious_head
				root = faith.religious_head
			}
			AND = {
				exists = faith.religious_head
				exists = faith.religious_head.liege
				faith.religious_head.liege = root
			}
		}
		OR = {
			has_trait = scholar
			learning >= very_high_skill_rating
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = -0.5
			faith = { fervor < medium_fervor_value }
		}
		modifier = {
			add = -0.5
			NOR = {
				AND = {
					exists = faith.religious_head
					root = faith.religious_head
				}
				AND = {
					exists = faith.religious_head
					exists = faith.religious_head.liege
					faith.religious_head.liege = root
					faith.religious_head = { is_ai = yes }
				}
			}
		}
	}

	immediate = {
		add_character_flag = had_learning_theology_special_1001_this_lifetime
		if = {
			limit = {
				exists = faith.religious_head
				root = faith.religious_head
			}
			faith.religious_head = {
				save_scope_as = player_pope
				save_scope_as = portrait #For portrait
			}
		}
		else_if = {
			limit = {
				exists = faith.religious_head
				exists = faith.religious_head.liege
				faith.religious_head.liege = root
				faith.religious_head = { is_ai = yes }
			}
			faith.religious_head = {
				save_scope_as = vassal_pope
				save_scope_as = portrait #For portrait
			}
			save_scope_as = pope_liege
		}
		else_if = {
			limit = {
				exists = cp:councillor_court_chaplain
			}
			cp:councillor_court_chaplain = {
				save_scope_as = bishop
				save_scope_as = portrait #For portrait
			}
		}
		hidden_effect = { #To randomize the doctrine that's changed
			random_list = {
				10 = {
					trigger = {
						NOT = { faith = { has_doctrine = doctrine_adultery_women_accepted } }
					}
					save_scope_value_as = {
						name = female_adultery_doctrine
						value = yes
					}
				}
				10 = {
					trigger = {
						NOT = { faith = { has_doctrine = doctrine_adultery_men_accepted } }
					}
					save_scope_value_as = {
						name = male_adultery_doctrine
						value = yes
					}
				}
				10 = {
					trigger = {
						NOT = { faith = { has_doctrine = doctrine_homosexuality_accepted } }
					}
					save_scope_value_as = {
						name = homosexuality_doctrine
						value = yes
					}
				}
				10 = {
					trigger = {
						NOT = { faith = { has_doctrine = doctrine_kinslaying_accepted } }
					}
					save_scope_value_as = {
						name = kinslyaing_doctrine
						value = yes
					}
				}
				10 = {
					trigger = {
						NOT = { faith = { has_doctrine_parameter = witchcraft_accepted } }
					}
					save_scope_value_as = {
						name = witchcraft_doctrine
						value = yes
					}
				}
				10 = {
					trigger = {
						NOT = { faith = { has_doctrine = doctrine_consanguinity_unrestricted } }
					}
					save_scope_value_as = {
						name = consanguinity_doctrine
						value = yes
					}
				}
			}
		}
	}
	option = { #Player Religious Head decides to incorporate doctrine.
		name = learning_theology_special.1001.d
		trigger = {
			exists = scope:player_pope
			faith = { fervor >= medium_fervor_value }
		}
		duel = {
			skill = learning
			value = extremely_high_skill_rating
			10 = {
				desc = learning_theology_special.1001.d.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 1
				}
				show_as_tooltip = {
					learning_theology_special_1001_doctrine_effect = yes
					add_learning_lifestyle_perk_points = 1
				}
				trigger_event = learning_theology_special.1002
			}
			20 = {
				desc = learning_theology_special.1001.d.failure
				send_interface_toast = {
					title = learning_theology_special.1001.d.failure.toast
					left_icon = root
					add_learning_lifestyle_xp = minor_lifestyle_xp
					add_piety = major_piety_loss
				}
			}
		}
		stress_impact = {
			zealous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 0
		}
	}
	option = { #Player petitions vassal religious head to integrate doctrine.
		name = learning_theology_special.1001.e
		trigger = {
			exists = scope:vassal_pope
			faith = { fervor >= medium_fervor_value }
		}
		duel = {
			skill = learning
			target = scope:vassal_pope
			1 = {
				desc = learning_theology_special.1001.e.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 2
				}
				opinion_modifier = { # Opinion Factor
					who = scope:vassal_pope
					opinion_target = root
					multiplier = 0.25
				}
				show_as_tooltip = {
					learning_theology_special_1001_doctrine_effect = yes
					add_learning_lifestyle_perk_points = 1
				}
				trigger_event = learning_theology_special.1002
			}
			50 = {
				desc = learning_theology_special.1001.e.failure
				send_interface_toast = {
					title = learning_theology_special.1001.e.failure.toast
					left_icon = scope:vassal_pope
					add_learning_lifestyle_xp = minor_lifestyle_xp
					add_piety = major_piety_loss
				}
			}
		}
		stress_impact = {
			zealous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 0
		}
	}

	option = { #Share findings with Court Chaplain.
		name = learning_theology_special.1001.a
		trigger = {
			exists = scope:bishop
		}
		scope:bishop = {
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = 15
			}
		}
		random_list = {
			desc = learning_theology_special.1001.a.desc
			100 = {
				desc = learning_theology_special.1001.a.success
				show_chance = no
				modifier = {
					add = {
						value = scope:bishop.ai_zeal
					}
				}
				send_interface_toast = {
					title = learning_theology_special.1001.a.success.toast
					add_learning_lifestyle_perk_points = 1
				}
			}
			100 = {
				desc = learning_theology_special.1001.a.failure
				show_chance = no
				modifier = { #Make this instant success
					scope:bishop.ai_zeal >= low_positive_ai_value
					add = -1000
				}
				modifier = {
					add = {
						value = scope:bishop.ai_zeal
						multiply = -1
					}
				}
				send_interface_toast = {
					title = learning_theology_special.1001.a.failure.toast
					left_icon = scope:bishop
					add_learning_lifestyle_xp = miniscule_lifestyle_xp
					add_piety = minor_piety_gain
				}
			}
		}

		stress_impact = {
			zealous = minor_stress_impact_loss
			cynical = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
		}
	}

	option = { #Study in private.
		name = learning_theology_special.1001.b
		add_learning_lifestyle_xp = medium_lifestyle_xp
		add_piety = minor_piety_loss
		stress_impact = {
			zealous = medium_stress_impact_gain
			cynical = medium_stress_impact_loss
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = -0.5
			}
		}
	}

	option = { #Burn.
		name = learning_theology_special.1001.c
		add_piety = medium_piety_gain
		zealous_progression_effect = yes
		stress_impact = {
			zealous = medium_stress_impact_loss
			cynical = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = 1.5
			}
		}
	}
}

#Player successfully changed the faith's doctrine.
learning_theology_special.1002 = {
	type = character_event
	title = learning_theology_special.1002.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:player_pope
				}
				desc = learning_theology_special.1002.a.desc
			}
			triggered_desc = {
				trigger = {
					exists = scope:vassal_pope
				}
				desc = learning_theology_special.1002.b.desc
			}
		}
	}
	theme = learning_theology_focus
	left_portrait = {
		character = root
		animation = personality_zealous
	}
	right_portrait = {
		character = scope:portrait
		animation = disapproval
		trigger = {
			exists = scope:portrait
			scope:portrait != root
		}
	}

	immediate = {
		learning_theology_special_1001_doctrine_effect = yes
		add_learning_lifestyle_perk_points = 1

	}
	option = { #
		name = learning_theology_special.1002.a
		every_player = {
			limit = {
				NOR = {
					this = root
					this = scope:vassal_pope
				}
				faith = root.faith
			}
			trigger_event = learning_theology_special.1003
		}
	}
}

#Other players notified of the doctrinal change.
learning_theology_special.1003 = {
	type = character_event
	title = learning_theology_special.1002.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:player_pope
				}
				desc = learning_theology_special.1003.a.desc
			}
			triggered_desc = {
				trigger = {
					exists = scope:vassal_pope
				}
				desc = learning_theology_special.1003.b.desc
			}
		}
	}
	theme = learning_theology_focus

	left_portrait = {
		character = root
		animation = interested_left
	}
	right_portrait = {
		character = scope:portrait
		animation = personality_zealous
		trigger = {
			exists = scope:portrait
			scope:portrait != root
		}
	}

	immediate = {
		show_as_tooltip = {
			learning_theology_special_1001_doctrine_effect = yes
		}
	}
	option = {
		name = learning_theology_special.1003.a
	}
}

##################################################
# Learned scholar come to your court
# by Linnéa Thimrén
##################################################

scripted_trigger learning_theology_special_1101_rabbi_trigger = {
	faith = faith:rabbinism
	OR = {
		has_trait = education_learning_2
		has_trait = education_learning_3
		has_trait = education_learning_4
	}
	learning >= medium_skill_rating
	can_be_clergy_due_to_gender_trigger = yes
}

learning_theology_special.1101 = {
	type = character_event
	title = learning_theology_special.1101.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					has_character_flag = flag_learning_theology_2020_historical
				}
				desc = learning_theology_special.1101.desc
			}
			desc = learning_theology_special.1101.desc.fallback
		}
	}

	theme = learning_theology_focus
	override_background = {
		reference = throne_room
	}
	left_portrait = {
		character = root
		animation = interested_left
	}
	right_portrait = {
		character = scope:scholar
		animation = writing
	}

	trigger = {
		OR = {
			has_focus = learning_theology_focus
			has_focus = learning_adventurer_focus
			has_realm_law = camp_purpose_scholars
		}
		NOT = { has_character_flag = had_learning_theology_special_1101_this_lifetime }
		is_playable_character = yes
		faith = {
			OR = {
				religion_tag = judaism_religion
				OR = { religion_tag = eastern_orthodox_religion religion_tag = catholic_religion religion_tag = protestant_religion }
				religion_tag = dualism_religion
				religion_tag = islam_religion
			}
		}
	}

	immediate = {
		add_character_flag = {
			flag = is_in_learning_special_event
			days = 200
		}
		add_character_flag = had_learning_theology_special_1101_this_lifetime

		if = { #If Rashi could have been alive we create him (for players!)
			limit = {
				game_start_date >= 1040.1.1
				game_start_date <= 1105.1.1
				is_ai = no
				NOT = { #Only spawns once.
					is_target_in_global_variable_list = {
						name = special_character_list
						target = flag:flag_theology_1101_shlomo_yitzchaki
					}
				}
			}
			create_character = {
				location = root.capital_province
				template = scholar_character
				faith = faith:rabbinism
				culture = culture:french
				trait = scholar
				trait = diligent
				name = "Shlomo Yitzchaki"
				gender = male
				save_scope_as = scholar
			}
			save_scope_value_as = {
				name = rashi
				value = yes
			}
			add_to_global_variable_list = {
				name = special_character_list
				target = flag:flag_theology_1101_shlomo_yitzchaki
			}
			add_character_flag = flag_learning_theology_2020_historical
		}
		else_if = {
			limit = {
				exists = root.capital_province
				any_pool_character = {
					province = root.capital_province
					learning_theology_special_1101_rabbi_trigger = yes
				}
			}
			random_pool_character = {
				province = root.capital_province
				limit = { learning_theology_special_1101_rabbi_trigger = yes }
				save_scope_as = scholar
			}
			save_scope_value_as = {
				name = rashi
				value = no
			}
		}
		else = {
			create_character = {
				location = root.capital_province
				template = scholar_character
				faith = root.faith
				culture = root.culture
				gender_female_chance = {
					if = {
						limit = { faith:rabbinism = { has_doctrine_parameter = clergy_must_be_male } }
						value = 0
					}
					else_if = {
						limit = { faith:rabbinism = { has_doctrine_parameter = clergy_must_be_female } }
						value = 100
					}
					else = {
						value = 50
					}
				}
				save_scope_as = scholar
				after_creation = {
					add_character_flag = created
				}
			}
			save_scope_value_as = {
				name = rashi
				value = no
			}
		}
	}

	option = { # Let's write commentaries!
		name = learning_theology_special.1101.a
		custom_tooltip = learning_lifestyle_rank_up_indication
		trigger_event = {
			id = learning_theology_special.1102
			days = { 14 21 }
		}
		add_visiting_courtier = scope:scholar
		if = {
			limit = {
				root.faith = {
					faith_hostility_level = {
						target = scope:scholar.faith
						value >= faith_hostile_level
					}
				}
			}
			stress_impact = {
				zealous = medium_stress_impact_gain
			}
		}
		ai_chance = {
			base = 75
		}
	}

	option = { #nah
		name = learning_theology_special.1101.b
		cynical_progression_effect = yes
		add_character_modifier = {
			modifier = focused_modifier
			years = 10
		}
		remove_character_flag = is_in_learning_special_event
		ai_chance = {
			base = 0
		}
	}

	option = { #heretic!!
		name = learning_theology_special.1101.c
		trigger = {
			root.faith = {
				faith_hostility_level = {
					target = scope:scholar.faith
					value >= faith_hostile_level
				}
			}
		}
		zealous_progression_effect = yes
		add_piety = major_piety_gain
		scope:scholar = {
			add_opinion = {
				modifier = disappointed_opinion
				opinion = -15
				target = root
			}
		}
		remove_character_flag = is_in_learning_special_event
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_zeal = 0.75
			}
		}
	}

	after = {
		remove_character_flag = flag_learning_theology_2020_historical
		scope:scholar = {
			silent_disappearance_ai_if_created_effect = yes
		}
	}
}

#Writing commentaries - publish one or do more?
learning_theology_special.1102 = {
	type = character_event
	title = learning_theology_special.1101.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:scholar
				}
				desc = learning_theology_special.1102.desc
			}
			desc = learning_theology_special.1102.desc_dead
		}
		desc = learning_theology_special.1102.desc_ending
	}

	theme = learning_theology_focus
	left_portrait = {
		character = root
		animation = writing
	}
	right_portrait = {
		character = scope:scholar
		animation = happy_teacher
	}

	option = { #Give credit to scholar
		trigger = {
			scope:scholar = { is_alive = yes }
		}
		name = learning_theology_special.1102.c

		if = {
			limit = {
				can_set_relation_friend_trigger = { CHARACTER = scope:scholar }
			}
			set_relation_friend = { reason = friend_bible_commentary target = scope:scholar }
		}

		random_list = {
			desc = learning_theology_special.1102.c.rl_desc
			100 = {
				desc = learning_theology_special.1102.c.success
				show_chance = no
				modifier = {
					add = {
						value = scope:scholar.ai_honor
					}
				}

				send_interface_toast = {
					title = learning_theology_special.1102.c.success.toast
					left_icon = scope:scholar
					add_learning_lifestyle_perk_points = 1
				}
			}
			100 = {
				desc = learning_theology_special.1102.c.failure
				show_chance = no
				modifier = { #Make this instant success
					scope:scholar.ai_honor >= low_positive_ai_value
					add = -1000
				}
				modifier = {
					add = {
						value = scope:scholar.ai_honor
						multiply = -1
					}
				}
				send_interface_toast = {
					title = learning_theology_special.1102.c.failure.toast
					left_icon = scope:scholar
					add_learning_lifestyle_xp = minor_lifestyle_xp
				}
			}
		}

		ai_chance = {
			base = 200
		}
	}

	option = { #"Publish" and claim prestige
		trigger = {
			scope:scholar = { is_alive = yes }
		}
		name = learning_theology_special.1102.b

		set_relation_rival = {
			target = scope:scholar
			reason = rival_academic_dispute
		}
		scope:scholar = { select_and_move_to_pool_effect = yes }

		duel = {
			skill = intrigue
			target = scope:scholar
			60 = {
				desc = learning_theology_special.1102.b.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 4
				}
				add_learning_lifestyle_perk_points = 1
				add_prestige = medium_prestige_gain

			}
			40 = {
				desc = learning_theology_special.1102.b.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -2
				}
				add_learning_lifestyle_xp = minor_lifestyle_xp
				add_prestige = medium_prestige_loss
			}
		}
		ai_chance = {
			base = 25
			modifier = {
				factor = 2.5
				OR = {
					has_trait = ambitious
					has_trait = arrogant
				}
			}
		}
	}

	option = { #Cop-out if the scholar has died
		name = learning_theology_special.1102.d
		trigger = {
			scope:scholar = {
				is_alive = no
			}
		}
		add_learning_lifestyle_xp = minor_lifestyle_xp
		ai_chance = {
			base = 200
		}
	}

	after = {
		remove_character_flag = is_in_learning_special_event
	}
}

