namespace = false_conversion

##################################################
#False Conversion CB events

	#0001-0003	- Flag characters & counties that might be falsely converted.
	#0020		- Revoke false conversion decision events.
	#0030-0031	- Encourage false conversion admittance decision events.

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

##################################################
# General Maintenance
# by Ewan Cowhig Croft
# 0001-0002
##################################################

#	Flag characters that might be falsely converted.
#		by Ewan Cowhig Croft
# false_conversion.0001 = {
# 	hidden = yes

# 	trigger = {
# 		scope:old_faith = { has_doctrine_parameter = sanctioned_false_conversion }
# 		NOR = {
# 			any_secret = { type = secret_crypto_religionist }
# 			has_variable = forbid_crypto_reconversion
# 		}
# 	}

# 	immediate = {
# 		set_variable = {
# 			name = false_convert
# 			value = scope:old_faith
# 		}
# 	}
# }

#	Flag counties that might be falsely converted.
#		by Ewan Cowhig Croft
false_conversion.0002 = {
	hidden = yes
	scope = landed_title

	trigger = {
		scope:old_faith = { has_doctrine_parameter = sanctioned_false_conversion }
		NOR = {
			has_variable = false_convert
			has_variable = forbid_crypto_reconversion
		}
	}

	immediate = {
		make_county_crypto_religionists_effect = { FAITH = scope:old_faith }
	}
}

#	Cleanup counties that have been reconverting.
#		by Ewan Cowhig Croft
false_conversion.0003 = {
	hidden = yes
	scope = landed_title

	trigger = {
		has_county_modifier = relieved_cryptos_modifier
	}

	immediate = {
		remove_county_modifier = relieved_cryptos_modifier
	}
}

##################################################
# Revoke False Conversion Decision Events
# by Ewan Cowhig Croft
# 0020-0021
##################################################

#	Crypto-Faithism
#		by Ewan Cowhig Croft
false_conversion.0020 = {
	type = character_event
	title = false_conversion.0020.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { has_government = landless_adventurer_government }
				desc = false_conversion.0020.desc_landless
			}
			desc = false_conversion.0020.desc
		}
	}
	theme = faith
	left_portrait =	root
	weight_multiplier = {
		base = 1
	}
	immediate = {
		secret_faith = { save_scope_as = old_faith }	# For loc.
		faith = { save_scope_as = current_faith }		# For loc.
	}
	# You return to your original faith. Huzzah for secret cults!
	option = {	
		name = false_conversion.0020.a
		trigger = { is_landed_or_landless_administrative = yes }
		set_character_faith_with_conversion = secret_faith
		remove_character_secret_faith = yes
		if = {	#If independent, also grab any counties in your realm that still have crypto-religious communities.
			limit = {
				top_liege = this
				any_sub_realm_county = {
					has_variable = false_convert
					var:false_convert = root.faith
					faith != root.faith	#Discount them if they've already been switched by the conversion action.
				}
			}
			set_variable = {	#Log how many counties switch.
				name = num_false_converts_counties
				value = 0
			}
			every_sub_realm_county = {
				limit = {
					has_variable = false_convert
					var:false_convert = root.faith
					faith != root.faith	#Discount them if they've already been switched by the conversion action.
				}
				set_county_faith = var:false_convert	#Everyone likes practicing their faith in the open!
				remove_county_modifier = false_convert_modifier
				add_county_modifier = {
					modifier = relieved_cryptos_modifier
					years = 25
				}
				root = {	#Adjust logging for each valid county.
					change_variable = {
						name = num_false_converts_counties
						add = 1
					}
				}
				remove_variable = false_convert	#Cleanup the variable when we're done.
			}
			send_interface_message = {	#Alert the user if any counties have switched.
				type = event_religious_neutral_text
				title = event_false_converts.t
				desc = event_false_converts_counties_only.desc
			}
		}
		# Deduct piety, but only if faith doesn't sanction false conversions
		if = {
			limit = {
				faith = {
					NOT = { has_doctrine_parameter = sanctioned_false_conversion }
				}
			}
			add_piety = major_piety_loss
		}
		if = {
			limit = { top_liege != this }
			liege = {
				send_interface_message = {
					type = event_religious_neutral_text
					title = event_false_convert_my_vassal.t
					desc = event_false_convert_interface.desc
					right_icon = root
				}
			}
		}
		every_vassal = {
			send_interface_message = {
				type = event_religious_neutral_text
				title = event_false_convert_my_liege.t
				desc = event_false_convert_interface.desc
				right_icon = root
			}
		}
#		# Fp3 Struggle Catalyst
#		if = {
#			limit = {
#				highest_held_title_tier >= tier_county
#				faith.religion = religion:islam_religion
#				any_character_struggle = {
#					involvement = involved
#					phase_has_catalyst = catalyst_revealed_secret_faith_islam
#				}
#			}
#			every_character_struggle = {
#				involvement = involved
#				limit = {
#					phase_has_catalyst = catalyst_revealed_secret_faith_islam
#				}
#				activate_struggle_catalyst = {
#					catalyst = catalyst_revealed_secret_faith_islam
#					character = root
#				}
#			}
#		}
#		else_if = {
#			limit = {
#				highest_held_title_tier >= tier_county
#				NOT = { faith.religion = religion:islam_religion }
#				any_character_struggle = {
#					involvement = involved
#					phase_has_catalyst = catalyst_revealed_secret_faith_non_islam
#				}
#			}
#			every_character_struggle = {
#				involvement = involved
#				limit = {
#					phase_has_catalyst = catalyst_revealed_secret_faith_non_islam
#				}
#				activate_struggle_catalyst = {
#					catalyst = catalyst_revealed_secret_faith_non_islam
#					character = root
#				}
#			}
#		}

		stress_impact = {
			zealous = medium_stress_impact_gain	#Damn it, I was passionate about my openly-practiced faith!
			cynical	= medium_stress_impact_gain	#Damn it, they're all basically the same! Probably!
		}
		ai_chance = {
			base = 60
			ai_value_modifier = {
				ai_zeal = 0.5
				ai_boldness = 0.25
			}
			modifier = {
				has_trait = zealous	#Must not stress self.
				factor = 0
			}
			modifier = {
				has_trait = cynical	#Must. Not. Stress. Self
				factor = 0
			}
		}
	}
	#Landless convertee
	option = {
		name = false_conversion.0020.c
		trigger = { has_government = landless_adventurer_government }
		set_character_faith_with_conversion = secret_faith
		remove_character_secret_faith = yes
		# Deduct piety, but only if faith doesn't sanction false conversions
		if = {
			limit = {
				faith = {
					NOT = { has_doctrine_parameter = sanctioned_false_conversion }
				}
			}
			add_piety = major_piety_loss
		}
		stress_impact = {
			zealous = medium_stress_impact_gain	#Damn it, I was passionate about my openly-practiced faith!
			cynical	= medium_stress_impact_gain	#Damn it, they're all basically the same! Probably!
		}
		ai_chance = {
			base = 60
			ai_value_modifier = {
				ai_zeal = 0.5
				ai_boldness = 0.25
			}
			modifier = {
				has_trait = zealous	#Must not stress self.
				factor = 0
			}
			modifier = {
				has_trait = cynical	#Must. Not. Stress. Self
				factor = 0
			}
		}
	}
	# On seconds thoughts...
	option = {	
		name = false_conversion.0020.b

		if = { # Return cost when backing out
			limit = { scope:decision_piety_cost > 0 }
			add_piety = scope:decision_piety_cost
		}

		ai_chance = {
			base = 40
			ai_value_modifier = {
				ai_zeal = -0.25
				ai_boldness = -0.25
			}
			modifier = {
				add = 20
				has_trait = lazy #Efffforrrtttt.
			}
		}
	}
}

##################################################
# Encourage False Conversion Admittance Decision Events
# by Ewan Cowhig Croft
# 0030-0031
##################################################

#	You encourage crypto-religionists in your realm to return to openly practicing their faiths.
#		by Ewan Cowhig Croft
false_conversion.0030 = {
	type = character_event
	title = false_conversion.0030.t
	desc = {
		desc = false_conversion.0030.desc_start
		first_valid = {
			triggered_desc = {
				trigger = {
					has_variable = false_convert
				}
				desc = false_conversion.0030.desc_has_secret_faith
			}
			triggered_desc = {
				trigger = {
					faith = {
						has_doctrine = doctrine_pluralism_pluralistic
					}
				}
				desc = false_conversion.0030.desc_no_secret_faith
			}
			desc = false_conversion.0030.desc_no_secret_faith_not_pluralist
		}
		desc = false_conversion.0030.desc_end
	}
	
	theme = faith
	left_portrait =	root

	weight_multiplier = {
		base = 1
	}

	immediate = {
		if = {
			limit = {
				exists = secret_faith
			}
			secret_faith = { save_scope_as = old_faith } # For loc.
		}
		set_variable = {	#Initialise counting for the number of landed converts.
			name = num_false_converts_vassal
			value = 0
		}
		set_variable = {	#Initialise counting for the number of landless converts.
			name = num_false_converts_landless
			value = 0
		}
		set_variable = {	#Log how many counties switch.
			name = num_false_converts_counties
			value = 0
		}
		if = {	#If pluralistic, look at any hidden faiths.
			limit = {
				faith = { has_doctrine = doctrine_pluralism_pluralistic }
			}
			every_vassal = {
				limit = {	#Providing they are equal-to-or-less in hostility.
					is_ai = yes
					exists = secret_faith
					NOR = {	#And not super-committed to their public religion.
						has_trait = zealous
						this = faith.religious_head
					}
					save_temporary_scope_as = current_character
					root.faith = {	#Public conversion must be advantageous, or at least not harmful.
						faith_hostility_level_comparison = {
							scope:current_character.secret_faith <= scope:current_character.faith
						}
					}
					OR = {	#The vassals should either be trusting, or else have an iron-clad reason to believe the amnesty.
						NOR = {
							has_trait = deceitful
							has_trait = paranoid
						}
						secret_faith = root.faith
					}
				}
				add_to_list = converting_vassals_list
				root = {
					change_variable = {
						name = num_false_converts_vassal
						add = 1
					}
				}
			}
			every_courtier_or_guest = {	#Grab courtiers and such too.
				limit = {
					is_ai = yes
					exists = secret_faith
					NOT = { has_trait = zealous }
					save_temporary_scope_as = current_character
					root.faith = {
						faith_hostility_level_comparison = {
							secret_faith <= scope:current_character.faith
						}
					}
					OR = {
						NOR = {
							has_trait = deceitful
							has_trait = paranoid
						}
						secret_faith = root.faith
					}
				}
				add_to_list = converting_landless_list
				root = {
					change_variable = {
						name = num_false_converts_landless
						add = 1
					}
				}
			}
			if = {	#If independent, also grab any counties in your realm that still have crypto-religious communities.
				limit = {
					top_liege = this
					any_sub_realm_county = {
						has_variable = false_convert
					}
				}
				every_sub_realm_county = {
					limit = {
						has_variable = false_convert
						save_temporary_scope_as = current_county
						root.faith = {
							faith_hostility_level_comparison = {
								scope:current_county.var:false_convert <= scope:current_county.faith
							}
						}
					}
					add_to_list = converting_counties_list
					root = {	#Adjust logging for each valid county.
						change_variable = {
							name = num_false_converts_counties
							add = 1
						}
					}
				}
			}
		}
		else = {	#Otherwise, only check for within your own faith. Crypto-religionists don't want to come out of hiding for just anybody.
			every_vassal = {
				if = {
					limit = {
						any_secret = { type = secret_crypto_religionist }
					}
					random_secret = {
						type = secret_crypto_religionist
						save_scope_as = convert_crypto_secret
					}
				}
				limit = {
					is_ai = yes
					exists = secret_faith
					NOR = {
						has_trait = zealous
						this = faith.religious_head
					}
					secret_faith = root.faith
				}
				add_to_list = converting_vassals_list
				root = {
					change_variable = {
						name = num_false_converts_vassal
						add = 1
					}
				}
			}
			every_courtier_or_guest = {	#And any courtiers or hangers-on.
				if = {
					limit = {
						any_secret = { type = secret_crypto_religionist }
					}
					random_secret = {
						type = secret_crypto_religionist
						save_scope_as = convert_crypto_secret
					}
				}
				limit = {
					is_ai = yes
					exists =secret_faith
					NOT = { has_trait = zealous }
					secret_faith = root.faith
				}
				add_to_list = converting_landless_list
				root = {
					change_variable = {
						name = num_false_converts_landless
						add = 1
					}
				}
			}
			every_sub_realm_county = {
				limit = {
					has_variable = false_convert
					var:false_convert = root.faith
					faith != root.faith	#Discount them if they've already been switched by the conversion action.
				}
				set_county_faith = var:false_convert
				remove_county_modifier = false_convert_modifier
				add_county_modifier = {
					modifier = relieved_cryptos_modifier
					years = 25
				}
				root = {	#Adjust logging for each valid county.
					change_variable = {
						name = num_false_converts_counties
						add = 1
					}
				}
				remove_variable = false_convert	#Cleanup the variable when we're done.
			}
		}
	}

	option = {	#Tell everyone to just be honest about their faith.
		name = false_conversion.0030.a
		custom_tooltip = false_conversion.0030.a.tt
		hidden_effect = {
			every_in_list = {	#Convert the vassals.
				list = converting_vassals_list
				set_character_faith_with_conversion = secret_faith
				remove_character_secret_faith = yes
				save_temporary_scope_as = reconverter
				every_vassal = {	#Notify your vassals' vassals of the change.
					send_interface_message = {
						type = event_religious_neutral_text
						title = event_false_convert_my_vassal.t
						desc = event_false_convert_interface.desc
						right_icon = scope:reconverter
					}
				}
				add_opinion = {	#Huzzah! I can go to church!
					modifier = religious_freedom_opinion
					target = root
				}
			}
			every_in_list = {	#And the dregs.
				list = converting_landless_list
				set_character_faith_with_conversion = secret_faith
				remove_character_secret_faith = yes
				add_opinion = {	#Huzzah! I can go to church! Shame I don't own any!
					modifier = religious_freedom_opinion
					target = root
				}
			}
			if = {	#If independent, also grab any counties in your realm that still have crypto-religious communities.
				limit = { top_liege = this }
				every_in_list = {
					list = converting_counties_list
					set_county_faith = var:false_convert
					add_county_modifier = {	#Everyone likes practicing their faith in the open!
						modifier = relieved_cryptos_modifier
						years = 25
					}
					remove_variable = false_convert	#Cleanup the variable when we're done.
				}
			}
			if = {	#Include counties in the message if there are any.
				limit = { var:num_false_converts_counties >= 1 }
				send_interface_message = {
					type = event_religious_neutral_text
					title = event_false_converts.t
					desc = event_false_converts_plus_counties.desc
				}
			}
			if = {	#Else, just talk about vassals and landless characters.
				limit = { var:num_false_converts_counties <= 0 }
				send_interface_message = {
					type = event_religious_neutral_text
					title = event_false_converts.t
					desc = event_false_converts_without_counties.desc
				}
			}
			if = {	#Under pluralist lieges, tell suitable players that their liege is offering amnesty.
				limit = {
					faith = { has_doctrine = doctrine_pluralism_pluralistic }
				}
				every_vassal = {
					limit = {
						is_ai = no
						any_secret = { type = secret_crypto_religionist }
					}
					trigger_event = false_conversion.0031
				}
			}
			else = {	#Under non-pluralist lieges, tell suitable players that their liege is offering amnesty.
				every_vassal = {
					limit = {
						is_ai = no
						secret_faith ?= root.faith
					}
					trigger_event = false_conversion.0031
				}
			}
		}
		# Piety loss, but not if has false conversion sanction tenet
		if = {
			limit = {
				faith = {
					NOT = { has_doctrine = tenet_false_conversion_sanction }
				}
			}
			add_piety = major_piety_loss
		}
		stress_impact = {
			honest = minor_stress_impact_loss
			trusting = minor_stress_impact_loss
		}
		ai_chance = {
			base = 40
			ai_value_modifier = {
				ai_compassion = 0.5	#Everyone should be open with each other.
			}
			modifier = {
				add = 20
				has_trait = honest	#Honesty is the best policy.
			}
			modifier = {
				add = 20
				has_trait = trusting	#Trust people to trust your word.
			}
		}
	}
	option = {	#Let's let sleeping sectarian conflicts lie.
		name = {
			text = false_conversion.0030.b_no_secret_faith
			trigger = {
				NOT = {
					any_secret = { type = secret_crypto_religionist }
				 }
			}
		}
		name = {
			text = false_conversion.0030.b_has_secret_faith
			trigger = {
				any_secret = { type = secret_crypto_religionist }
			}
		}
		ai_chance = {
			base = 60
			ai_value_modifier = {
				ai_boldness = -0.25
			}
		}
	}

}

#	Your liege is trying to promulgate freedom of worship.
#		by Ewan Cowhig Croft
false_conversion.0031 = {
	type = character_event
	title = false_conversion.0031.t
	desc = false_conversion.0031.desc
	
	theme = faith
	override_background = {
		reference = temple_scope
	}
	left_portrait =	root.liege

	weight_multiplier = {
		base = 1
	}

	immediate = {
		root.liege = {
			save_scope_as = background_temple_scope
		}
		secret_faith = { save_scope_as = old_faith }
	}

	option = {	#I hop on board the faith-train to Conversion City.
		name = false_conversion.0031.a
		set_character_faith_with_conversion = scope:old_faith
		liege = {
			send_interface_message = {
				type = event_religious_neutral_text
				title = event_false_convert_my_vassal.t
				desc = event_false_convert_interface.desc
				right_icon = root
			}
		}
		every_vassal = {
			send_interface_message = {
				type = event_religious_neutral_text
				title = event_false_convert_my_vassal.t
				desc = event_false_convert_interface.desc
				right_icon = root
			}
		}
		add_opinion = {	#Huzzah! I can go to church!
			modifier = religious_freedom_opinion
			target = root
		}
		stress_impact = {
			zealous = medium_stress_impact_gain
			cynical = medium_stress_impact_gain
			deceitful = medium_stress_impact_gain
			honest = medium_stress_impact_loss
			trusting = medium_stress_impact_loss

		}
		ai_chance = {
			base = 0	#Player-only event.
		}
	}
	option = {	#I know how this goes: I'll keep my private faith private.
		name = false_conversion.0031.b
		stress_impact = {
			honest = medium_stress_impact_gain
			trusting = medium_stress_impact_gain
			deceitful = medium_stress_impact_loss
		}
		ai_chance = {
			base = 100	#Player-only event.
		}
	}
}

###########################################################################
# Conversion request events
# Decide to refuse the request, agree, or agree and keep a secret religion
###########################################################################

# Decide what type of false conversion event to fire
false_conversion.0900 = {
	hidden = yes

	immediate = {
		grab_spouses_and_family_to_convert_effect = yes
		# If the recipient already has a crypto religion, then just convert them and the family without any fuss
		if = {
			limit = {
				any_secret = { type = secret_crypto_religionist }
			}
			convert_family_to_faith_effect = {
				FALSE_CONVERSION = no
				FORCED = yes
			}
		}
		# Otherwise give them a choice
		else = {
			if = {
				limit = {
					is_married = yes
					is_imprisoned = no
					primary_spouse = {
						is_imprisoned = no
						is_ai = yes
					}
					# Spouse cannot suggest to keep a faith they weren't following as a secret faith
					primary_spouse.faith = root.faith
				}
				trigger_event = false_conversion.1010
			}
			else = {
				trigger_event = false_conversion.1000
			}
		}
	}
}


# Default conversion event for if you have no spouse or are imprisoned
false_conversion.1000 = {
	type = character_event
	title = false_conversion.1000.t
	desc = {
		desc = false_conversion.1000.desc_intro
		triggered_desc = {
			trigger = {
				any_in_list = {
					list = spouses_and_family_to_convert
					count > 1
				}
			}
			desc = false_conversion.1000.desc_has_family
		}
		desc = false_conversion.1000.desc_convert
		first_valid = {
			# If a hook is being used, then lament this blackmail
			triggered_desc = {
				trigger = { exists = scope:forcibly_converted }
				desc = false_conversion.1000.desc_forced
			}
			desc = false_conversion.1000.desc_voluntary
		}
		first_valid = {
			triggered_desc = {
				trigger = { ai_boldness > low_positive_ai_value }
				desc = false_conversion.1000.desc_forced
			}
			desc = false_conversion.1000.desc_cowardly
		}
		desc = false_conversion.1000.desc_outro
	}
	override_background = {
		trigger = { scope:recipient = { is_imprisoned = yes } }
		reference = dungeon
	}
	theme = faith
	left_portrait = root

	option = { # Accept conversion
		name = false_conversion.1000.a
		convert_family_to_faith_effect = {
			FALSE_CONVERSION = no
			FORCED = yes
		}
		ai_chance = {
			base = 25
		}
	}

	option = { # Keep old faith as a secret
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = {
							faith = { has_doctrine_parameter = sanctioned_false_conversion }
							any_in_list = {
								list = spouses_and_family_to_convert
								count > 1
							}
						}
						desc = false_conversion.1000.b_sanctioned_plural
					}
					triggered_desc = {
						trigger = {
							faith = { has_doctrine_parameter = sanctioned_false_conversion }
						}
						desc = false_conversion.1000.b_sanctioned_single
					}
					triggered_desc = {
						trigger = {
							any_in_list = {
								list = spouses_and_family_to_convert
								faith = root.faith
								count > 1
							}
						}
						desc = false_conversion.1000.b_plural
					}
					desc = false_conversion.1000.b_single
				}
			}
		}
		trigger = {
			#faith = { has_doctrine_parameter = sanctioned_false_conversion }
			# Don't override old secret faiths
			NOR = {
				any_secret = { type = secret_crypto_religionist }
				has_variable = forbid_crypto_reconversion
			}
		}
		convert_family_to_faith_effect = {
			FALSE_CONVERSION = yes
			FORCED = yes
		}
		ai_chance = {
			base = 0
			religion_adopt_secret_faith_modifier = {
				TARGET = root
				FORCED = yes
				FAITH = root.faith
			}
		}
	}
}

# If your whole family is being asked to convert, consult with spouse
false_conversion.1010 = {
	type = character_event
	title = false_conversion.1000.t
	desc = {
		desc = false_conversion.1000.desc_intro
		first_valid = {
			triggered_desc = {
				trigger = {
					any_in_list = {
						list = spouses_and_family_to_convert
						count > 2
					}
				}
				desc = false_conversion.1000.desc_has_family
			}
			desc = false_conversion.1010.desc_has_no_family
		}
		desc = false_conversion.1000.desc_convert
		desc = false_conversion.1010.desc_spouse_intro
		# Spouse's reaction:
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:spouse_wants_secret_faith }
				desc = false_conversion.1010.desc_spouse_advises_secrecy
			}
			triggered_desc = {
				trigger = {
					exists = scope:spouse_wants_to_convert
					scope:spouse = { has_trait = cynical }
				}
				desc = false_conversion.1010.desc_spouse_advises_conversion_cynical
			}
			triggered_desc = {
				trigger = { exists = scope:spouse_wants_to_convert }
				desc = false_conversion.1010.desc_spouse_advises_conversion_neutral
			}
		}
		desc = false_conversion.1010.desc_outro_demure
		triggered_desc = {
			trigger = {
				opinion = {
					target = scope:spouse
					value >= 10
				}	
			}
			desc = false_conversion.1010.desc_spouse_liked
		}
		triggered_desc = {
			trigger = {
				opinion = {
					target = scope:spouse
					value <= -40
				}	
			}
			desc = false_conversion.1010.desc_spouse_disliked
		}
		desc = false_conversion.1010.desc_outro_wife_husband
	}
	theme = faith
	left_portrait = root
	right_portrait = primary_spouse

	immediate = {
		primary_spouse = {
			save_scope_as = spouse
		}
		# Determine whether spouse wants to convert
		random_list = {
			100 = {
				save_scope_value_as = {
					name = spouse_wants_to_convert
					value = yes
				}
			}
			0 = {
				religion_adopt_secret_faith_modifier = {
					TARGET = root
					FORCED = yes
					FAITH = root.faith
				}
				save_scope_value_as = {
					name = spouse_wants_secret_faith
					value = yes
				}
			}
		}
	}

	option = { # Accept conversion
		name = false_conversion.1000.a
		convert_family_to_faith_effect = {
			FALSE_CONVERSION = no
			FORCED = yes
		}
		if = {
			limit = { exists = scope:spouse_wants_to_convert }
			reverse_add_opinion = {
				target = primary_spouse
				modifier = pleased_opinion
				opinion = 20
			}
		}
		else = {
			reverse_add_opinion = {
				target = primary_spouse
				modifier = disappointed_opinion
				opinion = -20
			}
		}
		ai_chance = {
			base = 25
		}
	}

	option = { # Keep old faith as a secret
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = {
							faith = { has_doctrine_parameter = sanctioned_false_conversion }
						}
						desc = false_conversion.1000.b_sanctioned_plural
					}
					desc = false_conversion.1000.b_plural
				}
			}
		}
		convert_family_to_faith_effect = {
			FALSE_CONVERSION = yes
			FORCED = yes
		}
		if = {
			limit = { exists = scope:spouse_wants_secret_faith }
			reverse_add_opinion = {
				target = primary_spouse
				modifier = pleased_opinion
				opinion = 20
			}
		}
		else = {
			reverse_add_opinion = {
				target = primary_spouse
				modifier = disappointed_opinion
				opinion = -20
			}
		}
		ai_chance = {
			base = 0
			religion_adopt_secret_faith_modifier = {
				TARGET = root
				FORCED = yes
				FAITH = root.faith
			}
		}
	}
}

# Secret-Faith Yearlies
# =====================
## A Moment of Weakness
## Someone close to you is in pain, attempt to convert them to your crypto-religion as a coping method?
scripted_trigger false_conversion_2000_is_vulnerable_trigger = {
	NOT = { exists = secret_faith }
	age >= 12 # For narrative purposes
	is_available = yes
	OR = {
		stress_level >= 1
		AND = {
			has_character_modifier = stress_frozen_grief
			# We need memories in order to grab who died that we're sad about
			any_memory = {
				OR = {
					has_memory_type = friend_died
					has_memory_type = best_friend_died
					has_memory_type = lover_died
					has_memory_type = soulmate_died
					has_memory_type = relative_died
					has_memory_type = spouse_died
					has_memory_type = dog_died
				}
			}
		}
		has_trait = depressed_1
	}
}

# Converts a target and ameliorates their grief/stress/depression
scripted_effect false_conversion_2000_convert = {
	# Buff relation
	if = {
		limit = { scope:crypto_opportunist = { has_character_flag = false_conversion_2000_grief } }
		scope:vulnerable_relation = { remove_character_modifier = stress_frozen_grief }
		scope:crypto_opportunist = { remove_character_flag  = false_conversion_2000_grief }
	}
	else_if = {
		limit = { scope:crypto_opportunist = { has_character_flag = false_conversion_2000_depression } }
		scope:vulnerable_relation = { add_character_modifier = fp3_higher_purpose_modifier }
	}
	else_if = {
		limit = { scope:crypto_opportunist = { has_character_flag = false_conversion_2000_stress } }
		scope:vulnerable_relation = { add_stress = major_stress_impact_loss }
	}
	send_interface_toast = {
		title = false_conversion.2000.a_success
		left_icon = scope:vulnerable_relation
		scope:crypto_opportunist = {
			random_secret = {
				type = secret_crypto_religionist
				# This is necessary for spread_crypto_religion_to_target_effect
				save_scope_as = owner_crypto_secret
			}
			spread_crypto_religion_to_target_effect = { TARGET = scope:vulnerable_relation }
		}
	}
}

## A Moment of Weakness
## Take advantage of your target's grief to push your religion
false_conversion.2000 = {
	type = character_event
	title = false_conversion.2000.t
	desc = {
		desc = false_conversion.2000.desc_intro
		first_valid = {
			triggered_desc = {
				trigger = { has_character_flag = false_conversion_2000_grief }
				desc = false_conversion.2000.desc_descriptor_grief
			}
			triggered_desc = {
				trigger = { has_character_flag = false_conversion_2000_depression }
				desc = false_conversion.2000.desc_descriptor_depression
			}
			triggered_desc = {
				trigger = { has_character_flag = false_conversion_2000_stress }
				desc = false_conversion.2000.desc_descriptor_stress
			}
		}
		desc = false_conversion.2000.desc_bridge
		first_valid = {
			triggered_desc = {
				trigger = { has_character_flag = false_conversion_2000_grief }
				desc = false_conversion.2000.desc_quote_grief
			}
			triggered_desc = {
				trigger = { has_character_flag = false_conversion_2000_depression }
				desc = false_conversion.2000.desc_quote_depression
			}
			triggered_desc = {
				trigger = { has_character_flag = false_conversion_2000_stress }
				desc = false_conversion.2000.desc_quote_stress
			}
		}
		desc = false_conversion.2000.desc_outro
	}
	left_portrait = {
		character = scope:vulnerable_relation
		animation = grief
	}
	theme = faith
	override_background = { reference = corridor_night }
	cooldown = { years = 1 }

	# Only target the vulnerable
	trigger = {
		# Runs through most characters covered by get_characters_of_interest_effect
		# Yup, it's necessary to do it like this. Sorry.
		exists = secret_faith
		OR = {
			any_close_or_extended_family_member = { false_conversion_2000_is_vulnerable_trigger = yes }
			any_powerful_vassal = { false_conversion_2000_is_vulnerable_trigger = yes }
			any_consort = { false_conversion_2000_is_vulnerable_trigger = yes }
			any_concubine = { false_conversion_2000_is_vulnerable_trigger = yes }
			any_normal_councillor = { false_conversion_2000_is_vulnerable_trigger = yes }
			any_ally = { false_conversion_2000_is_vulnerable_trigger = yes }
			betrothed ?= { false_conversion_2000_is_vulnerable_trigger = yes }
			# I hate my life
			trigger_if = {
				limit = {
					exists = liege
					is_powerful_vassal = yes
				}
				liege = { false_conversion_2000_is_vulnerable_trigger = yes }
			}

			trigger_if = {
				limit = { is_ai = no }
				OR = {
					any_relation = {
						type = lover
						false_conversion_2000_is_vulnerable_trigger = yes
					}
					any_relation = {
						type = ward
						false_conversion_2000_is_vulnerable_trigger = yes
					}
					any_relation = {
						type = friend
						false_conversion_2000_is_vulnerable_trigger = yes
					}
					# Skipping courtiers because minor_interest_skilled_courtiers_trigger requires a list as input
					trigger_if = {
						limit = {
							age >= 12
						}
						any_relation = {
							type = guardian
							false_conversion_2000_is_vulnerable_trigger = yes
						}
					}
				}
			}
			any_knight = { false_conversion_2000_is_vulnerable_trigger = yes }
		}
	}

	immediate = {
		save_scope_as = crypto_opportunist
		save_scope_as = owner # For spread_crypto_religion_to_target_effect
		get_characters_of_interest_effect = { LISTNAME = vulnerable_relations }
		# Prioritize characters of high interest before those of low interest
		random_in_list = {
			list = vulnerable_relations
			limit = {
				is_of_major_interest_to_root_trigger = yes
				false_conversion_2000_is_vulnerable_trigger = yes
			}
			save_scope_as = vulnerable_relation
		}
		# If we weren't able to find anyone of major interest, then any ol' minor relation will do
		if = {
			limit = { NOT = { exists = scope:vulnerable_relation } }
			random_in_list = {
				list = vulnerable_relations
				limit = { false_conversion_2000_is_vulnerable_trigger = yes }
				save_scope_as = vulnerable_relation
			}
		}
		# Also for the effect
		scope:vulnerable_relation = { save_scope_as = target }
		# Determine which weakness we will capitalize on
		# Rarer conditions first for more visibility
		if = {
			limit = {
				scope:vulnerable_relation = {
					AND = {
						has_character_modifier = stress_frozen_grief
						OR = {
							has_memory_type = friend_died
							has_memory_type = best_friend_died
							has_memory_type = lover_died
							has_memory_type = soulmate_died
							has_memory_type = relative_died
							has_memory_type = spouse_died
							has_memory_type = dog_died
						}
					}
				}
			}
			add_character_flag = {
				flag = false_conversion_2000_grief
			}
			# Grab the most recent person who died that the relation remembers.  Hopefully they actually care about them.
			ordered_memory = {
				limit = {
					OR = {
						has_memory_type = friend_died
						has_memory_type = best_friend_died
						has_memory_type = lover_died
						has_memory_type = soulmate_died
						has_memory_type = relative_died
						has_memory_type = spouse_died
						has_memory_type = dog_died
					}
				}
				order_by = memory_creation_date
				random_memory_participant = {
					limit = { this != root }
					save_scope_as = deceased_character
				}
			}
		}
		else_if = {
			limit = { scope:vulnerable_relation = { has_trait = depressed_1 } }
			add_character_flag = {
				flag = false_conversion_2000_depression
				days = 1
			}
		}
		else = {
			add_character_flag = {
				flag = false_conversion_2000_stress
				days = 1
			}
		}
	}

	option = { # Glory to Ohrmazd
		name = false_conversion.2000.a
		if = {
			# If relation is a player, then let them decide whether to accept the your secret faith
			limit = { scope:vulnerable_relation = { is_ai = no } }
			scope:vulnerable_relation = { trigger_event = false_conversion.2001 }
			custom_tooltip = false_conversion.2000.a_flavor
		}
		else = {
			duel = {
				skill = learning
				target = scope:vulnerable_relation
				50 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = 2.5
					}
					desc = false_conversion.2000.a_success
					opinion_modifier = {
						who = scope:vulnerable_relation
						opinion_target = scope:crypto_opportunist
						multiplier = 0.1
					}
					# Convert the relation and take away (some of) their pain
					false_conversion_2000_convert = yes
				}
				50 = { # Relation declines
					desc = false_conversion.2000.a_failure
					compare_modifier = {
						value = scope:duel_value
						multiplier = -2.5
					}
					opinion_modifier = {
						who = scope:vulnerable_relation
						opinion_target = scope:crypto_opportunist
						multiplier = -0.1
					}
					send_interface_toast = {
						title = false_conversion.2000.a_failure
						left_icon = scope:vulnerable_relation
						reverse_add_opinion = {
							target = scope:vulnerable_relation
							modifier = fp2_questioned_my_faith_opinion
						}
					}
				}
			}
		}
		stress_impact = {
			honest = minor_stress_impact_gain
		}

		ai_chance = {
		 	base = 10
		 	ai_value_modifier = {
		 		ai_boldness = 0.1
				ai_compassion = -0.2
				ai_honor = -0.1
				ai_rationality = 0.1
				ai_sociability = -0.1
				ai_zeal = 0.2
			}
		}
	}

	option = { # Just comfort them instead
		name = false_conversion.2000.b
		reverse_add_opinion = {
			target = scope:vulnerable_relation
			modifier = comforted_opinion
		}
		stress_impact = {
			compassionate = minor_stress_impact_loss
		}

		ai_chance = {
		 	base = 10
		 	ai_value_modifier = {
		 		ai_boldness = -0.1
				ai_compassion = 0.2
				ai_honor = 0.1
				ai_rationality = -0.1
				ai_sociability = 0.1
				ai_zeal = -0.2
			}
		}
	}
}

## My Time of Need
## Convert to someone's crypto-faith and ameliorate your grief/stress/depression
false_conversion.2001 = {
	type = character_event
	title = false_conversion.2001.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:crypto_opportunist = { has_character_flag = false_conversion_2000_grief } }
				desc = false_conversion.2001.desc_grief
			}
			triggered_desc = {
				trigger = { scope:crypto_opportunist = { has_character_flag = false_conversion_2000_depression } }
				desc = false_conversion.2001.desc_depression
			}
			triggered_desc = {
				trigger = { scope:crypto_opportunist = { has_character_flag = false_conversion_2000_stress } }
				desc = false_conversion.2001.desc_stress
			}
		}
		desc = false_conversion.2001.desc_outro
	}
	theme = faith
	override_background = { reference = corridor_night }
	left_portrait = scope:crypto_opportunist

	option = { # Convert
		name = false_conversion.2001.a
		false_conversion_2000_convert = yes
		stress_impact = {
			honest = major_stress_impact_gain
			craven = medium_stress_impact_gain
			paranoid = medium_stress_impact_gain
		}
		# No AI chance as AI should never encounter this event
	}

	option = { # Refuse
		name = false_conversion.2001.b
		flavor = false_conversion.2001.b_flavor
	}
}

# Bonus event: Avoid a holy war by converting to the aggressor's religion
# TO-DO

# Your secret religion has been exposed, do you openly convert to it or abandon it?
false_conversion.8000 = {
	type = character_event
	title = false_conversion.8000.t
	desc = {
		desc = false_conversion.8000.desc_intro
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:disapproving_chaplain }
				desc = false_conversion.8000.desc_disapproving_chaplain
			}
			triggered_desc = {
				trigger = { exists = scope:silent_chaplain }
				desc = false_conversion.8000.desc_silent_chaplain
			}
		}
		desc = false_conversion.8000.desc_outro
	}
	theme = secret
	left_portrait = root
	right_portrait = scope:secret_exposer

	trigger = {
		root != scope:secret_exposer
	}

	immediate = {
		save_scope_as = owner
		# Have the realm priest chastise you unless they also practice the same secret religion
		if = {
			limit = {
				exists = cp:councillor_court_chaplain
				cp:councillor_court_chaplain = {
					secret_faith ?= root.secret_faith
				}
			}
			cp:councillor_court_chaplain = { save_scope_as = silent_chaplain }
		}
		else_if = {
			limit = {
				exists = cp:councillor_court_chaplain
			}
			cp:councillor_court_chaplain = { save_scope_as = disapproving_chaplain }
		}
		secret_exposed_owner_effects_effect = { SECRET = scope:secret POV = root }
		secret_exposed_owner_opinion_effects_effect = yes
		play_music_cue = "mx_cue_secret"
	}

	option = { # Abandon secret faith
		name = false_conversion.8000.a
		add_piety = medium_piety_loss
		add_piety_level = -1

		stress_impact = {
			zealous = major_stress_impact_gain
			content = minor_stress_impact_loss
			arbitrary = minor_stress_impact_loss
		}
		ai_chance = {
			base = 5
		}
	}

	option = { # Convert back to secret faith
		name = false_conversion.8000.b
		set_character_faith_with_conversion = secret_faith
		remove_character_secret_faith = yes
		
		stress_impact = {
			cynical = minor_stress_impact_gain
			zealous = medium_stress_impact_loss
			honest = minor_stress_impact_loss
		}
		ai_chance = {
			base = 5
		}
	}
}
