﻿#Used for all witch executions
execute_witch_effect = {

	$VICTIM$ = {
		save_scope_as = victim
	}

	$EXECUTIONER$ = {
		save_scope_as = executioner
		save_scope_as = imprisoner #Save this scope to show correct tyranny tooltip
	}
	
	$JUDGE$ = {
		save_scope_as = judge
	}

	show_as_tooltip = {
		if = {
			limit = {
				$EXECUTIONER$.rite = { rite_has_tenet = tenet_human_sacrifice }
			}
			$VICTIM$ = {
				death = {
					death_reason = death_sacrificed_to_gods
					killer = $JUDGE$
				}
			}
		}
		else = {
			$VICTIM$ = {
				death = {
					death_reason = death_execution
					killer = $JUDGE$
				}
			}
		}
	}

	scope:executioner = {
		# Dread gain
		if = {
			limit = {
				scope:victim = {
					time_in_prison = { years > 15 } # No one even remembers who they are anymore
				}
			}
			# No dread for you
		}
		else_if = { # Executing Emperors/HoF is quite dreadful
			limit = {
				scope:victim = {
					OR = {
						highest_held_title_tier >= tier_empire
						scope:executioner.faith.religious_head = scope:victim # Your head of faith
					}
				}
			}
			add_dread = execute_interaction_massive_dread_gain
		}
		else_if = {
			limit = {
				scope:victim = {
					OR = {
						highest_held_title_tier >= tier_kingdom
						tier_or_related_liege_tier_greater_or_equal_trigger = { TIER = tier_empire }
						is_powerful_vassal_of = scope:executioner # Is your powerful vassal
						target_is_vassal_or_below = scope:executioner # Your liege/s
						is_close_family_of = scope:executioner
					}
				}
			}
			add_dread = execute_interaction_major_dread_gain
		}
		else_if = {
			limit = {
				scope:victim = {
					OR = {
						highest_held_title_tier >= tier_duchy
						tier_or_related_liege_tier_greater_or_equal_trigger = { TIER = tier_kingdom }
						AND = { # Is your vassal, and higher than Baron
							is_vassal_of = scope:executioner
							primary_title.tier > tier_barony
						}
						AND = { # Peer Vassals
							exists = primary_title
							primary_title.tier > tier_barony
							exists = liege
							liege = scope:executioner.liege
						}
						has_trait = peasant_leader
					}
				}
			}
			add_dread = execute_interaction_medium_dread_gain
		}
		else_if = {
			limit = {
				scope:victim = {
					OR = {
						highest_held_title_tier >= tier_county
						tier_or_related_liege_tier_greater_or_equal_trigger = { TIER = tier_duchy }
						is_vassal_of = scope:executioner # Is your Baron vassal
						is_close_or_extended_family_of = scope:executioner
						
						scope:executioner = { # Executing close family of your vassals is dreadful...
							any_vassal = {
								is_close_family_of = scope:victim
							}
						}
						scope:executioner = { # Executing close family of your liege/s is the same...
							any_liege_or_above = {
								is_close_family_of = scope:victim
							}
						}
					}
				}
			}
			add_dread = execute_interaction_minor_dread_gain
		}
		
		# Piety gain
		if = {
			limit = {
				faith = {
					has_doctrine_parameter = human_sacrifice_active
				}
			}
			scope:victim = {
				if = {
					limit = {
						OR = {
							highest_held_title_tier >= tier_empire
							any_close_family_member = {
								highest_held_title_tier >= tier_empire
							}
						}
					}
					scope:executioner = { add_piety = massive_piety_gain }
					scope:judge = { hidden_effect = { add_piety = major_piety_gain } }
				}
				else_if = {
					limit = {
						OR = {
							highest_held_title_tier >= tier_kingdom
							any_close_family_member = {
								highest_held_title_tier >= tier_kingdom
							}
						}
					}
					scope:executioner = { add_piety = major_piety_gain }
					scope:judge = { hidden_effect = { add_piety = medium_piety_gain } }
				}
				else_if = {
					limit = {
						OR = {
							highest_held_title_tier >= tier_duchy
							any_close_family_member = {
								highest_held_title_tier >= tier_duchy
							}
						}
					}
					scope:executioner = { add_piety = medium_piety_gain }
					scope:judge = { hidden_effect = { add_piety = minor_piety_gain } }
				}
				else = {
					scope:executioner = { add_piety = minor_piety_gain }
					scope:judge = { hidden_effect = { add_piety = minor_piety_gain } }
				}
			}
		}
		else_if = {
			limit = {
				faith = scope:victim.faith
				NOT = { has_perk = divine_retribution_perk }
				scope:victim = {
					has_no_particular_noble_roots_trigger = yes
				}
			}
			add_piety = miniscule_piety_gain
			scope:judge = { hidden_effect = { add_piety = miniscule_piety_gain } }
		}
		else_if = {
			limit = {
				faith = scope:victim.faith
				NOT = { has_perk = divine_retribution_perk }
			}
			add_piety = minor_piety_gain
			scope:judge = { hidden_effect = { add_piety = minor_piety_gain } }
		}
		
		# Stress loss
		execute_witch_stress_effect = yes
	}
	
	scope:judge = {
		hidden_effect = {
			execute_witch_stress_effect = yes
		}
	}

	execute_witch_opinion_effect = { VICTIM = scope:victim EXECUTIONER = scope:executioner JUDGE = scope:judge }
	
	#If you have the Human Sacrifice tenet, give victim an appropriate death reason
	hidden_effect = {
		if = {
			limit = {
				scope:executioner.rite = {
					rite_has_tenet = tenet_human_sacrifice
				}
			}
			$VICTIM$ = {
				death = {
					death_reason = death_sacrificed_to_gods
					killer = $JUDGE$
				}
			}
		}
		else = {
			$VICTIM$ = {
				death = {
					death_reason = death_execution
					killer = $JUDGE$
				}
			}
		}
	}
}

execute_witch_stress_effect = {
	# Stress loss
	if = {
		limit = { has_relation_rival = scope:victim }

		if = {
			limit = {
				NOR = {
					has_trait = sadistic
					has_trait = vengeful
					has_trait = compassionate
					has_trait = forgiving
				}
			}
			add_stress = medium_stress_loss
		}
		else = {
			stress_and_fulfillment_impact = {
				sadistic = major_stress_impact_loss
				vengeful = massive_stress_impact_loss
				just = minor_stress_impact_loss
				zealous = medium_stress_impact_loss
				compassionate = minor_stress_impact_gain
				forgiving = minor_stress_impact_gain
			}
		}
	}
	else_if = { #Killing infidels is relaxing
		limit = {
			has_trait = zealous
			NOT = { scope:executioner.faith = scope:victim.faith }
		}

		if = {
			limit = {
				NOR = {
					has_trait = sadistic
					has_trait = compassionate
					has_trait = forgiving
				}
			}
			add_stress = medium_stress_loss
		}
		else = {
			stress_and_fulfillment_impact = {
				sadistic = major_stress_impact_loss
				compassionate = minor_stress_impact_gain
				just = minor_stress_impact_loss
				zealous = medium_stress_impact_loss
				forgiving = minor_stress_impact_gain
			}
		}
	}
	# Stress Gain
	else_if = {
		limit = {
			NOT = { has_trait = sadistic }
			scope:victim = {
				OR = {
					is_child_of = scope:executioner
					is_grandchild_of = scope:executioner
					is_great_grandchild_of = scope:executioner
				}
			}
		}
		stress_and_fulfillment_impact = {
			base = minor_stress_impact_gain
			compassionate = massive_stress_impact_gain
			forgiving = major_stress_impact_gain
			generous = minor_stress_impact_gain
			zealous = minor_stress_impact_loss
			family_first = minor_stress_impact_gain
		}
	}
	else_if = {
		limit = {
			NOT = { has_trait = sadistic }
			scope:victim = {
				OR = {
					is_child_of = scope:executioner
					is_grandchild_of = scope:executioner
					is_great_grandchild_of = scope:executioner
				}
			}
		}
		stress_and_fulfillment_impact = {
			base = medium_stress_impact_gain
			compassionate = massive_stress_impact_gain
			forgiving = major_stress_impact_gain
			generous = medium_stress_impact_gain
			trusting = minor_stress_impact_gain
			content = minor_stress_impact_gain
			zealous = minor_stress_impact_loss
			family_first = minor_stress_impact_gain
		}
		if = {
			limit = {
				exists = scope:execution_sacrifice
				NOT = { always = scope:execution_sacrifice }
			}
			stress_and_fulfillment_impact = {
				just = medium_stress_impact_gain
			}
		}
	}
	else_if = {
		limit = {
			NOT = { has_trait = sadistic }
			scope:victim = {
				OR = {
					has_relation_friend = scope:executioner
					has_relation_lover = scope:executioner
				}
			}
		}
		stress_and_fulfillment_impact = {
			base = medium_stress_impact_gain
			compassionate = massive_stress_impact_gain
			forgiving = major_stress_impact_gain
			generous = medium_stress_impact_gain
			trusting = minor_stress_impact_gain
			zealous = minor_stress_impact_loss
			content = minor_stress_impact_gain
		}
		if = {
			limit = {
				exists = scope:execution_sacrifice
				NOT = { always = scope:execution_sacrifice }
			}
			stress_and_fulfillment_impact = {
				just = medium_stress_impact_gain
			}
		}
	}
	else = {
		stress_and_fulfillment_impact = {
			sadistic = medium_stress_impact_loss
			compassionate = medium_stress_impact_gain
			forgiving = minor_stress_impact_gain
			generous = minor_stress_impact_gain
			zealous = minor_stress_impact_loss
		}
	}
}

execute_witch_opinion_effect = {
	$VICTIM$ = {
		# Victim's non-zealous family & spouse hates executioner
		every_close_family_member = {
			limit = {
				NOR = {
					this = $EXECUTIONER$
					this = $JUDGE$
					ai_zeal >= high_positive_zeal
					has_trait = witch
				}
			}
			add_to_temporary_list = victim_family_list
		}
		every_spouse = {
			limit = {
				NOR = {
					this = $EXECUTIONER$
					this = $JUDGE$
					ai_zeal >= high_positive_zeal
					is_in_list = victim_family_list
					has_trait = witch
				}
			}
			add_to_temporary_list = victim_family_list
		}
		
		if = {
			limit = {
				any_in_list = {
					list = victim_family_list
					count > 0
				}
			}
			every_in_list = {
				list = victim_family_list
				custom = all_close_family_and_spouses
				add_opinion = {
					target = $EXECUTIONER$
					modifier = executed_close_family_witch
				}
				hidden_effect = {
					add_opinion = {
						target = $JUDGE$
						modifier = executed_close_family
					}
				}
			}
		}
		
		# Victim's friends and lovers
		every_relation = {
			type = friend
			limit = {
				NOR = {
					this = $EXECUTIONER$
					this = $JUDGE$
					is_in_list = victim_family_list
					has_trait = witch
					ai_zeal >= high_positive_zeal
				}
			}
			add_to_list = victim_close_relations_list
		}
		every_relation = {
			type = lover
			limit = {
				NOR = {
					this = $EXECUTIONER$
					this = $JUDGE$
					is_in_list = victim_family_list
					is_in_list = victim_close_relations_list
					has_trait = witch
					ai_zeal >= high_positive_zeal
				}
			}
			add_to_list = victim_close_relations_list
		}
		if = {
			limit = {
				any_in_list = {
					list = victim_close_relations_list
					always = yes
				}
			}
			every_in_list = {
				list = victim_close_relations_list
				limit = {
					NOT = { this = $EXECUTIONER$ }
				}
				custom = all_friends_and_lovers
				add_opinion = {
					target = $EXECUTIONER$
					modifier = executed_close_relation_witch
				}
				hidden_effect = {
					add_opinion = {
						target = $JUDGE$
						modifier = executed_close_relation_opinion
					}
				}
			}
		}
	}
}

witch_trial_confession_effect = {
	random_list = {
		50 = {
			modifier = {
				add = -25
				scope:accused_witch = { has_character_flag = challenge_withcraft_defiant }
			}
			modifier = {
				add = 25
				scope:accused_witch = { has_character_flag = challenge_withcraft_surrender }
			}
			modifier = {
				factor = 1.5
				scope:accused_witch = { is_ruler = yes }
			}
			modifier = {
				factor = 5
				scope:accused_witch = {
					OR = {
						is_close_family_of = scope:accuser
						is_close_family_of = scope:court_chaplain
						has_relation_best_friend = scope:accuser
						has_relation_best_friend = scope:court_chaplain
						has_relation_friend = scope:accuser
						has_relation_friend = scope:court_chaplain
						has_relation_lover = scope:court_chaplain
					}
					NOR = {
						has_relation_rival = scope:court_chaplain
						has_relation_nemesis = scope:court_chaplain
					}
				}
			}
			modifier = {
				factor = 2
				scope:accused_witch = {
					OR = {
						is_extended_family_of = scope:accuser
						is_extended_family_of = scope:court_chaplain
						AND = {
							exists = dynasty
							dynasty = scope:court_chaplain.dynasty
						}
					}
					NOR = {
						has_relation_rival = scope:court_chaplain
						has_relation_nemesis = scope:court_chaplain
					}
				}
			}
			ai_value_modifier = {
				who = scope:court_chaplain
				ai_compassion = 0.50
				ai_vengefulness = -0.25
			}
			ai_value_modifier = {
				who = scope:accused_witch
				ai_honor = 0.50
			}
			opinion_modifier = {
				who = scope:court_chaplain
				opinion_target = scope:accused_witch
				multiplier = 0.25
			}
			show_chance = no
			desc = expwitch.1022.b.believe.tt
			if = {
				limit = { scope:accused_witch = { has_no_particular_noble_roots_trigger = yes } }
				scope:accuser = {
					send_interface_message = {
						type = event_generic_good
						title = expwitch.1022.b.believe.tt
						left_icon = scope:accused_witch
						add_piety = minor_piety_gain
						scope:accused_witch = {
							remove_trait = witch
							release_from_prison = yes
							consume_all_criminal_reasons_effect = {
								LIEGE = scope:accuser
								CRIMINAL = scope:accused_witch
							}
							add_character_flag = block_convert_to_witchcraft
							hidden_effect = {
								challenge_confession_effect = yes
								remove_opinion = {
									modifier = challenged_witchcraft_opinion
									target = scope:accuser
								}
							}
						}
					}
				}
				if = {
					limit = {
						scope:accused_witch = {
							any_known_secret = {
								secret_type = secret_witch
								NOT = { is_known_by = scope:accuser }
								secret_owner = { target_is_liege_or_above = scope:accuser }
							}
						}
					}
					scope:accuser = { trigger_event = expwitch.1023 }
				}
				else = {
					challenge_cleanup_flags = yes
				}
			}
			else = {
				custom_tooltip = conduct_witch_trial_decide_tt
				scope:accused_witch = {
					remove_trait = witch
					hidden_effect = {
						add_character_flag = block_convert_to_witchcraft
						remove_opinion = {
							modifier = challenged_witchcraft_opinion
							target = scope:accuser
						}
					}
				}
				scope:accuser = { trigger_event = expwitch.1024 }
			}
		}
		50 = {
			modifier = {
				add = 25
				scope:accused_witch = { has_character_flag = challenge_withcraft_defiant }
			}
			modifier = {
				add = -25
				scope:accused_witch = { has_character_flag = challenge_withcraft_surrender }
			}
			modifier = {
				factor = 2
				scope:accused_witch = {
					OR = {
						has_relation_rival = scope:court_chaplain
						has_relation_nemesis = scope:court_chaplain
						has_relation_rival = scope:accuser
						has_relation_nemesis = scope:accuser
					}
				}
			}
			show_chance = no
			desc = expwitch.1022.b.execute.tt
			scope:accuser = {
				send_interface_message = {
					type = event_generic_bad
					title = expwitch.1022.b.execute.tt
					left_icon = scope:accused_witch
					execute_witch_effect = {
						VICTIM = scope:accused_witch
						EXECUTIONER = scope:accuser
						JUDGE = scope:court_chaplain
					}
				}
				trigger_event = expwitch.1025
			}
			challenge_cleanup_flags = yes
		}
	}
}

witch_trial_effect = {
	duel = {
		skills = { learning intrigue }
		target = scope:accused_witch
		50 = {
			desc = expwitch.1022.a_confess.desc
			modifier = {
				scope:accused_witch = { has_character_flag = challenge_withcraft_defiant }
				add = -45
			}
			modifier = {
				factor = 1.5
				OR = {
					has_trait = erudite
					has_trait = theologian
				}
			}
			modifier = {
				factor = 2
				scope:accused_witch = {
					OR = {
						has_relation_best_friend = scope:court_chaplain
						has_relation_friend = scope:court_chaplain
						has_relation_best_friend = scope:accuser
						has_relation_friend = scope:accuser
						has_relation_lover = scope:court_chaplain
					}
				}
			}
			modifier = {
				add = 10
				has_trait = calm
			}
			modifier = {
				add = 10
				has_trait = just
			}
			modifier = {
				add = -10
				NOT = { faith = scope:accused_witch.faith }
			}
			modifier = {
				add = 20
				scope:accused_witch = { has_trait = contrite }
			}
			modifier = {
				add = 10
				scope:accused_witch = { has_trait = trusting }
			}
			modifier = {
				add = 10
				scope:accused_witch = { has_trait = humble }
			}
			modifier = {
				add = 20
				scope:accused_witch = { has_trait = craven }
			}
			modifier = {
				add = 20
				scope:accused_witch = { has_trait = schemer }
			}
			modifier = {
				add = 10
				scope:accused_witch = { has_trait = deceitful }
			}
			ai_value_modifier = {
				who = scope:accused_witch
				ai_rationality = 0.5
				ai_zeal = -1
				ai_honor = 0.5
				max = 25
			}
			compare_modifier = {
				value = scope:duel_value
				multiplier = 3.5
				min = 0
			}
			witch_trial_confession_effect = yes
		}
		50 = {
			desc = expwitch.1022.a_execute.desc
			modifier = {
				factor = 3
				scope:accused_witch = { has_trait = lunatic }
			}
			modifier = {
				factor = 2
				scope:accused_witch = {
					OR = {
						has_trait = excommunicated
						#KINSLAYER
						AND = {
							has_trait = kinslayer_3
							trait_is_criminal_in_rite_trigger = { TRAIT = trait:kinslayer_3 RITE = scope:accuser.rite GENDER_CHARACTER = scope:accused_witch }
						}
						AND = {
							has_trait = kinslayer_2
							trait_is_criminal_in_rite_trigger = { TRAIT = trait:kinslayer_2 RITE = scope:accuser.rite GENDER_CHARACTER = scope:accused_witch }
						}
						AND = {
							has_trait = kinslayer_1
							trait_is_criminal_in_rite_trigger = { TRAIT = trait:kinslayer_1 RITE = scope:accuser.rite GENDER_CHARACTER = scope:accused_witch }
						}
						#CANNIBAL
						AND = {
							has_trait = cannibal
							trait_is_criminal_in_rite_trigger = { TRAIT = trait:cannibal RITE = scope:accuser.rite GENDER_CHARACTER = scope:accused_witch }
						}
						#SODOMITE
						AND = {
							has_trait = sodomite
							trait_is_criminal_in_rite_trigger = { TRAIT = trait:sodomite RITE = scope:accuser.rite GENDER_CHARACTER = scope:accused_witch }
						}
						#DEVIANT
						AND = {
							has_trait = deviant
							trait_is_criminal_in_rite_trigger = { TRAIT = trait:deviant RITE = scope:accuser.rite GENDER_CHARACTER = scope:accused_witch }
						}
						AND = {
							has_trait = incestuous
							trait_is_criminal_in_rite_trigger = { TRAIT = trait:incestuous RITE = scope:accuser.rite GENDER_CHARACTER = scope:accused_witch }
						}
						#ADULTERER/FORNICATOR
						AND = {
							has_trait = adulterer
							trait_is_criminal_in_rite_trigger = { TRAIT = trait:adulterer RITE = scope:accuser.rite GENDER_CHARACTER = scope:accused_witch }
						}
						AND = {
							has_trait = fornicator
							trait_is_criminal_in_rite_trigger = { TRAIT = trait:fornicator RITE = scope:accuser.rite GENDER_CHARACTER = scope:accused_witch }
						}
					}
				}
			}
			modifier = {
				factor = 2
				scope:accused_witch = {
					OR = {
						has_relation_rival = scope:court_chaplain
						has_relation_nemesis = scope:court_chaplain
						has_relation_rival = scope:accuser
						has_relation_nemesis = scope:accuser
					}
				}
			}
			modifier = {
				add = 10
				has_trait = schemer
			}
			modifier = {
				add = 10
				has_trait = lazy
			}
			modifier = {
				add = 10
				has_trait = wrathful
			}
			modifier = {
				add = 10
				has_trait = impatient
			}
			modifier = {
				add = 10
				has_trait = arbitrary
			}
			modifier = {
				add = 20
				has_trait = sadistic
			}
			modifier = {
				add = 20
				has_trait = callous
			}
			modifier = {
				add = 10
				scope:accused_witch = { has_trait = arrogant }
			}
			modifier = {
				add = 10
				scope:accused_witch = { has_trait = stubborn }
			}
			modifier = {
				add = 20
				scope:accused_witch = { has_trait = paranoid }
			}
			ai_value_modifier = {
				who = scope:court_chaplain
				ai_zeal = 0.5
				min = -25
			}
			compare_modifier = {
				value = scope:duel_value
				multiplier = -3.5
				min = 0
			}
			scope:accuser = {
				send_interface_message = {
					type = event_generic_bad
					title = expwitch.1022.a_execute.desc
					left_icon = scope:accused_witch
					execute_witch_effect = {
						VICTIM = scope:accused_witch
						EXECUTIONER = scope:accuser
						JUDGE = scope:court_chaplain
					}
				}
				trigger_event = expwitch.1025
			}
			challenge_cleanup_flags = yes
		}
	}
}

challenge_confession_effect = {
	random_list = {
		40 = {
			modifier = {
				factor = 2
				has_trait = zealous
			}
			modifier = {
				factor = 0
				NOT = { has_trait = zealous }
				number_of_personality_traits > 3
			}
			trigger = {
				OR = {
					has_trait = zealous
					NOR = {
						has_trait = zealous
						has_trait = cynical
					}
				}
			}
			if = {
				limit = { has_trait = zealous }
				remove_trait = zealous
			}
			else = {
				add_trait = cynical
			}
		}
		30 = {
			modifier = {
				factor = 2
				has_trait = brave
			}
			modifier = {
				factor = 0
				NOT = { has_trait = brave }
				number_of_personality_traits > 3
			}
			trigger = {
				OR = {
					has_trait = brave
					NOR = {
						has_trait = brave
						has_trait = craven
					}
				}
			}
			if = {
				limit = { has_trait = brave }
				remove_trait = brave
			}
			else = {
				add_trait = craven
			}
		}
		30 = {
			trigger = {
				has_trait = ambitious
			}
			remove_trait = ambitious
		}
		20 = {
			modifier = {
				factor = 2
				has_trait = arrogant
			}
			modifier = {
				factor = 0
				NOT = { has_trait = arrogant }
				number_of_personality_traits > 3
			}
			trigger = {
				OR = {
					has_trait = arrogant
					NOR = {
						has_trait = arrogant
						has_trait = humble
					}
				}
			}
			if = {
				limit = { has_trait = arrogant }
				remove_trait = arrogant
			}
			else = {
				add_trait = humble
			}
		}
		20 = {
			trigger = {
				NOR = {
					has_trait = depressed_1
					has_trait = depressed_genetic
				}
			}
			add_trait = depressed_1
		}
		10 = {}
	}
}

challenge_confession_betrayed_effect = {
	if = {
		limit = { root = scope:accuser }
		scope:accuser = {
			progress_towards_rival_effect = {
				CHARACTER = scope:accused_witch
				REASON = betrayed_witch_confession
				OPINION = -50
			}
		}
	}
	else = {
		progress_towards_rival_effect = {
			CHARACTER = scope:accuser
			REASON = betrayed_witch_confession
			OPINION = -50
		}
	}
	random_list = {
		30 = {
			modifier = {
				factor = 2
				has_trait = forgiving
			}
			modifier = {
				factor = 0
				NOT = { has_trait = forgiving }
				number_of_personality_traits > 3
			}
			trigger = {
				OR = {
					has_trait = forgiving
					NOR = {
						has_trait = forgiving
						has_trait = vengeful
					}
				}
			}
			if = {
				limit = { has_trait = forgiving }
				remove_trait = forgiving
			}
			else = {
				add_trait = vengeful
			}
		}
		30 = {
			trigger = {
				NOR = {
					has_trait = calm
					has_trait = wrathful
					number_of_personality_traits > 3
				}
			}
			add_trait = wrathful
		}
		20 = {
			modifier = {
				factor = 2
				has_trait = trusting
			}
			modifier = {
				factor = 0
				NOT = { has_trait = trusting }
				number_of_personality_traits > 3
			}
			trigger = {
				OR = {
					has_trait = trusting
					NOR = {
						has_trait = trusting
						has_trait = paranoid
					}
				}
			}
			if = {
				limit = { has_trait = trusting }
				remove_trait = trusting
			}
			else = {
				add_trait = paranoid
			}
		}
		20 = {
			modifier = {
				factor = 2
				has_trait = just
			}
			modifier = {
				factor = 0
				NOT = { has_trait = just }
				number_of_personality_traits > 3
			}
			trigger = {
				OR = {
					has_trait = just
					NOR = {
						has_trait = just
						has_trait = arbitrary
					}
				}
			}
			if = {
				limit = { has_trait = just }
				remove_trait = just
			}
			else = {
				add_trait = arbitrary
			}
		}
		10 = {
			trigger = {
				NOR = {
					has_trait = depressed_1
					has_trait = depressed_genetic
				}
			}
			add_trait = depressed_1
		}
		10 = {}
	}
}

challenge_cleanup_flags = {
	scope:accuser = {
		remove_character_flag = confront_diplomacy_initial
		remove_character_flag = confront_learning_initial
		remove_character_flag = confront_intrigue_initial
		remove_character_flag = confront_diplomacy_second
		remove_character_flag = confront_learning_second
		remove_character_flag = confront_threaten_second
		remove_character_flag = confront_witch_progress
		remove_character_flag = confront_witch_no_progress
		remove_character_flag = confront_witch_fail
		remove_character_flag = confront_witch_end_success
		remove_character_flag = confront_witch_end_fail
		remove_character_flag = confront_witch_end_critfail
	}
	scope:accused_witch = {
		if = {
			limit = { is_alive = yes }
			remove_character_flag = challenge_withcraft_defiant
			remove_character_flag = challenge_withcraft_surrender
			remove_character_flag = liege_imprisoned_me
			remove_character_flag = liege_revealed_witch_secret
			remove_character_flag = confront_critfail_release
			remove_character_flag = confront_critfail_favor
			remove_character_flag = confront_critfail_leave
			remove_character_flag = confront_critfail_convert
			remove_character_flag = confront_critfail_convert_fail
		}
	}
}

