################
# WITCH EVENTS #
################

namespace = witch

#witch.1001-1999 - Guardian coverts ward
#witch.2001-2899 - Convert to witchcraft scheme
#witch.2900-2999 - Reveal as witch interaction
#witch.3001-3999 - Witch ritual activity events
#witch.4001-4999 - Witch ongoing events
#

##########################
# GUARDIAN CONVERTS WARD #
##########################

witch.1001 = { #by Mathilda Bjarnehed
	hidden = yes
	
	trigger = {
		is_witch_trigger = no
		any_relation = {
			type = guardian
			is_witch_trigger = yes
		}
	}

	immediate = {
		save_scope_as = child
		#If coven and child is AI, immediately convert them
		if = {
			limit = {
				is_ai = yes
				house ?= {
					has_house_modifier = witch_coven
					house_head = { is_ai = yes }
				}
				any_relation = {
					type = guardian
					is_ai = yes
				}
			}
			child_witch_conversion_success_effect = yes
		}
		#For non-covens children and player children, send guardian choice event (AI guardians must chose convert for witch coven player children)
		else = {
			random_relation = { type = guardian trigger_event = witch.1002 }
		}
	}
}	

scripted_trigger witch_1002_allow_reveal_outcome_trigger = {
	exists = scope:child.liege
	scope:guardian = {
		this != scope:child.liege
		any_secret = {
			type = secret_witch
			OR = {
				NOT = { is_known_by = scope:child }
				NOT = { is_known_by = scope:child.liege }
			}
		}
	}
}

#Guardian: covert this child?
witch.1002 = { #by Mathilda Bjarnehed
	type = character_event
	title = witch.1002.t
	desc = witch.1002.desc
	theme = witchcraft
	override_background = {
		reference = study
	}
	left_portrait = scope:child

	immediate = { save_scope_as = guardian }
	
	#Convert them
	option = {
		name = witch.1002.a


		#Duel if child is AI
		if = {
			limit = { scope:child = { is_ai = yes } }
			duel = {
				skill = learning
				target = scope:child
				50 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = 2.5
					}
					opinion_modifier = {
						who = scope:child
						opinion_target = scope:guardian
						multiplier = 0.25
						step = 5
					}
					modifier = {
						scope:child = { has_trait = ambitious }
						add = 20
					}
					modifier = {
						scope:child = { has_trait = curious }
						add = 20
					}
					desc = child_witch_conversion_success_effect.desc
					child_witch_conversion_success_effect = yes
				}
				35 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = -2.5
					}
					opinion_modifier = {
						who = scope:child
						opinion_target = scope:guardian
						multiplier = -0.25
						step = 5
					}
					modifier = {
						scope:child = { has_trait = craven }
						add = 30
					}
					desc = child_witch_conversion_failure_effect.desc
					child_witch_conversion_failure_effect = yes
				}
				15 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = -2.5
					}
					opinion_modifier = {
						who = scope:child
						opinion_target = scope:guardian
						multiplier = -0.25
						step = 5
					}
					modifier = {
						scope:child = { has_trait = zealous }
						add = 150
					}
					trigger = {
						witch_1002_allow_reveal_outcome_trigger = yes
					}
					desc = child_witch_conversion_critical_failure_effect.desc
					child_witch_conversion_critical_failure_effect = yes
				}
			}
		}
		else = {
			show_as_tooltip = {
				random_list = {
					1 = {
						show_chance = no
						desc = child_witch_conversion_success_effect.desc
						child_witch_conversion_success_effect = yes
					}
					1 = {
						show_chance = no
						desc = child_witch_conversion_failure_effect.desc
						child_witch_conversion_failure_effect = yes
					}
					1 = {
						show_chance = no
						trigger = {
							witch_1002_allow_reveal_outcome_trigger = yes
						}
						desc = child_witch_conversion_critical_failure_effect.desc
						child_witch_conversion_critical_failure_effect = yes
					}
				}
			}

			scope:child = {
				trigger_event = witch.1003
			}
		}
		
		ai_chance = {
			base = 100

			ai_boldness_target_modifier = { VALUE = 50 }
			#Player children of witch covens should always be asked
			modifier = {
				scope:child = {
					house ?= { has_house_modifier = witch_coven }
					is_ai = no
				}
				add = 1000
			}
		}
	}

	#Don't risk it
	option = {
		name = witch.1002.b



		ai_chance = {
			base = 0

			ai_boldness_target_modifier = { VALUE = -100 }

			modifier = {
				exists = liege
				trait_is_criminal_in_faith_trigger = { TRAIT = witch FAITH = liege.faith GENDER_CHARACTER = root }
				add = 100
			}
			#Player children of witch covens should always be asked
			modifier = {
				scope:child = {
					house ?= { has_house_modifier = witch_coven }
					is_ai = no
				}
				add = -1000
			}
		}
	}
}


#Do I want to become a witch?
witch.1003 = { #by Mathilda Bjarnehed
	type = character_event
	title = witch.1003.t
	desc = witch.1003.desc
	theme = witchcraft
	override_background = {
		reference = study
	}
	left_portrait = {
		character = scope:guardian
		animation = personality_dishonorable
	}



	#Yes
	option = {
		name = witch.1003.a
		
		child_witch_conversion_success_effect = yes
	}

	#No...
	option = {
		name = witch.1003.b

		child_witch_conversion_failure_effect = yes
	}
	
	#I will tell someone!
	option = {
		trigger = {
			witch_1002_allow_reveal_outcome_trigger = yes
		}
		name = witch.1003.c

		child_witch_conversion_critical_failure_effect = yes
	}
}



##############################################
######COVERT TO WITCHCRAFT SCHEME EVENTS######
##############################################

#Do I want to go ahead with this?
witch.2001 = { #by Mathilda Bjarnehed
	type = character_event
	title = witch.2001.t
	desc = {
		desc = witch.2001.start.desc
		first_valid = {
			triggered_desc = {
				trigger = { trait_is_shunned_or_criminal_in_my_or_lieges_faith_trigger = { TRAIT = witch GENDER_CHARACTER = root } }
				desc = witch.2001.secrecy.desc
			}
			desc = witch.2001.no_secrecy.desc
		}
		desc = witch.2001.end.desc
	}
	theme = witchcraft
	override_background = {
		reference = sitting_room
	}
	left_portrait = scope:target
	
	#Yes
	option = {
		name = witch.2001.a
		custom_tooltip = witch.2001.a.tt

		if = {
			limit = { scope:target = { is_ai = no } }
			scope:target = {
				trigger_event = {
					id = witch.2002
					days = 3
				}
			}
		}
		else_if = {
			limit = { exists = scope:scheme_successful }
			trigger_event = {
				id = witch.2003
				days = 3
			}
		}
		else = {
			trigger_event = {
				on_action = convert_to_witchcraft_failure_outcome
				days = 3
			}
		}

		ai_chance = {
			base = 100
		}
	}

	#No
	option = {
		name = {
			trigger = {
				use_convert_to_witchcraft_secrecy_trigger = { OWNER = root }
			}
			text = witch.2001.b1
		}
		name = {
			trigger = {
				use_convert_to_witchcraft_secrecy_trigger = { OWNER = root }
			}
			text = witch.2001.b2
		}
		scope:scheme = {
			end_scheme = yes
		}

		ai_chance = {
			base = 0
		}
	}
}

#Someone is trying to convert me to become a witch (player only)
witch.2002 = { #by Mathilda Bjarnehed
	type = character_event
	title = witch.2002.t
	desc = {
		desc = witch.2002.start.desc
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:scheme_discovered }
				desc = witch.2002.discovery.desc
			}
			desc = witch.2002.no_discovery.desc
		}
		desc = witch.2002.end.desc
	}
	theme = witchcraft
	override_background = {
		reference = sitting_room
	}
	left_portrait = {
		character = scope:left_portrait
		triggered_animation = {
			trigger = { scope:left_portrait = root }
			animation = disbelief
		}
		animation = personality_dishonorable
	}
	cooldown = { years = 10 }
	
	immediate = {
		if = {
			limit = { exists = scope:scheme_discovered }
			scope:owner = {
				save_scope_as = left_portrait
				show_as_tooltip = {
					random_secret = {
						type = secret_witch
						limit = {
							NOT = { is_known_by = root }
						}
						reveal_to = root
					}
				}
			}
		}
		else = {
			save_scope_as = left_portrait
		}
	}

	#Yes I want to be a witch
	option = {
		name = witch.2002.a

		give_witch_secret_or_trait_effect = yes

		if = {
			limit = {
				faith = {
					NOT = { has_doctrine_parameter = witchcraft_accepted }
				}
			}
			add_piety = medium_piety_loss
		}
		
		scope:owner = {
			trigger_event = witch.2003
		}

		stress_impact = {
			zealous = massive_stress_impact_gain
			craven = medium_stress_impact_gain
		}
	}

	#No I don't want to be a witch
	option = {
		name = witch.2002.b

		add_piety = medium_piety_gain

		scope:owner = {
			trigger_event = witch.2004
		}

		if = {
			limit = { exists = scope:scheme_discovered }
			reverse_add_opinion = {
				target = scope:owner
				modifier = disappointed_opinion
				opinion = -15
			}
		}

		stress_impact = {
			ambitious = minor_stress_impact_gain
		}
	}
	
	#Reveal them to the world!
	option = {
		trigger = { exists = scope:scheme_discovered }
		name = witch.2002.c

		add_piety = medium_piety_gain

		reverse_add_opinion = {
			target = scope:owner
			modifier = hate_opinion
			opinion = -30
		}

		scope:owner = {
			trigger_event = witch.2005
		}

		stress_impact = {
			craven = medium_stress_impact_gain
			compassionate = minor_stress_impact_gain
			trusting = minor_stress_impact_gain
		}
	}
}	

#SUCCESS EVENTS
scripted_trigger witch_2003_can_learn_owner_secret = {
	save_temporary_scope_as = secret_learner
	scope:owner = {
		any_secret = {
			type = secret_witch
			NOT = { is_known_by = scope:secret_learner }
		}
	}
}

scripted_trigger witch_2003_unlock_reveal_trigger = {
	NOT = { exists = scope:scheme_discovered }
	scope:target = { witch_2003_can_learn_owner_secret = yes }
}


witch.2003 = { #by Mathilda Bjarnehed
	type = character_event
	title = witch.2003.t
	desc = witch.2003.desc
	theme = witchcraft
	override_background = {
		reference = sitting_room
	}
	left_portrait = {
		character = scope:target
		animation = personality_rational
	}
	immediate = {
		scope:target = {
			give_witch_secret_or_trait_effect = yes
			random_secret = {
				type = secret_witch
				reveal_to = root
			}
		}
		if = {
			limit = { exists = scope:scheme_discovered }
			random_secret = {
				type = secret_witch
				limit = {
					NOT = { is_known_by = scope:target }
				}
				reveal_to = scope:target
			}

			reverse_add_opinion = {
				target = scope:target
				modifier = grateful_opinion
				opinion = 20
			}
		}
	}

	#Great!
	option = {
		trigger = { witch_2003_unlock_reveal_trigger = no }
		name = witch.2003.a

		scope:scheme = {
			end_scheme = yes
		}
	}
	
	#Let them know who I am
	option = {
		trigger = { witch_2003_unlock_reveal_trigger = yes }
		name = witch.2003.b

		if = {
			limit = {
				house ?= { has_house_modifier = witch_coven }
			}
			custom_tooltip = witch.2003.b.tt
		}

		scope:target = {
			send_interface_message = {
				type = event_witchcraft_good
				title = witch.2003.message
				left_icon = scope:owner
				scope:owner = {
					random_secret = {
						type = secret_witch
						limit = {
							NOT = { is_known_by = scope:target }
						}
						reveal_to = scope:target
					}
				}
			}
		}

		reverse_add_opinion = {
			target = scope:target
			modifier = grateful_opinion
			opinion = 20
		}

		scope:scheme = {
			end_scheme = yes
		}

		ai_chance = {
			base = 100

			modifier = {
				has_trait = honest
				add = 50
			}
			modifier = {
				has_trait = trusting
				add = 100
			}
		}
	}

	#Keep my secret
	option = {
		trigger = { witch_2003_unlock_reveal_trigger = yes }
		name = witch.2003.c

		scope:scheme = {
			end_scheme = yes
		}

		ai_chance = {
			base = 50
			modifier = {
				has_trait = paranoid
				add = 100
			}
			modifier = {
				has_trait = craven
				add = 50
			}
			modifier = {
				has_trait = deceitful
				add = 50
			}
		}
	}

	after = {
		#Handle discover
		if = {
			limit = {
				exists = scope:scheme_discovered
				scope:target = {
					is_ai = yes
					OR = {
						AND = {
							is_ruler = no
							liege ?= {
								witch_2003_can_learn_owner_secret = yes
								this != scope:owner
							}
						}
						any_relation = { type = lover witch_2003_can_learn_owner_secret = yes }
						any_consort = { witch_2003_can_learn_owner_secret = yes }
						any_child = {
							age >= 7
							witch_2003_can_learn_owner_secret = yes
						}
					}
				}
			}
			#Trigger the Overheard-event for the Scheme Owner
			trigger_event = witch.2010
		}
	}
}

#Success, but discovered
witch.2010 = { #by Mathilda Bjarnehed
	type = character_event
	title = witch.2010.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					any_secret = {
						type = secret_witch
						is_known_by = scope:target
					}
				}
				desc = witch.talk.2010
			}
			desc = witch.leave.2010
		}
		desc = witch.end.2010
	}
	theme = witchcraft
	override_background = {
		reference = sitting_room
	}
	left_portrait = {
		character = scope:target
		animation = personality_rational
	}
	
	immediate = {
		hidden_effect = {
			scope:target = {
				random_list = {
					3 = {
						trigger = {
							is_ruler = no
							liege ?= {
								witch_2003_can_learn_owner_secret = yes
								this != scope:owner
							}
						}
						liege = { save_scope_as = listener }
					}
					5 = {
						trigger = {
							any_relation = { 
								type = lover 
								witch_2003_can_learn_owner_secret = yes 
							}
						}
						random_relation = {
							type = lover
							limit = { witch_2003_can_learn_owner_secret = yes }
							save_scope_as = listener
						}
					}
					5 = {
						trigger = {
							any_consort = { witch_2003_can_learn_owner_secret = yes }
						}
						random_consort = {
							limit = { witch_2003_can_learn_owner_secret = yes }
							save_scope_as = listener
						}
					}
					1 = {
						trigger = {
							any_child = {
								age >= 7
								witch_2003_can_learn_owner_secret = yes
							}
						}
						random_child = {
							limit = {
								age >= 7
								witch_2003_can_learn_owner_secret = yes
							}
							save_scope_as = listener
						}
					}
				}
			}
			#Let's notify the Listener that they learned the secret
			scope:listener = {
				send_interface_message = {
					type = event_witchcraft_neutral
					title = witch.2010.message
					left_icon = scope:owner
					scope:owner = {
						random_secret = {
							type = secret_witch
							reveal_to = scope:listener
						}
					}
				}
			}
		}
	}
	option = {
		name = witch.2010.a
		custom_tooltip = witch.2010.a.tt
	}
}


#FAILURE EVENTS

#They refuse
witch.2004 = { #by Mathilda Bjarnehed
	type = character_event
	title = witch.2004.t
	desc = {
		desc = witch.2004.start.desc
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:scheme_discovered }
				desc = witch.2004.discovered.desc
			}
			desc = witch.2004.not_discovered.desc
		}
	}
	theme = witchcraft
	override_background = {
		reference = sitting_room
	}
	left_portrait = {
		character = scope:target
		animation = anger
	}

	immediate = {
		if = {
			limit = { exists = scope:scheme_discovered }
			random_secret = {
				type = secret_witch
				limit = {
					NOT = { is_known_by = scope:target }
				}
				reveal_to = scope:target
			}
			reverse_add_opinion = {
				target = scope:target
				modifier = impious_opinion
				opinion = -20
			}
		}
		scope:target = {
			add_character_flag = {	
				flag = block_convert_to_witchcraft
				days = 7300
			}
		}
	}
	
	option = {
		name = witch.2004.a

		scope:scheme = {
			end_scheme = yes
		}
	}
}

#They tell their liege
witch.2005 = { #by Mathilda Bjarnehed
	type = character_event
	title = witch.2004.t
	desc = {
		desc = witch.2004.start.desc
		desc = witch.2005.end.desc
	}
	theme = witchcraft
	override_background = {
		reference = sitting_room
	}
	left_portrait = {
		character = scope:target
		animation = anger
	}
	trigger = {
		scope:target = {
			exists = liege
			is_ruler = no
			liege = { this != scope:owner }
		}
		exists = scope:scheme_discovered
	}

	weight_multiplier = {
		base = 1

		ai_value_modifier = {
			who = scope:target
			ai_zeal = 0.05
			max = 2
			min = -0.5
		}
		opinion_modifier = {
			who = scope:target
			opinion_target = root
			multiplier = -0.05
			max = 2
			min = -0.5
		}
	}


	immediate = {
		random_secret = {
			type = secret_witch
			if = {
				limit = { NOT = { is_known_by = scope:target } }
				reveal_to = scope:target
			}
			if = {
				limit = { NOT = { is_known_by = scope:target.liege } }
				reveal_to = scope:target.liege
			}
		}
		scope:target = {
			add_character_flag = {	
				flag = block_convert_to_witchcraft
				days = 7300
			}
		}
		reverse_add_opinion = {
			target = scope:target
			modifier = impious_opinion
			opinion = -20
		}
	}
	
	option = {
		name = witch.2005.a
		flavor = witch.2005.a.tt

		scope:scheme = {
			end_scheme = yes
		}
	}
}


#Target was already a witch! Expose your secrets to each other - for owner
witch.2006 = { #by Linnéa Thimrén
	type = character_event
	title = witch.2006.t
	desc = witch.2006.desc
	theme = witchcraft
	override_background = {
		reference = sitting_room
	}
	left_portrait = {
		character = scope:target
		animation = shock
	}

	trigger = { #Make sure the secrets are still unknown and that target is alive and kicking
		any_scheme = {
			type = convert_to_witchcraft
			scheme_target_character = scope:target
		}
		scope:target = {
			is_alive = yes
			any_secret = {
				type = secret_witch
				NOT = {  any_secret_knower = { this = root } }
			}
		}
	}

	immediate = {
		scope:target = {
			random_secret = {
				type = secret_witch
				reveal_to = root
			}
			trigger_event = witch.2007
		}
		random_secret = {
			type = secret_witch
			reveal_to = scope:target
		}
		reverse_add_opinion = {
			target = scope:target
			modifier = respect_opinion
			opinion = 20
		}
	}

	#Great!
	option = {
		name = witch.2006.a
	}

	after = {
		scope:scheme = {
			end_scheme = yes
		}
	}
}


#Target was already a witch! Expose your secrets to each other - for target
witch.2007 = { #by Linnéa Thimrén
	type = character_event
	title = witch.2007.t
	desc = witch.2007.desc
	theme = witchcraft
	override_background = {
		reference = sitting_room
	}
	left_portrait = {
		character = scope:owner
		animation = shock
	}

	trigger = { #Make sure the secrets are still unknown and that target is alive and kicking
		scope:owner = {
			is_alive = yes
			is_witch_trigger = yes
		}
	}

	immediate = {
		show_as_tooltip = {
			scope:owner = {
				random_secret = {
					type = secret_witch
					reveal_to = root
				}
			}
			random_secret = {
				type = secret_witch
				reveal_to = scope:owner
			}
		}
		reverse_add_opinion = {
			target = scope:owner
			modifier = respect_opinion
			opinion = 20
		}
	}

	#Great!
	option = {
		name = witch.2007.a
	}
}

###############################
# REVEAL AS WITCH INTERACTION #
###############################

witch.2900 = {
	type = letter_event
	opening = witch.2900.t
	desc = witch.2900.desc
	sender = scope:actor
	orphan = yes

	immediate = {
		scope:witch_secret = { reveal_to = root }
		hidden_effect = {
			if = {
				limit = { can_set_relation_potential_friend_trigger = { CHARACTER = scope:actor } }
				set_relation_potential_friend = scope:actor
			}
		}
	}

	option = {
		name = witch.2900.a
		scope:actor = {
			trigger_event = {
				id = witch.2901
				days = 3
			}
		}
	}
}

witch.2901 = {
	type = letter_event
	opening = witch.2901.t
	desc = witch.2901.desc
	sender = scope:recipient

	option = {
		name = witch.2901.a
	}
}


#########################
# WITCH RITUAL ACTIVITY #
#########################

witch.3001 = {
	type = letter_event
	opening = witch.3001.t
	desc = witch.3001.desc
	sender = scope:host
	orphan = yes # deprecated by new activity system

	immediate = {
		scope:activity.activity_host = { save_scope_as = host }
		debug_log = invitation_received
	}

	#Yes!
	option = {
		name = witch.3001.a

		play_music_cue = "mx_cue_sacredrite"
		accept_activity_invite = scope:activity
		reverse_add_opinion = {
			target = scope:host
			modifier = pleased_opinion
			opinion = 10
		}
		ai_chance = {
			base = 100
			opinion_modifier = {
				opinion_target = scope:host
			}
		}
	}

	#No...
	option = {
		name = witch.3001.b

		decline_activity_invite = scope:activity
		reverse_add_opinion = {
			target = scope:host
			modifier = disappointed_opinion
			opinion = -10
		}
		ai_chance = {
			base = 10
			modifier = {
				add = 15
				target_is_liege_or_above = scope:host
			}
			ai_value_modifier = {
				ai_boldness = 0.2
			}
		}
	}
}

#No guests came
witch.3002 = { #by Mathilda Bjarnehed
	type = activity_event
	title = witch.3002.t
	desc = witch.3002.desc
	theme = witchcraft
	override_background = {
		reference = bp1_bonfire
	}
	left_portrait = {
		character = scope:target
		animation = sadness
	}

	option = {
		name = witch.3002.a
		
		scope:activity = {
			set_variable = activity_invalidated
		}
	}
}


#Uninvited guest
scripted_trigger witch_3003_potential_guest_trigger = {
	is_adult = yes
	NOR = {
		has_RelationToMe_relation = { CHARACTER = root }
		any_secret = {
			type = secret_witch
			is_known_by = root
		}
	}
	faith = scope:inviter.faith
	culture = { has_same_culture_heritage = scope:inviter.culture }
	is_witch_trigger = yes
}


witch.3003 = { #by Mathilda Bjarnehed
	type = activity_event
	title = witch.3003.t
	desc = witch.3003.desc
	theme = witchcraft
	override_background = {
		reference = corridor_night
	}
	left_portrait = scope:inviter
	right_portrait = scope:new_guest
	
	trigger = {
		scope:activity = {
			any_attending_character = {
				this != root
				is_adult = yes
			}
		}
	}

	immediate = {
		hidden_effect = {
			capital_province = { save_scope_as = capital }

			#Find inviter
			scope:activity = {
				random_attending_character = {
					limit = {
						NOR = {
							is_courtier_of = root
							this = root
						}
						is_ai = yes
						is_adult = yes
					}
					alternative_limit = {
						is_ai = yes
						is_adult = yes
					}
					alternative_limit = { is_adult = yes }
					save_scope_as = inviter
				}
			}

			#50% chance of pool character guest, 50% chance of new guest
			random = {
				chance = 50
				random_pool_character = {
					province = capital_province
					limit = {
						witch_3003_potential_guest_trigger = yes
						save_temporary_scope_as = potential_guest
						OR = {
							AND = {
								OR = {
									has_trait = beauty_good
									has_trait = intellect_good
								}
								matching_gender_and_sexuality_trigger = { CHARACTER_1 = scope:potential_guest CHARACTER_2 = root }
							}
							has_trait = lifestyle_herbalist
						}
					}
					alternative_limit = {
						witch_3003_potential_guest_trigger = yes
					}
					save_scope_as = new_guest
				}
			}

			if = {
				limit = {
					NOT = { exists = scope:new_guest }
				}
				create_witch_effect = { WHO = root }
				scope:created_witch = {
					save_scope_as = new_guest
					visit_court_of = root
				}
			}
			
			#Discover secret
			scope:new_guest = {
				random_secret = {
					type = secret_witch
					limit = {
						NOT = { is_known_by = root }
					}
					reveal_to = root
				}
				add_character_flag = {
					flag = grand_rite_new_guest
					days = 30
				}
			}
		}
	}

	#You are very welcome!
	option = {
		name = witch.3003.a
		
		scope:new_guest = {
			add_to_activity = scope:activity
		}
		reverse_add_opinion = {
			target = scope:new_guest
			modifier = grateful_opinion
			opinion = 15
		}
		reverse_add_opinion = {
			target = scope:inviter
			modifier = grateful_opinion
			opinion = 15
		}
	}

	#Guest of honor!
	option = {
		name = witch.3003.b
		
		scope:new_guest = {
			add_to_activity = scope:activity
		}
		reverse_add_opinion = {
			target = scope:new_guest
			modifier = grateful_opinion
			opinion = 30
		}
		reverse_add_opinion = {
			target = scope:inviter
			modifier = envy_opinion
			opinion = -10
		}
	}

	#Invitations only, sorry
	option = {
		name = witch.3003.c
		
		reverse_add_opinion = {
			target = scope:new_guest
			modifier = disappointed_opinion
			opinion = -15
		}
		reverse_add_opinion = {
			target = scope:inviter
			modifier = disappointed_opinion
			opinion = -15
		}
	}
}


#Grand rite choice

scripted_effect grand_rite_good_outcome = {
	scope:activity = {
		every_attending_character = {
			limit = { this != root }
			custom = every_grand_rite_participant
			add_opinion = {
				target = root
				modifier = impressed_opinion
				opinion = 20
			}
		}
	}
}

scripted_effect grand_rite_poor_outcome = {
	scope:activity = {
		every_attending_character = {
			limit = { this != root }
			custom = every_grand_rite_participant
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -15
			}
		}
	}
	add_stress = minor_stress_gain
}

witch.3010 = { #by Mathilda Bjarnehed
	type = activity_event
	title = witch.3010.t
	desc = witch.3010.desc
	theme = witchcraft
	override_background = {
		reference = bp1_bonfire
	}
	left_portrait = root

	immediate = {
		save_scope_as = host
		capital_province = { save_scope_as = background_wilderness_scope } 
	}

	#Read old scroll
	option = {
		name = witch.3010.a

		duel = {
			skill = learning
			value = average_skill_rating
			75 = {
				desc = witch.3010.a.great
				compare_modifier = {
					value = scope:duel_value
					multiplier = 5
				}
				save_scope_value_as = {
					name = grand_rite_ceremony_outcome
					value = flag:great_translation
				}
				show_as_tooltip = { grand_rite_good_outcome = yes }
			}
			25 = {	
				desc = witch.3010.a.poor
				compare_modifier = {
					value = scope:duel_value
					multiplier = -5
				}
				min = 10
				save_scope_value_as = {
					name = grand_rite_ceremony_outcome
					value = flag:poor_translation
				}
				show_as_tooltip = { grand_rite_poor_outcome = yes }
			}
		}
	}

	#Use some tricks
	option = {
		name = witch.3010.b
		
		duel = {
			skill = intrigue
			value = average_skill_rating
			75 = {
				desc = witch.3010.b.great
				compare_modifier = {
					value = scope:duel_value
					multiplier = 5
				}
				save_scope_value_as = {
					name = grand_rite_ceremony_outcome
					value = flag:great_tricks
				}
				show_as_tooltip = { grand_rite_good_outcome = yes }
			}
			25 = {	
				desc = witch.3010.b.poor
				compare_modifier = {
					value = scope:duel_value
					multiplier = -5
				}
				min = 10
				save_scope_value_as = {
					name = grand_rite_ceremony_outcome
					value = flag:poor_tricks
				}
				show_as_tooltip = { grand_rite_poor_outcome = yes }
			}
		}

		stress_impact = {
			honest = minor_stress_impact_gain
		}
	}

	#Improvise
	option = {
		name = witch.3010.c

		duel = {
			skill = diplomacy
			value = average_skill_rating
			75 = {
				desc = witch.3010.c.great
				compare_modifier = {
					value = scope:duel_value
					multiplier = 5
				}
				save_scope_value_as = {
					name = grand_rite_ceremony_outcome
					value = flag:great_improvisation
				}
				show_as_tooltip = { grand_rite_good_outcome = yes }
			}
			25 = {	
				desc = witch.3010.c.poor
				compare_modifier = {
					value = scope:duel_value
					multiplier = -5
				}
				min = 10
				save_scope_value_as = {
					name = grand_rite_ceremony_outcome
					value = flag:poor_improvisation
				}
				show_as_tooltip = { grand_rite_poor_outcome = yes }
			}
		}

		stress_impact = {
			shy = minor_stress_impact_gain
		}
	}

	#Have a really nice offering
	option = {
		trigger = {
			is_ai = no
			short_term_gold >= medium_gold_value
		}
		name = witch.3010.d
		
		remove_short_term_gold = medium_gold_value

		save_scope_value_as = {
			name = grand_rite_ceremony_outcome
			value = flag:offering
		}

		grand_rite_good_outcome = yes

		stress_impact = {
			greedy = minor_stress_impact_gain
		}
	}

	option = {
		trigger = {
			short_term_gold < medium_gold_value
		}
		name = witch.3010.e
		custom_tooltip = witch.3010.e.tt

	}

	after = {
		scope:activity = {
			every_attending_character = {
				trigger_event = {
					id = witch.3014
				}
			}
		}
	}
}

#Everyone reacts to the grand rite (host and guests)
scripted_trigger witch_3014_can_have_sex_trigger = {
	is_adult = yes
	NOR = {
		has_sexuality = asexual
		has_trait = celibate
	}
	might_cheat_on_every_partner_trigger = yes
}

scripted_trigger witch_3014_sex_partner_trigger = {
	witch_3014_can_have_sex_trigger = yes
	this != root
	is_ai = yes
	save_temporary_scope_as = seduction_target
	matching_gender_and_sexuality_trigger = { CHARACTER_1 = scope:seduction_target CHARACTER_2 = root }
	might_cheat_on_every_partner_trigger = yes
}

scripted_trigger witch_3014_loved_sex_partner_trigger = {
	witch_3014_sex_partner_trigger = yes
	OR = {
		has_relation_lover = root
		is_consort_of = root
		has_relation_soulmate = root
	}
}

scripted_trigger witch_3014_regular_sex_partner_trigger = {
	witch_3014_sex_partner_trigger = yes
	NOR = {
		has_relation_lover = root
		has_relation_soulmate = root
		is_consort_of = root
	}
}

scripted_effect witch_3017_soulmate_sex_effect = {
	reverse_add_opinion = {
		target = scope:sex_partner
		modifier = love_opinion
		opinion = 20
	}
	add_stress = major_stress_loss
	had_sex_with_effect = { CHARACTER = scope:sex_partner PREGNANCY_CHANCE = 50 }
}


witch.3014 = { #by Mathilda Bjarnehed
	type = activity_event
	title = witch.3010.t
	desc = {
		#host
		first_valid = {
			triggered_desc = {
				trigger = { root = scope:host }
				desc = {
					first_valid = {
						triggered_desc = {
							trigger = { scope:grand_rite_ceremony_outcome = flag:great_translation }
							desc = witch.3014.host.great_translation.desc
						}
						triggered_desc = {
							trigger = { scope:grand_rite_ceremony_outcome = flag:poor_translation }
							desc = witch.3014.host.poor_translation.desc
						}
						triggered_desc = {
							trigger = { scope:grand_rite_ceremony_outcome = flag:great_tricks }
							desc = witch.3014.host.great_tricks.desc
						}
						triggered_desc = {
							trigger = { scope:grand_rite_ceremony_outcome = flag:poor_tricks }
							desc = witch.3014.host.poor_tricks.desc
						}
						triggered_desc = {
							trigger = { scope:grand_rite_ceremony_outcome = flag:great_improvisation }
							desc = witch.3014.host.great_improvisation.desc
						}
						triggered_desc = {
							trigger = { scope:grand_rite_ceremony_outcome = flag:poor_improvisation }
							desc = witch.3014.host.poor_improvisation.desc
						}
						triggered_desc = {
							trigger = { scope:grand_rite_ceremony_outcome = flag:offering }
							desc = witch.3014.host.offering.desc
						}
						desc = witch.3014.host.fallback.desc
					}
					desc = witch.3014.host.end.desc
				}
			}
			#everyone else
			desc = {
				desc = witch.3014.guest.start.desc
				first_valid = {
					triggered_desc = {
						trigger = {
							OR = {
								scope:grand_rite_ceremony_outcome = flag:great_translation
								scope:grand_rite_ceremony_outcome = flag:great_tricks
								scope:grand_rite_ceremony_outcome = flag:great_improvisation
								scope:grand_rite_ceremony_outcome = flag:offering
								NOT = { exists = scope:grand_rite_ceremony_outcome }
							}
						}
						desc = witch.3014.guest.good.desc
					}
					triggered_desc = {
						trigger = {
							OR = {
								scope:grand_rite_ceremony_outcome = flag:poor_translation
								scope:grand_rite_ceremony_outcome = flag:poor_tricks
								scope:grand_rite_ceremony_outcome = flag:poor_improvisation
							}
						}
						desc = witch.3014.guest.bad.desc
					}
					desc = witch.3014.guest.fallback.desc
				}
				desc = witch.3014.guest.end.desc
			}
		}
	}	
	theme = witchcraft
	override_background = {
		reference = bp1_bonfire
	}
	left_portrait = scope:left_portrait
	right_portrait = scope:right_portrait
	lower_left_portrait = scope:lower_left_portrait
	lower_center_portrait = scope:lower_center_portrait
	lower_right_portrait = scope:lower_right_portrait



	immediate = {
		#Tell everyone secret about everyone else
		hidden_effect = {
			scope:activity = {
				every_attending_character = {
					save_temporary_scope_as = learning_secret
					scope:activity = {
						every_attending_character = {
							random_secret = {
								type = secret_witch
								limit = {
									NOT = { is_known_by = scope:learning_secret }
								}
								reveal_to = scope:learning_secret
							}
						}
					}
				}
			}
		}

		#Give outcome to host
		if = {
			limit = { this = scope:host }

			if = {
				limit = {
					OR = {
						scope:grand_rite_ceremony_outcome = flag:great_translation
						scope:grand_rite_ceremony_outcome = flag:great_tricks
						scope:grand_rite_ceremony_outcome = flag:great_improvisation
						scope:grand_rite_ceremony_outcome = flag:offering
					}
				}
				grand_rite_good_outcome = yes
			}
			else = {
				grand_rite_poor_outcome = yes
			}
		}


		###What is available to do?###
		scope:activity = {
			#Talk to new guest
			if = {
				limit = { root = scope:host }
				scope:activity = {
					random_attending_character = {
						limit = { has_character_flag = grand_rite_new_guest }
						save_scope_as = new_guest
					}
				}
			}

			#Herbalism
			random_attending_character = {
				limit = {
					has_trait = lifestyle_herbalist
					NOR = {
						trigger_if = {
							limit = { exists = scope:new_guest }
							this = scope:new_guest
						}
						this = root
					}
				}
				save_scope_as = herbalist
			}

			#Teacher (experience )
			random_attending_character = {
				limit = {
					NOR = {
						trigger_if = {
							limit = { exists = scope:new_guest }
							this = scope:new_guest
						}
						trigger_if = {
							limit = { exists = scope:herbalist }
							this = scope:herbalist
						}
						this = root
					}
					trigger_if = {
						limit = { highest_skill = diplomacy }
						root = { diplomacy_lifestyle_perk_points < max_perk_amount_per_lifestyle }
					}
					trigger_else_if = {
						limit = { highest_skill = martial }
						root = { martial_lifestyle_perk_points < max_perk_amount_per_lifestyle }
					}
					trigger_else_if = {
						limit = { highest_skill = stewardship }
						root = { stewardship_lifestyle_perk_points < max_perk_amount_per_lifestyle }
					}
					trigger_else_if = {
						limit = { highest_skill = intrigue }
						root = { intrigue_lifestyle_perk_points < max_perk_amount_per_lifestyle }
					}
					trigger_else_if = {
						limit = { highest_skill = learning }
						root = { learning_lifestyle_perk_points < max_perk_amount_per_lifestyle }
					}
					trigger_else = {
						always = no
					}
				}
				weight = {
					base = 0
					modifier = {
						add = {
							if = {
								limit = { highest_skill = diplomacy }
								add = diplomacy
							}
							else_if = {
								limit = { highest_skill = martial }
								add = martial
							}
							else_if = {
								limit = { highest_skill = stewardship }
								add = stewardship
							}
							else_if = {
								limit = { highest_skill = intrigue }
								add = intrigue
							}
							else_if = {
								limit = { highest_skill = learning }
								add = learning
							}
						}
					}
				}
				save_scope_as = teacher
			}

			#Someone to seduce
			if = {
				limit = {
					root = {
						witch_3014_can_have_sex_trigger = yes
					}
				}
				#If you have a soulmate here, only sleep with them (not available if they can't sleep with you for some reason)
				if = {
					limit = { any_attending_character = { has_relation_soulmate = root } }
					random_attending_character = {
						limit = {
							witch_3014_loved_sex_partner_trigger = yes
							has_relation_soulmate = root
						}
						save_scope_as = sex_partner
					}
				}
				else = {
					random_list = {
						#Just someone regular
						1 = {
							trigger = {
								any_attending_character = {
									witch_3014_regular_sex_partner_trigger = yes
									accepts_incest_with_trigger = { CHARACTER = root } #Skip this one if there's only non-accepting incest options available
								}
							}
							random_attending_character = {
								limit = {
									witch_3014_regular_sex_partner_trigger = yes
									save_temporary_scope_as = sex_partner_check #Saved for weight modifier
								}
								weight = {
									base = 10
									modifier = {
										has_trait = seducer
										add = 10
									}
									modifier = {
										has_trait = lustful
										add = 10
									}
									modifier = {
										has_trait = beauty_good
										add = 10
									}
									modifier = {
										has_relation_potential_lover = root
										add = 10
									}
									incest_acceptance_modifier = {
										TARGET = scope:sex_partner_check
										SEDUCER = root
									}
								}
								save_scope_as = sex_partner
							}
						}
						1 = {
							trigger = {
								any_attending_character = {
									witch_3014_loved_sex_partner_trigger = yes
								}
							}
							random_attending_character = {
								limit = {
									witch_3014_loved_sex_partner_trigger = yes
								}
								weight = {
									base = 1
									modifier = {
										is_spouse_of = root
										add = 2
									}
								}
								save_scope_as = sex_partner
							}
						}
					}
				}		
			}

			#Set portraits
			if = {
				limit = {
					exists = scope:herbalist
					exists = scope:teacher
					exists = scope:new_guest
				}
				scope:herbalist = { save_scope_as = lower_left_portrait }
				scope:teacher = { save_scope_as = lower_center_portrait }
				scope:new_guest = { save_scope_as = lower_right_portrait }
			}
			else_if = {
				limit = {
					exists = scope:herbalist
					exists = scope:teacher
				}
				scope:herbalist = { save_scope_as = left_portrait }
				scope:teacher = { save_scope_as = right_portrait }
			}
			else_if = {
				limit = {
					exists = scope:herbalist
					exists = scope:new_guest
				}
				scope:herbalist = { save_scope_as = left_portrait }
				scope:new_guest = { save_scope_as = right_portrait }
			}
			else_if = {
				limit = {
					exists = scope:teacher
					exists = scope:new_guest
				}
				scope:teacher = { save_scope_as = left_portrait }
				scope:new_guest = { save_scope_as = right_portrait }
			}
			else_if = {
				limit = { exists = scope:herbalist }
				scope:herbalist = { save_scope_as = left_portrait }
			}
			else_if = {
				limit = { exists = scope:teacher }
				scope:teacher = { save_scope_as = left_portrait }
			}
			else_if = {
				limit = { exists = scope:new_guest }
				scope:new_guest = { save_scope_as = left_portrait }
			}
			else = {
				save_scope_as = left_portrait
			}
		}
	}

	###WHAT DO I WANT TO DO?###

	#Herbalism
	option = {
		trigger = {
			exists = scope:herbalist
		}
		name = witch.3014.a
		highlight_portrait = scope:herbalist
		
		if = {
			limit = { NOT = { has_trait = lifestyle_herbalist } }
			random_list = {
				40 = {
					desc = witch.3014.a.knowledge
					send_interface_toast = {
						title = witch.3014.a.knowledge
						left_icon = scope:herbalist
						add_trait = lifestyle_herbalist
					}
				}
				60 = {
					desc = witch.3014.a.inspiration
					send_interface_toast = {
						title = witch.3014.a.inspiration
						left_icon = scope:herbalist
						add_character_modifier = {
							modifier = seeker_of_knowledge
							years = 5
						}
					}
				}
			}
		}
		else = {
			add_character_modifier = {
				modifier = seeker_of_knowledge
				years = 5
			}
		}

		stress_impact = {
			lazy = minor_stress_impact_gain
		}
	}

	#Teacher gives you lifestyle perk point
	option = {
		trigger = { exists = scope:teacher }
		name = {
			text = {
				desc = witch.3014.b.start
				first_valid = {
					triggered_desc = {
						trigger = { scope:teacher = { highest_skill = diplomacy } }
						desc = witch.3014.b.diplomacy
					}
					triggered_desc = {
						trigger = { scope:teacher = { highest_skill = martial } }
						desc = witch.3014.b.martial
					}
					triggered_desc = {
						trigger = { scope:teacher = { highest_skill = stewardship } }
						desc = witch.3014.b.stewardship
					}
					triggered_desc = {
						trigger = { scope:teacher = { highest_skill = intrigue } }
						desc = witch.3014.b.intrigue
					}
					triggered_desc = {
						trigger = { scope:teacher = { highest_skill = learning } }
						desc = witch.3014.b.learning
					}
				}
			}
		}
		highlight_portrait = scope:teacher

		if = {
			limit = { scope:teacher = { highest_skill = diplomacy } }
			add_diplomacy_lifestyle_perk_points = 1
		}
		else_if = {
			limit = { scope:teacher = { highest_skill = martial } }
			add_martial_lifestyle_perk_points = 1
		}
		else_if = {
			limit = { scope:teacher = { highest_skill = stewardship } }
			add_stewardship_lifestyle_perk_points = 1
		}
		else_if = {
			limit = { scope:teacher = { highest_skill = intrigue } }
			add_intrigue_lifestyle_perk_points = 1
		}
		else_if = {
			limit = { scope:teacher = { highest_skill = learning } }
			add_learning_lifestyle_perk_points = 1
		}

		stress_impact = {
			lazy = minor_stress_impact_gain
		}
	}
	
	#Seducer (sneak away)
	option = {
		trigger = {
			exists = scope:sex_partner
			NOT = { has_relation_soulmate = scope:sex_partner }
			is_attracted_to_gender_of = scope:sex_partner
			might_cheat_on_every_partner_trigger = yes
		}
		name = witch.3014.c
		custom_tooltip = witch.3014.c.tt

		if = {
			limit = { scope:sex_partner = { witch_3014_loved_sex_partner_trigger = yes } }
			trigger_event = {
				id = witch.3016
				days = 1
			}
		}
		else = {
			trigger_event = {
				id = witch.3015
				days = 1
			}
		}

		stress_impact = {
			chaste = medium_stress_impact_gain
			shy = minor_stress_impact_gain
			rakish = minor_stress_impact_loss
		}
	}

	#Seducer (soulmate)
	option = {
		trigger = {
			exists = scope:sex_partner
			has_relation_soulmate = scope:sex_partner
		}
		name = witch.3014.e
		highlight_portrait = scope:sex_partner
		
		trigger_event = {
			id = witch.3017
			days = 1
		}
		show_as_tooltip = { witch_3017_soulmate_sex_effect = yes }
	}

	#Talk with new guest
	option = {
		trigger = { exists = scope:new_guest }
		name = witch.3014.d
		highlight_portrait = scope:new_guest

		random_list = {
			35 = { #Becomes friend and joins court
				desc = witch.3014.d.move_in
				compatibility_modifier = {
					who = root
					compatibility_target = scope:new_guest
					multiplier = 3
					max = 50
					min = -30
				}
				send_interface_toast = {
					title = witch.3014.d.move_in
					left_icon = scope:new_guest
					set_relation_friend = { reason = friend_bond_at_ceremony target = scope:new_guest }
					add_courtier = scope:new_guest
				}
			}
			50 = { #Becomes friend
				desc = witch.3014.d.friend
				compatibility_modifier = {
					who = root
					compatibility_target = scope:new_guest
					multiplier = 2
					max = 35
					min = -35
				}
				send_interface_toast = {
					title = witch.3014.d.friend
					left_icon = scope:new_guest
					set_relation_friend = { reason = friend_bond_at_ceremony target = scope:new_guest province = root.location }
				}
			}
			15 = {
				desc = witch.3014.d.enemy
				compatibility_modifier = {
					who = root
					compatibility_target = scope:new_guest
					multiplier = -3
					max = 60
					min = -9
				}
				modifier = {
					OR = {
						has_trait = vengeful
						has_trait = callous
						has_trait = sadistic
						has_trait = wrathful
					}
					add = 15
				}
				send_interface_toast = {
					title = witch.3014.d.enemy
					left_icon = scope:new_guest
					set_relation_rival = {
						target = scope:new_guest
						reason = rival_at_ceremony
					}
				}
			}
		}

		stress_impact = {
			shy = minor_stress_impact_gain
		}
	}

	#Relax and indulge
	option = {
		trigger = {
			calc_true_if = {
				amount <= 3
				exists = scope:herbalist
				exists = scope:teacher
				exists = scope:sex_partner
				exists = scope:new_guest
			}
		}
		name = witch.3014.f

		stress_impact = {
			base = major_stress_loss
			gregarious = minor_stress_impact_loss
			drunkard = minor_stress_impact_loss
			hashishiyah = minor_stress_impact_loss
			comfort_eater = minor_stress_impact_loss
		}
	}
}	


#Sleep with someone (regular)
witch.3015 = { #by Mathilda Bjarnehed
	type = activity_event
	title = witch.3015.t
	desc = {
		desc = witch.3015.start.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:new_guest
					scope:sex_partner = scope:new_guest
				}
				desc = witch.3015.new_guest.desc
			}
			desc = witch.3015.regular.desc
		}
		desc = witch.3015.end.desc
	}
	theme = witchcraft
	override_background = {
		reference = bp1_bonfire
	}
	left_portrait = {
		character = scope:sex_partner
		animation = flirtation
	}

	#Yes
	option = {
		name = witch.3015.a

		progress_towards_lover_effect = {
			CHARACTER = scope:sex_partner
			REASON = lover_witch_sex_partner
			OPINION = default_lover_opinion
		}
		had_sex_with_effect = { CHARACTER = scope:sex_partner PREGNANCY_CHANCE = 50 }
	}

	#No
	option = {
		name = witch.3015.b
		custom_tooltip = witch.3015.b.tt

		reverse_add_opinion = {
			target = scope:sex_partner
			modifier = disappointed_opinion
			opinion = -15
		}
	}
}

#Sleep with someone (spouse/lover -> soulmate)
witch.3016 = { #by Mathilda Bjarnehed
	type = activity_event
	title = witch.3016.t
	desc = {
		desc = witch.3015.start.desc
		desc = witch.3016.end.desc
	}
	theme = witchcraft
	override_background = {
		reference = bp1_bonfire
	}
	left_portrait = {
		character = scope:sex_partner
		animation = love
	}
	
	#Yes
	option = {
		name = witch.3016.a

		set_relation_soulmate = { reason = soulmate_witch_ceremony copy_reason = lover target = scope:sex_partner }
		had_sex_with_effect = { CHARACTER = scope:sex_partner PREGNANCY_CHANCE = 50 }
	}

	#No
	option = {
		name = witch.3016.b
		custom_tooltip = witch.3015.b.tt

		reverse_add_opinion = {
			target = scope:sex_partner
			modifier = disappointed_opinion
			opinion = -15
		}
	}
}


#Sleep with someone (soulmate)
witch.3017 = { #by Mathilda Bjarnehed
	type = activity_event
	title = witch.3016.t
	desc = {
		desc = witch.3015.start.desc
		desc = witch.3017.end.desc
	}
	theme = witchcraft
	override_background = {
		reference = bp1_bonfire
	}
	left_portrait = {
		character = scope:sex_partner
		animation = love
	}
	
	#Yes
	option = {
		name = witch.3017.a
		witch_3017_soulmate_sex_effect = yes
	}

	#No
	option = {
		name = witch.3017.b
		custom_tooltip = witch.3015.b.tt

		reverse_add_opinion = {
			target = scope:sex_partner
			modifier = disappointed_opinion
			opinion = -15
		}
	}
}


###Grand rite end events##

#End for host
witch.3098 = { #by Mathilda Bjarnehed
	type = activity_event
	title = witch.3098.t
	desc = {
		desc = witch.3098.start.desc
		desc = witch.3098.end.desc
	}
	theme = witchcraft
	override_background = {
		reference = bp1_bonfire
	}
	left_portrait = root

	immediate = {
		capital_province = { save_scope_as = background_wilderness_scope }
	}
	
	option = {
		name = witch.3098.a
	}
}

#End for guest
witch.3099 = { #by Mathilda Bjarnehed
	type = activity_event
	title = witch.3098.t
	desc = {
		desc = witch.3099.start.desc
		desc = witch.3098.end.desc
	}
	theme = witchcraft
	override_background = {
		reference = bp1_bonfire
	}
	left_portrait = root
	
	option = {
		name = witch.3098.a
		custom_tooltip = witch.3099.tt
	}
}



########################
# WITCH ONGOING EVENTS #
########################

### Court chaplain / other clergy is an idiot ###

scripted_trigger witch_4001_annoying_clergy_trigger = {
	OR = {
		has_council_position = councillor_court_chaplain
		is_clergy = yes
	}
	ai_zeal >= medium_negative_ai_value
	NOR = {
		is_close_family_of = root
		has_relation_friend = root
		has_relation_lover = root
		opinion = {
			target = root
			value >= medium_positive_opinion
		}
		any_secret = {
			type = secret_non_believer
		}
	}
	is_ai = yes
	faith = root.faith
}

scripted_effect witch_4001_prank_success_effect = {
	add_character_modifier = {
		modifier = trickster_modifier
		years = 10
	}
	stress_impact = {
		base = medium_stress_impact_loss
		compassionate = minor_stress_impact_gain
		honest = minor_stress_impact_gain
		forgiving = minor_stress_impact_gain
		vengeful = minor_stress_impact_loss
		sadistic = medium_stress_impact_loss
		deceitful = minor_stress_impact_loss
	}
	scope:annoying_clergy = {
		add_prestige = medium_prestige_loss
	}
}

scripted_effect witch_4001_corruption_success_effect = {
	scope:annoying_clergy = {
		add_secret = {
			type = secret_non_believer
		}
		random_secret = {
			type = secret_non_believer
			reveal_to = root
		}
		custom_tooltip = witch_4001_corruption_success_effect.tt
	}
}

scripted_trigger witch_4001_desc_valid_sin_trigger = {
	faith = { trait_is_sin = $TRAIT$ }
	NOT = {
		scope:annoying_clergy = { has_trait = $TRAIT$ }
	}
}

scripted_trigger witch_4001_desc_prefered_sin_trigger = {
	witch_4001_desc_valid_sin_trigger = { TRAIT = $TRAIT$ }
	has_trait = $TRAIT$
}

scripted_trigger witch_4001_zeal_condition_trigger = {
	OR = {
		ai_zeal <= high_negative_zeal
		AND = {
			num_sinful_traits >= 1		
			ai_zeal < 0
		}
	}
}

scripted_trigger witch_4001_event_available_trigger = {
	NOT = { has_character_flag = event_cooldown_witch_4001 }
	OR = {
		trigger_if = {
			limit = { exists = cp:councillor_court_chaplain }
			cp:councillor_court_chaplain = { witch_4001_annoying_clergy_trigger = yes }
		}
		trigger_if = {
			limit = { is_landed = no }
			any_courtier = {
				witch_4001_annoying_clergy_trigger = yes
			}
		}
		trigger_else = {
			any_vassal = {
				witch_4001_annoying_clergy_trigger = yes
			}
		}
	}
}

witch.4000 = { #Pre-event to ensure witch if sent through trait-specific on-action
	hidden = yes

	trigger = {
		is_witch_trigger = yes
		witch_4001_event_available_trigger = yes
	}

	immediate = {
		trigger_event = witch.4001
	}
}

witch.4001 = { #by Mathilda Bjarnehed
	type = character_event
	title = witch.4001.t
	desc = {
		desc = witch.4001.start.desc
		#Pick a sin
		first_valid = {
			#A sin that root has
			triggered_desc = {
				trigger = { witch_4001_desc_prefered_sin_trigger = { TRAIT = forgiving } }
				desc = witch.4001.forgiving.desc
			}
			triggered_desc = {
				trigger = { witch_4001_desc_prefered_sin_trigger = { TRAIT = deceitful } }
				desc = witch.4001.deceitful.desc
			}
			triggered_desc = {
				trigger = { witch_4001_desc_prefered_sin_trigger = { TRAIT = gluttonous } }
				desc = witch.4001.gluttonous.desc
			}
			triggered_desc = {
				trigger = { witch_4001_desc_prefered_sin_trigger = { TRAIT = wrathful } }
				desc = witch.4001.wrathful.desc
			}
			triggered_desc = {
				trigger = { witch_4001_desc_prefered_sin_trigger = { TRAIT = greedy } }
				desc = witch.4001.greedy.desc
			}
			triggered_desc = {
				trigger = { witch_4001_desc_valid_sin_trigger = { TRAIT = arbitrary } }
				desc = witch.4001.arbitrary.desc
			}
			triggered_desc = {
				trigger = {
					OR = {
						witch_4001_desc_prefered_sin_trigger = { TRAIT = sadistic }
						witch_4001_desc_prefered_sin_trigger = { TRAIT = callous }
					}
				}
				desc = witch.4001.sadistic.desc
			}
			triggered_desc = {
				trigger = { witch_4001_desc_prefered_sin_trigger = { TRAIT = craven } }
				desc = witch.4001.craven.desc
			}
			triggered_desc = {
				trigger = { witch_4001_desc_prefered_sin_trigger = { TRAIT = lustful } }
				desc = witch.4001.lustful.desc
			}
			triggered_desc = {
				trigger = { witch_4001_desc_prefered_sin_trigger = { TRAIT = vengeful } }
				desc = witch.4001.vengeful.desc
			}
			triggered_desc = {
				trigger = { witch_4001_desc_prefered_sin_trigger = { TRAIT = arrogant } }
				desc = witch.4001.arrogant.desc
			}
			#A sin that root doesn't have
			random_valid = {
				triggered_desc = {
					trigger = { witch_4001_desc_valid_sin_trigger = { TRAIT = forgiving } }
					desc = witch.4001.forgiving.desc
				}
				triggered_desc = {
					trigger = { witch_4001_desc_valid_sin_trigger = { TRAIT = deceitful } }
					desc = witch.4001.deceitful.desc
				}
				triggered_desc = {
					trigger = { witch_4001_desc_valid_sin_trigger = { TRAIT = gluttonous } }
					desc = witch.4001.gluttonous.desc
				}
				triggered_desc = {
					trigger = { witch_4001_desc_valid_sin_trigger = { TRAIT = wrathful } }
					desc = witch.4001.wrathful.desc
				}
				triggered_desc = {
					trigger = { witch_4001_desc_valid_sin_trigger = { TRAIT = greedy } }
					desc = witch.4001.greedy.desc
				}
				triggered_desc = {
					trigger = { witch_4001_desc_valid_sin_trigger = { TRAIT = arbitrary } }
					desc = witch.4001.arbitrary.desc
				}
				triggered_desc = {
					trigger = {
						OR = {
							witch_4001_desc_valid_sin_trigger = { TRAIT = sadistic }
							witch_4001_desc_valid_sin_trigger = { TRAIT = callous }
						}
					}
					desc = witch.4001.sadistic.desc
				}
				triggered_desc = {
					trigger = { witch_4001_desc_valid_sin_trigger = { TRAIT = craven } }
					desc = witch.4001.craven.desc
				}
				triggered_desc = {
					trigger = { witch_4001_desc_valid_sin_trigger = { TRAIT = lustful } }
					desc = witch.4001.lustful.desc
				}
				triggered_desc = {
					trigger = { witch_4001_desc_valid_sin_trigger = { TRAIT = vengeful } }
					desc = witch.4001.vengeful.desc
				}
				triggered_desc = {
					trigger = { witch_4001_desc_valid_sin_trigger = { TRAIT = arrogant } }
					desc = witch.4001.arrogant.desc
				}
			}
			desc = witch.4001.fallback.desc
		}
		first_valid = {
			triggered_desc = {
				trigger = { is_witch_trigger = yes }
				desc = witch.4001.witch.desc
			}
			desc = witch.4001.impious.desc
		}
	}
	theme = faith
	override_icon = {
		trigger = { is_witch_trigger = yes }
		reference = "gfx/interface/icons/event_types/type_medicine.dds"
	}
	left_portrait = scope:annoying_clergy
	
	trigger = {
		OR = {
			witch_4001_zeal_condition_trigger = yes
			is_witch_trigger = yes
		}
		witch_4001_event_available_trigger = yes
	}

	weight_multiplier = {
		base = 0.2
		modifier = {
			is_witch_trigger = yes
			add = 0.8
		}
		modifier = {
			num_sinful_traits >= 1	
			add = 0.4
		}
	}

	immediate = {
		add_character_flag = event_cooldown_witch_4001
		if = {
			limit = {
				exists = cp:councillor_court_chaplain
				cp:councillor_court_chaplain = { witch_4001_annoying_clergy_trigger = yes }
			}
			cp:councillor_court_chaplain = { add_to_list = annoying_clergy_list }
		}
		if = {
			limit = { is_landed = no }
			every_courtier = {
				limit = {
					NOT = { is_in_list = annoying_clergy_list }
					witch_4001_annoying_clergy_trigger = yes
				}
				add_to_list = annoying_clergy_list
			}
		}
		else = {
			every_vassal = {
				limit = {
					NOT = { is_in_list = annoying_clergy_list }
					witch_4001_annoying_clergy_trigger = yes
				}
				add_to_list = annoying_clergy_list
			}
		}


		random_in_list = {
			list = annoying_clergy_list
			weight = {
				base = 30
				modifier = {
					OR = {
						is_councillor = yes
						is_powerful_vassal = yes
					}
					add = 150
				}
				opinion_modifier = {
					opinion_target = root
					multiplier = -1
					min = -25
				}
				modifier = {
					add = {
						value = ai_zeal
						divide = 2
					}
				}
			}
			save_scope_as = annoying_clergy
		}

		capital_province = { save_scope_as = capital }
	}

	#Make a fool of them
	option = {
		name = witch.4001.a
		flavor = witch.4001.a.tt
		
		duel = {
			skill = intrigue
			target = scope:annoying_clergy
			desc = outcome_in_a_few_days

			60 = {
				desc = witch.4001.a.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
				}
				show_as_tooltip = { witch_4001_prank_success_effect = yes }
				trigger_event = {
					id = witch.4002
					days = 3
				}
			}
			40 = {
				desc = witch.4001.a.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -2
				}
				send_interface_toast = {
					title = witch.4001.a.failure
					left_icon = scope:annoying_clergy
					reverse_add_opinion = {
						target = scope:annoying_clergy
						modifier = angry_opinion
						opinion = -10
					}
				}
			}
		}

		stress_impact = {
			compassionate = minor_stress_impact_gain
			honest = minor_stress_impact_gain
			forgiving = minor_stress_impact_gain
			craven = minor_stress_impact_gain
		}

	}

	#Impress them
	option = {
		name = witch.4001.c

		reverse_add_opinion = {
			target = scope:annoying_clergy
			modifier = pious_opinion
			opinion = 20
		}
		add_piety = minor_piety_gain

		stress_impact = {
			honest = minor_stress_impact_gain
			cynical = minor_stress_impact_gain
		}
	}

	#Turn them around
	option = {
		name = witch.4001.b

		duel = {
			desc = outcome_in_a_few_weeks
			skill = learning
			target = scope:annoying_clergy

			30 = {
				desc = witch.4001.b.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3
				}
				show_as_tooltip = { witch_4001_corruption_success_effect = yes }

				trigger_event = {
					id = witch.4003
					days = { 7 14 }
				}
			}
			20 = {
				desc = witch.4001.b.neutral
				compare_modifier = {
					value = scope:duel_value
					multiplier = 1
				}
				custom_tooltip = witch.4001.b.neutral.tt
				trigger_event = {
					id = witch.4004
					days = { 7 14 }
				}
			}
			50 = {
				desc = witch.4001.b.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3
				}
				trigger_event = {
					id = witch.4005
					days = { 7 14 }
				}
				modifier = {
					add = {
						value = scope:annoying_clergy.ai_zeal
						divide = 2
					}
				}
			}
		}
	}
}


#You made a fool out of them!
witch.4002 = { #by Mathilda Bjarnehed
	type = character_event
	title = witch.4001.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { is_witch_trigger = yes }
				desc = witch.4002.witch.desc
			}
			desc = witch.4002.impious.desc
		}
		first_valid = {
			#A sin
			triggered_desc = {
				trigger = {
					faith = { trait_is_sin = gluttonous }
					NOT = { scope:annoying_clergy = { has_trait = temperate } }
				}
				desc = witch.4002.gluttonous.desc
			}
			triggered_desc = {
				trigger = {
					OR = {
						faith = { trait_is_sin = wrathful }
						faith = { trait_is_sin = drunkard }
					}
				}
				desc = witch.4002.wrathful.desc
			}
			triggered_desc = {
				trigger = {
					OR = {
						faith = { trait_is_sin = sadistic }
						faith = { trait_is_sin = callous }
						faith = { trait_is_sin = vengeful }
					}
					NOR = {
						NOT = { scope:annoying_clergy = { has_trait = compassionate } }
						NOT = { scope:annoying_clergy = { has_trait = forgiving } }
					}
					exists = scope:vengeful_desc
				}
				desc = witch.4002.vengeful.desc
			}
			triggered_desc = {
				trigger = {
					faith = { trait_is_sin = craven }
					NOT = { scope:annoying_clergy = { has_trait = brave } }
				}
				desc = witch.4002.craven.desc
			}
			triggered_desc = {
				trigger = {
					faith = { trait_is_sin = lustful }
					exists = scope:lustful_desc
				}
				desc = witch.4002.lustful.desc
			}
			triggered_desc = {
				trigger = {
					faith = { trait_is_sin = arrogant }
					NOT = { scope:annoying_clergy = { has_trait = humble } }
				}
				desc = witch.4002.arrogant.desc
			}
			#Not sins but it still looks bad
			random_valid = {	
				triggered_desc = {
					trigger = { NOT = { scope:annoying_clergy = { has_trait = temperate } } }
					desc = witch.4002.gluttonous.desc
				}
				triggered_desc = {
					trigger = { exists = scope:lustful_desc }
					desc = witch.4002.lustful.desc
				}
				triggered_desc = {
					trigger = {
						NOR = {
							NOT = { scope:annoying_clergy = { has_trait = compassionate } }
							NOT = { scope:annoying_clergy = { has_trait = forgiving } }
						}
						exists = scope:vengeful_desc
					}
				}
				triggered_desc = {
					trigger = { NOT = { scope:annoying_clergy = { has_trait = humble } } }
					desc = witch.4002.arrogant.desc
				}
				desc = witch.4002.wrathful.desc
			}

		}
		desc = witch.4002.end.desc
	}
	theme = faith
	override_icon = {
		trigger = { is_witch_trigger = yes }
		reference = "gfx/interface/icons/event_types/type_medicine.dds"
	}
	left_portrait = scope:annoying_clergy
	
	trigger = {
		exists = scope:annoying_clergy
	}

	immediate = {
		witch_4001_prank_success_effect = yes
		if = {
			limit = { is_ai = no } #This is just for text
			random_courtier = {
				limit = {
					is_adult = yes
					NOR = {
						this = root
						this = scope:annoying_clergy
						is_consort_of = scope:annoying_clergy
						has_relation_lover = scope:annoying_clergy
					}
					scope:annoying_clergy = { is_attracted_to_gender_of = prev }
				}
				save_scope_as = lustful_desc
			}
			random_courtier = {
				limit = {
					is_adult = yes
					NOR = {
						this = root
						this = scope:annoying_clergy
					}
				}
				save_scope_as = vengeful_desc
			}
			scope:annoying_clergy = {
				romance_target_gender_effect = { SCOPE_NAME = wrathful_desc }
			}
		}
	}

	option = {
		name = witch.4002.a

	}
}


#You corrupted them!
witch.4003 = { #by Mathilda Bjarnehed
	type = character_event
	title = witch.4001.t
	desc = witch.4003.desc
	theme = faith
	override_icon = {
		trigger = { is_witch_trigger = yes }
		reference = "gfx/interface/icons/event_types/type_medicine.dds"
	}
	left_portrait = scope:annoying_clergy
	
	trigger = {
		exists = scope:annoying_clergy
	}

	immediate = {
		witch_4001_corruption_success_effect = yes

		if = {
			limit = {
				is_witch_trigger = yes
				NOT = { scope:annoying_clergy = { is_witch_trigger = yes } }
			}
			random = {
				chance = 30
				save_scope_value_as = {
					name = witch_options
					value = yes
				}
			}
		}
	}

	#Great!
	option = {
		name = witch.4003.a

	}

	#Yes, make them a witch!
	option = {
		trigger = { exists = scope:witch_options }
		name = witch.4003.b
		trait = witch

		scope:annoying_clergy = {
			give_witch_secret_or_trait_effect = yes
			random_secret = {
				type = secret_witch
				reveal_to = root
			}
		}
	}


	#Yes, make them a witch and tell them about me!
	option = {
		trigger = {
			exists = scope:witch_options
			any_secret = {
				type = secret_witch
				NOT = { is_known_by = scope:annoying_clergy }
			}
		}
		name = witch.4003.c
		trait = witch

		scope:annoying_clergy = {
			give_witch_secret_or_trait_effect = yes
			random_secret = {
				type = secret_witch
				reveal_to = root
			}
		}

		random_secret = {
			type = secret_witch
			reveal_to = scope:annoying_clergy
		}

		reverse_add_opinion = {
			modifier = respect_opinion
			opinion = 20
			target = scope:annoying_clergy
		}
	}
}

#You're nearly there...
witch.4004 = { #by Mathilda Bjarnehed
	type = character_event
	title = witch.4001.t
	desc = witch.4004.desc
	theme = faith
	override_icon = {
		trigger = { is_witch_trigger = yes }
		reference = "gfx/interface/icons/event_types/type_medicine.dds"
	}
	left_portrait = scope:annoying_clergy
	
	trigger = {
		exists = scope:annoying_clergy
	}

	#Keep trying!
	option = {
		name = witch.4004.a

		stress_impact = {
			base = major_stress_impact_gain
			diligent = medium_stress_impact_loss
			lazy = minor_stress_impact_gain
		}

		random_list = {
			desc = outcome_in_a_few_days
			85 = {
				desc = witch.4001.b.success
				show_as_tooltip = {
					witch_4001_corruption_success_effect = yes
				}
				trigger_event = {
					id = witch.4003
					days = 3
				}
			}
			15 = {
				desc = witch.4001.b.failure
				trigger_event = {
					id = witch.4005
					days = 3
				}
			}
		}


		ai_chance = {
			base = 50
		}
	}

	#Give up
	option = {
		name = witch.4004.b

		ai_chance = {
			base = 50
		}
	}
}

#Corruption failed
witch.4005 = { #by Mathilda Bjarnehed
	type = character_event
	title = witch.4001.t
	desc = witch.4005.desc
	theme = faith
	override_icon = {
		trigger = { is_witch_trigger = yes }
		reference = "gfx/interface/icons/event_types/type_medicine.dds"
	}
	left_portrait = scope:annoying_clergy
	
	trigger = {
		exists = scope:annoying_clergy
	}

	option = {
		name = witch.4005.a
	}
}


### PERSONAL WITCH RITUAL ###

scripted_effect witch_4010_option_effect = {
	random_list = {
		#DIPLOMACY
		10 = {
			trigger = {
				NOR = {
					exists = scope:confident_diplomat
					has_character_modifier = confident_diplomat
				}
			}
			modifier = {
				has_lifestyle = diplomacy_lifestyle
				add = 30
			}
			modifier = {
				add = {	
					value = extremely_high_skill_rating
					subtract = diplomacy
					multiply = 2
				}
			}
			save_scope_value_as = {
				name = confident_diplomat
				value = yes
			}
		}

		#MARTIAL
		10 = {
			trigger = {
				NOR = {
					exists = scope:confident_strategist
					has_character_modifier = confident_strategist
				}
			}
			modifier = {
				has_lifestyle = martial_lifestyle
				add = 30
			}
			modifier = {
				add = {	
					value = extremely_high_skill_rating
					subtract = martial
					multiply = 2
				}
			}
			save_scope_value_as = {
				name = confident_strategist
				value = yes
			}
		}

		#STEWARDSHIP
		10 = {
			trigger = {
				NOR = {
					exists = scope:confident_organizer
					has_character_modifier = confident_organizer
				}
			}
			modifier = {
				has_lifestyle = stewardship_lifestyle
				add = 30
			}
			modifier = {
				add = {	
					value = extremely_high_skill_rating
					subtract = stewardship
					multiply = 2
				}
			}
			save_scope_value_as = {
				name = confident_organizer
				value = yes
			}
		}

		#INTRIGUE
		10 = {
			trigger = {
				NOR = {
					exists = scope:confident_schemer
					has_character_modifier = confident_schemer
				}
			}
			modifier = {
				has_lifestyle = intrigue_lifestyle
				add = 30
			}
			modifier = {
				add = {	
					value = extremely_high_skill_rating
					subtract = intrigue
					multiply = 2
				}
			}
			save_scope_value_as = {
				name = confident_schemer
				value = yes
			}
		}

		#LEARNING
		10 = {
			trigger = {
				NOR = {
					exists = scope:confident_scholar
					has_character_modifier = confident_scholar
				}
			}
			modifier = {
				has_lifestyle = learning_lifestyle
				add = 30
			}
			modifier = {
				add = {	
					value = extremely_high_skill_rating
					subtract = learning
					multiply = 2
				}
			}
			save_scope_value_as = {
				name = confident_scholar
				value = yes
			}
		}

		#PROWESS
		10 = {
			trigger = {
				NOR = {
					exists = scope:confident_duelist
					has_character_modifier = confident_duelist
				}
			}
			modifier = {
				has_focus = martial_chivalry_focus
				add = 30
			}
			modifier = {
				add = {	
					value = extremely_high_skill_rating
					subtract = prowess
					multiply = 2
				}
			}
			save_scope_value_as = {
				name = confident_duelist
				value = yes
			}
		}

		#ATTRACTION
		20 = {
			trigger = {
				NOR = {
					exists = scope:alluring_confidence
					has_character_modifier = alluring_confidence
				}
			}
			modifier = {
				OR = {
					has_trait = lustful
					ai_sociability >= low_positive_ai_value
					has_focus = intrigue_temptation_focus
				}
				add = 50
			}
			save_scope_value_as = {
				name = alluring_confidence
				value = yes
			}
		}

		#RELAXATION
		20 = {
			trigger = {
				stress >= low_stress
				NOT = { exists = scope:stress }
			}
			modifier = {
				add = {
					value = stress
					divide = extremely_high_stress
					multiply = 80
				}
			}
			save_scope_value_as = {
				name = stress
				value = yes
			}
		}
	}
}


witch.4010 = { #by Mathilda Bjarnehed
	type = character_event
	title = witch.4010.t
	desc = witch.4010.desc
	theme = witchcraft
	override_background = {
		reference = wilderness
	}
	left_portrait = root
	
	trigger = {
		NOT = { has_character_flag = event_cooldown_witch_4010 }
		is_witch_trigger = yes
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		add_character_flag = {
			flag = event_cooldown_witch_4010
			days = 1825
		}

		#3 options
		witch_4010_option_effect = yes
		witch_4010_option_effect = yes
		witch_4010_option_effect = yes	
	}

	#Ask for love
	option = {
		trigger = { exists = scope:alluring_confidence }
		name = witch.4010.a

		add_character_modifier = {
			modifier = alluring_confidence
			years = 10
		}
	}

	#Ask for diplomacy
	option = {
		trigger = { exists = scope:confident_diplomat }
		name = witch.4010.b

		add_character_modifier = {
			modifier = confident_diplomat
			years = 10
		}
	}

	#Ask for martial
	option = {
		trigger = { exists = scope:confident_strategist }
		name = witch.4010.c

		add_character_modifier = {
			modifier = confident_strategist
			years = 10
		}
	}

	#Ask for stewardship
	option = {
		trigger = { exists = scope:confident_organizer }
		name = witch.4010.d

		add_character_modifier = {
			modifier = confident_organizer
			years = 10
		}
	}

	#Ask for intrigue
	option = {
		trigger = { exists = scope:confident_schemer }
		name = witch.4010.e

		add_character_modifier = {
			modifier = confident_schemer
			years = 10
		}
	}

	#Ask for learning
	option = {
		trigger = { exists = scope:confident_scholar }
		name = witch.4010.f

		add_character_modifier = {
			modifier = confident_scholar
			years = 10
		}
	}

	#Ask for prowess
	option = {
		trigger = { exists = scope:confident_duelist }
		name = witch.4010.g

		add_character_modifier = {
			modifier = confident_duelist
			years = 10
		}
	}
	
	#Ask for relaxation
	option = {
		trigger = { exists = scope:stress }
		name = witch.4010.h
		
		add_stress = monumental_stress_loss
	}
}


########################
# WITCH FRIEND: PRAYER #
########################

scripted_trigger witch_4020_prayer_friend_trigger = {
	this != root
	potential_witch_friend_trigger = { CHARACTER = root }
	NOT = { is_in_list = prayer_witches }
	basic_is_available_ai = yes
	OR = {
		has_relation_potential_friend = root
		opinion = {
			target = root
			value >= low_positive_opinion
		}
	}
}

witch.4020 = { #by Mathilda Bjarnehed
	type = character_event
	title = witch.4020.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:prayer_witch_2 }
				desc = witch.4020.two_witches.desc
			}
			desc = witch.4020.one_witch.desc
		}
		random_valid = {
			desc = witch.4020.full_moon.desc
			desc = witch.4020.new_moon.desc
			desc = witch.4020.equinox.desc
			desc = witch.4020.solstice.desc
		}
		desc = witch.4020.end.desc
	}
	theme = witchcraft
	override_background = {
		reference = wilderness
	}
	left_portrait = scope:prayer_witch_1
	right_portrait = scope:prayer_witch_2
	
	trigger = {
		OR = {
			any_known_secret = {
				secret_owner = {
					this != root # Don't include our own secrets!
					witch_4020_prayer_friend_trigger = yes
				}
			}
			any_relation = {
				type = potential_friend
				witch_4020_prayer_friend_trigger = yes
			}
			any_close_or_extended_family_member = { witch_4020_prayer_friend_trigger = yes }
			any_vassal = { witch_4020_prayer_friend_trigger = yes }
			any_courtier_or_guest = { witch_4020_prayer_friend_trigger = yes }
			any_consort = { witch_4020_prayer_friend_trigger = yes }
		}
		NOR = {
			has_character_modifier = clear_mind_modifier
			has_character_flag = event_cooldown_witch_4020
		}
	}


	immediate = {
		add_character_flag = {
			flag = event_cooldown_witch_4020
			years = 15
		}
		every_known_secret = {
			limit = {
				secret_owner = {
					witch_4020_prayer_friend_trigger = yes
					this != root
				}
			}
			secret_owner = { add_to_list = prayer_witches }
		}
		every_relation = {
			type = potential_friend
			limit = { witch_4020_prayer_friend_trigger = yes }
			add_to_list = prayer_witches
		}
		every_close_or_extended_family_member = {
			limit = { witch_4020_prayer_friend_trigger = yes }
			add_to_list = prayer_witches
		}
		every_vassal = {
			limit = { witch_4020_prayer_friend_trigger = yes }
			add_to_list = prayer_witches
		}
		every_courtier_or_guest = {
			limit = { witch_4020_prayer_friend_trigger = yes }
			add_to_list = prayer_witches
		}
		every_consort = {
			limit = { witch_4020_prayer_friend_trigger = yes }
			add_to_list = prayer_witches
		}

		# Pick two
		random_in_list = {
			list = prayer_witches

			weight = {
				base = 1

				compatibility_modifier = {
					compatibility_target = root
				}
				opinion_modifier = {
					opinion_target = root
				}
				ai_value_modifier = {
					ai_sociability = 0.5
					ai_compassion = 0.2
					ai_boldness = 0.2
				}
				modifier = {
					has_relation_potential_friend = root
					add = 100
				}
			}
			save_scope_as = prayer_witch_1
		}

		if = {
			limit = { exists = scope:prayer_witch_2 }
			random_in_list = {
				list = prayer_witches
				limit = { this != scope:prayer_witch_1 }
				weight = {
					base = 1

					compatibility_modifier = {
						compatibility_target = root
					}
					opinion_modifier = {
						opinion_target = root
					}
					ai_value_modifier = {
						ai_sociability = 0.5
						ai_compassion = 0.2
						ai_boldness = 0.2
					}
					modifier = {
						has_relation_potential_friend = root
						add = 100
					}
				}
				save_scope_as = prayer_witch_2
			}
		}
	}

	# Pray for prayer_witch_1
	option = {
		name = witch.4020.a
		
		progress_towards_friend_effect = { CHARACTER = scope:prayer_witch_1 REASON = friend_prayed_for_witch OPINION = default_friend_opinion }
		scope:prayer_witch_1 = {
			add_character_modifier = {
				modifier = clear_mind_modifier
				years = 10
			}
		}

		stress_impact = {
			greedy = minor_stress_impact_gain
			ambitious = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_greed = -1
				ai_compassion = -0.5
				ai_honor = -0.5
			}
			opinion_modifier = {
				opinion_target = scope:prayer_witch_1
			}
		}
	}

	# Pray for prayer_witch_2
	option = {
		name = witch.4020.b
		trigger = { exists = scope:prayer_witch_2 }

		progress_towards_friend_effect = { CHARACTER = scope:prayer_witch_2 REASON = friend_prayed_for_witch OPINION = default_friend_opinion }
		scope:prayer_witch_2 = {
			add_character_modifier = {
				modifier = clear_mind_modifier
				years = 10
			}
		}

		stress_impact = {
			greedy = minor_stress_impact_gain
			ambitious = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_greed = -1
				ai_compassion = -0.5
				ai_honor = -0.5
			}
			opinion_modifier = {
				opinion_target = scope:prayer_witch_2
			}
		}
	}
	
	# Pray for me!
	option = {
		name = witch.4020.c

		add_character_modifier = {
			modifier = clear_mind_modifier
			years = 10
		}

		stress_impact = {
			base = minor_stress_impact_loss # It's not be be prayed for
			generous = minor_stress_impact_gain
			shy = minor_stress_impact_gain
			craven = minor_stress_impact_gain
			content = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 2
				ai_compassion = -1
				ai_honor = -1
			}
		}
	}
}


#############
# RARE BOOK #
#############

scripted_trigger witch_4030_friend_trigger = {
	potential_witch_friend_trigger = { CHARACTER = root }
	basic_is_available_ai = yes
	is_adult = yes
	learning >= decent_skill_rating
}

scripted_trigger witch_4030_convince_trigger = {
	is_witch_trigger = no
	is_adult = yes
	basic_is_available_ai = yes
}

scripted_effect witch_4030_convince_success_effect = {
	save_scope_as = book_recipient
	give_witch_secret_or_trait_effect = yes
	random_secret = {
		type = secret_witch
		reveal_to = root
	}
	scope:newly_created_artifact = {
		set_owner = {
			target = scope:book_recipient
			history = {
				location = root.capital_province
				actor = scope:book_holder
				recipient = scope:book_recipient
				type = given
			}
		}
	}
}

scripted_effect witch_4030_convince_failure_effect = {
	add_character_modifier = {
		modifier = on_edge_modifier
		years = 10
	}
	destroy_artifact = scope:newly_created_artifact
}

witch.4030 = { #by Mathilda Bjarnehed
	type = character_event
	title = witch.4030.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:witch_friend }
				desc = witch.4030.friend.desc
			}
			desc = witch.4030.no_friend.desc
		}
	}
	theme = witchcraft
	override_background = {
		reference = study
	}
	left_portrait = scope:left_portrait
	right_portrait = scope:right_portrait
	lower_left_portrait = scope:lower_left_portrait
	lower_right_portrait = scope:lower_right_portrait
		artifact = {
		target = scope:newly_created_artifact
		position = lower_center_portrait
	}

	trigger = {
		OR = {
			has_trait = witch
			any_secret = { type = secret_witch }
		}
		OR = {
			has_lifestyle = diplomacy_lifestyle
			has_lifestyle = martial_lifestyle
			has_lifestyle = stewardship_lifestyle
			has_lifestyle = intrigue_lifestyle
			has_lifestyle = learning_lifestyle
		}
	}

	weight_multiplier = {
		base = 1

		# Friend helping
		modifier = {
			any_relation = {
				type = friend
				witch_4030_friend_trigger = yes
			}
			add = 1
		}
		modifier = {
			any_relation = {
				type = friend
				witch_4030_friend_trigger = yes
				learning >= high_skill_rating
			}
			add = 1
		}

		#Your learning
		modifier = {
			add = {
				value = learning
				subtract = average_skill_rating
				multiply = 0.1
				min = -0.7
				max = 1
			}
		}
	}

	immediate = {
		save_scope_as = book_holder

		#Did a friend help out? Show them :)
		random_relation = {
			type = friend
			limit = { witch_4030_friend_trigger = yes }
			weight = {
				base = 1
				opinion_modifier = {
					opinion_target = root
				}
				modifier = {
					add = {
						value = learning
						multiply = 5
					}
				}
			}
			save_scope_as = witch_friend
		}

		# Who can we convert? Pick two
		every_scheme = {
			type = convert_to_witchcraft
			limit = {
				scheme_target_character = { witch_4030_convince_trigger = yes }
			}
			scheme_target_character = { add_to_list = convince }
		}
		every_vassal = {	
			limit = { witch_4030_convince_trigger = yes }
			add_to_list = convince
		}
		every_councillor = {
			limit = { witch_4030_convince_trigger = yes }
			add_to_list = convince
		}
		every_spouse = {
			limit = { witch_4030_convince_trigger = yes }
			add_to_list = convince
		}
		every_close_or_extended_family_member = {
			limit = { witch_4030_convince_trigger = yes }
			add_to_list = convince
		}

		random_in_list = {
			list = convince
			limit = {
				save_temporary_scope_as = convert_target
				root = {
					any_scheme = {
						type = convert_to_witchcraft
						scheme_target_character = scope:convert_target
					}
				}
			}
			alternative_limit = { always = yes }

			weight = {
				base = 1
				ai_value_modifier = {
					ai_greed = 1
					ai_rationality = 1
				}
				modifier = {
					add = {
						value = learning
						multiply = 5
					}
				}
				modifier = {
					OR = {
						is_powerful_vassal_of = root
						is_councillor_of = root
						AND = {
							exists = root.house
							root.house = { NOT = { has_house_modifier = witch_coven } }
							house ?= root.house
						}	
					}
					add = 50
				}
			}
			save_scope_as = convince_target_1
		}

		if = {
			limit = { exists = scope:convince_target_1 }
			random_in_list = {
				list = convince
				limit = {
					this != scope:convince_target_1
				}

				weight = {
					base = 1
					ai_value_modifier = {
						ai_greed = 1
						ai_rationality = 1
					}
					modifier = {
						add = {
							value = learning
							multiply = 5
						}
					}
					modifier = {
						OR = {
							is_powerful_vassal_of = root
							is_councillor_of = root
							AND = {
								exists = root.house
								root.house = { NOT = { has_house_modifier = witch_coven } }
								house ?= root.house
							}	
						}
						add = 50
					}
				}
				save_scope_as = convince_target_2
			}
		}

		#Save portraits
		if = {
			limit = {
				exists = scope:witch_friend
				exists = scope:convince_target_2
			}
			scope:witch_friend = { save_scope_as = left_portrait }
			scope:convince_target_1 = { save_scope_as = lower_left_portrait }
			scope:convince_target_2 = { save_scope_as = lower_right_portrait }
		}
		else_if = {
			limit = {
				exists = scope:witch_friend
				exists = scope:convince_target_1
			}
			scope:witch_friend = { save_scope_as = left_portrait }
			scope:convince_target_1 = { save_scope_as = right_portrait }
		}
		else_if = {
			limit = { exists = scope:witch_friend }
			scope:witch_friend = { save_scope_as = left_portrait }
		}
		else_if = {
			limit = {
				exists = scope:convince_target_1
				exists = scope:convince_target_2
			}
			scope:convince_target_1 = { save_scope_as = left_portrait }
			scope:convince_target_2 = { save_scope_as = right_portrait }
		}
		else_if = {
			limit = { exists = scope:convince_target_1 }
			scope:convince_target_1 = { save_scope_as = left_portrait }
		}
		set_variable = {
			name = book_subject_witch_scope
			value = root
		}
		save_temporary_scope_value_as = {
			name = should_be_trinket
			value = yes
		}
		if = {
			limit = { exists = scope:witch_friend }
			create_artifact_book_effect = { #using effect to ensure that scope:owner is set properly
				OWNER = root
				CREATOR = scope:witch_friend
				SET_SUBJECT = flag:witch
				SET_TOPIC = flag:worship_horned_god
			}
		}
		else = {
			hidden_effect = {
				random_dummy_gender_effect = yes
			}
			create_artifact_book_effect = { #using effect to ensure that scope:owner is set properly
				OWNER = root
				CREATOR = scope:dummy_gender
				SET_SUBJECT = flag:witch
				SET_TOPIC = flag:worship_horned_god
			}
		}
		remove_variable = book_subject_witch_scope
	}

	# Study the book for perk together
	option = {
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = { exists = scope:witch_friend }
						desc = witch.4030.friend.a
					}
					desc = witch.4030.no_friend.a
				}
			}
		}
						

		if = {
			limit = { has_lifestyle = diplomacy_lifestyle }
			add_diplomacy_lifestyle_perk_points = 1
		}
		else_if = {
			limit = { has_lifestyle = martial_lifestyle }
			add_martial_lifestyle_perk_points = 1
		}
		else_if = {
			limit = { has_lifestyle = stewardship_lifestyle }
			add_stewardship_lifestyle_perk_points = 1
		}
		else_if = {
			limit = { has_lifestyle = intrigue_lifestyle }
			add_intrigue_lifestyle_perk_points = 1
		}
		else_if = {
			limit = { has_lifestyle = learning_lifestyle }
			add_learning_lifestyle_perk_points = 1
		}
		
		if = {
			limit = { exists = scope:witch_friend }
			scope:witch_friend = {
				if = {
					limit = { root = { has_lifestyle = diplomacy_lifestyle } }
					add_diplomacy_lifestyle_perk_points = 1
				}
				else_if = {
					limit = { root = { has_lifestyle = martial_lifestyle } }
					add_martial_lifestyle_perk_points = 1
				}
				else_if = {
					limit = { root = { has_lifestyle = stewardship_lifestyle } }
					add_stewardship_lifestyle_perk_points = 1
				}
				else_if = {
					limit = { root = { has_lifestyle = intrigue_lifestyle } }
					add_intrigue_lifestyle_perk_points = 1
				}
				else_if = {
					limit = { root = { has_lifestyle = learning_lifestyle } }
					add_learning_lifestyle_perk_points = 1
				}
			}
		}
		else = {
			add_stress = medium_stress_gain # No friend means working harder
		}
		show_as_tooltip = {
			scope:newly_created_artifact = { set_owner = root }
		}
	}

	# Sell it to other witches and share profit
	option = {
		name = witch.4030.b

		add_gold = medium_gold_value

		if = {
			limit = { exists = scope:witch_friend }
			scope:witch_friend = { add_gold = root.medium_gold_value }
		}
		destroy_artifact = scope:newly_created_artifact

	}

	# use it to convince someone (option 1)
	option = {
		trigger = { exists = scope:convince_target_1 }
		name = witch.4030.c

		scope:convince_target_1 = { save_scope_as = convince_target }

		random_list = {
			desc = outcome_in_a_few_days
			55 = {
				desc = witch.4030.c.success
				ai_value_modifier = {
					who = scope:convince_target_1
					ai_zeal = -0.5
					ai_greed = 0.5
					ai_rationality = 0.5
				}
				modifier = {
					add = {
						value = scope:convince_target_1.learning
						multiply = 2
					}
				}
				trigger_event = {
					id = witch.4031
					days = 3
				}
				show_as_tooltip = { scope:convince_target_1 = { witch_4030_convince_success_effect = yes } }
			}
			45 = {
				desc = witch.4030.c.failure
				ai_value_modifier = {
					who = scope:convince_target_1
					ai_zeal = 0.25
					ai_greed = -0.25
					ai_rationality = -0.25
				}
				trigger_event = {
					id = witch.4032
					days = 3
				}
				show_as_tooltip = { scope:convince_target_1 = { witch_4030_convince_failure_effect = yes } }
			}
		}
	}
	
	#  use it to convince someone (option 2)
	option = {
		trigger = { exists = scope:convince_target_2 }
		name = witch.4030.d

		scope:convince_target_2 = { save_scope_as = convince_target }

		random_list = {
			desc = outcome_in_a_few_days
			55 = {
				desc = witch.4030.d.success
				ai_value_modifier = {
					who = scope:convince_target_2
					ai_zeal = -0.5
					ai_greed = 0.5
					ai_rationality = 0.5
				}
				modifier = {
					add = {
						value = scope:convince_target_2.learning
						multiply = 2
					}
				}
				trigger_event = {
					id = witch.4031
					days = 3
				}
				show_as_tooltip = { scope:convince_target_2 = { witch_4030_convince_success_effect = yes } }
			}
			45 = {
				desc = witch.4030.d.failure
				ai_value_modifier = {
					who = scope:convince_target_2
					ai_zeal = 0.25
					ai_greed = -0.25
					ai_rationality = -0.25
				}
				trigger_event = {
					id = witch.4032
					days = 3
				}
				show_as_tooltip = { scope:convince_target_2 = { witch_4030_convince_failure_effect = yes } }
			}
		}
	}
}

# Convince success
witch.4031 = { #by Mathilda Bjarnehed
	type = character_event
	title = witch.4030.t
	desc = {
		desc = witch.4031.start.desc
		desc = witch.4031.end.desc
	}
	theme = witchcraft
	left_portrait = {
		character = scope:convince_target
		animation = personality_rational
	}
	
	trigger = {
		exists = scope:convince_target
		scope:convince_target = { is_alive = yes }
	}


	option = {
		name = witch.4031.a
			scope:convince_target = { witch_4030_convince_success_effect = yes }
	}
}

# Convince failure
witch.4032 = { #by Mathilda Bjarnehed
	type = character_event
	title = witch.4030.t
		desc = {
		desc = witch.4031.start.desc
		desc = witch.4032.end.desc
	}
	theme = witchcraft
	 left_portrait = {
		character = scope:convince_target
		animation = shock
	}
	
	trigger = {
		exists = scope:convince_target
		scope:convince_target = { is_alive = yes }
	}


	option = {
		name = witch.4032.a
			scope:convince_target = { witch_4030_convince_failure_effect = yes }
	}
}




