convert_to_everpreg_witch = {
	skill = diplomacy
	cooldown = { months = 120 }
	is_secret = yes
	uses_agents = yes
	power_per_skill_point = 15
	resistance_per_skill_point = 5
	minimum_progress_chance = 10
	base_secrecy = 30
	maximum_secrecy = 95
	minimum_success = 5
	maximum_success = 95

	
	allow = {
		is_everpreg_witch_trigger = yes
		house = { has_house_modifier = everpreg_witch_coven }	
		is_adult = yes
		is_imprisoned = no
		scope:target = {
			is_adult = yes
			NOT = { 
				faith = { has_doctrine_parameter = tenet_everpreg_holywomb }
			}
			is_imprisoned = no
		}
	}
	
	valid = {
		#Have I been blocked from targeting this character?
		custom_description = { #Permanent
			text = everpreg_witch_scheme_blocked
			subject = scope:target
			OR = {
				has_trait = everpreg_2
				has_trait = everpreg_3
			}
			NOT = {
				scope:target = {
					has_character_flag = block_convert_to_everpreg_witchcraft 
				}
			}
		}
		scope:target = {
			exists = location
		}
	}

	use_secrecy = {
		use_convert_to_everpreg_witchcraft_secrecy_trigger = yes
	}

	valid_agent = {
		age >= 14
		OR = {
			has_trait = everpreg_1
			has_trait = everpreg_2
			has_trait = everpreg_3
		}
		faith = { has_doctrine_parameter = tenet_everpreg_holywomb }		
	}

	agent_join_chance = {
		base = 0
		
		# Base Reluctance, including negative AI Energy
		modifier = {
			add = {
				value = -20
				if = {
					limit = {
						ai_energy < 0
					}
					add = {
						value = ai_energy
						multiply = 0.5
					}
				}
			}
			desc = BASE_RELUCTANCE
		}

		#Is Owner sending a gift in the invite interaction?
		modifier = {
			add = 10
			exists = scope:gift
			always = scope:gift
			NOT = {
				OR = {
					scope:target = { is_parent_of = root }
					root = { is_parent_of = scope:target }
				}
			}
			desc = "SCHEME_WITH_GIFT"
		}

		#Target will never scheme against themselves
		modifier = {
			add = -1000
			this = scope:target
			desc = COMPASSIONATE_REASON #SCHEME_NOT_AGAINST_SELF
		}
		
		#Target is not diplomatically available
		modifier = {
			add = -1000
			is_diplomatically_available = no
			desc = SCHEME_NOT_DIPLOMATICALLY_AVAILABLE
		}

		#Not a valid witch
		modifier = {
			add = -1000
			save_temporary_scope_as = everpreg_witch_agent
			NOT = { scope:owner = { knows_about_character_being_everpreg_witch_trigger = { CHARACTER = scope:everpreg_witch_agent } } }
			desc = SCHEME_I_AM_NOT_WITCH
		}
		modifier = {
			add = -50
			save_temporary_scope_as = witch_agent
			scope:owner = { knows_about_character_being_everpreg_witch_trigger = { CHARACTER = scope:everpreg_witch_agent } }
			NOT = { faith = { has_doctrine_parameter = tenet_everpreg_holywomb } }
			desc = SCHEME_NOT_FOLLOWER_OF_WITCHGOD
		}
		
		#I am a witch!
		modifier = {
			add = 50
			scope:owner = { knows_about_character_being_witch_trigger = { CHARACTER = scope:witch_agent } }
			desc = SCHEME_I_AM_WITCH
		}

		# Cowardice
		modifier = {
			trigger = {
				ai_boldness < 0
			}
			add = {
				value = ai_boldness
			}
			desc = SCHEME_I_AM_A_COWARD
		}

		#How much does Agent like Owner?
		opinion_modifier = {
			trigger = {
				NOT = { this = scope:owner }
			}
			who = this
			opinion_target = scope:owner
			multiplier = 0.25
			#step = 5
			desc = SCHEME_MY_OPINION_OF_YOU
		}
	}


	base_success_chance = {
		base = -100

		#Coven leader
		modifier = {
			scope:owner = {
				exists = house
				house = { has_house_modifier = everpreg_witch_coven }
			}
			desc = SCHEME_EVERPREG_WITCH_COVEN
			add = 20
		}

		#Learning based
		compare_modifier = {
			target = scope:owner
			value = learning
			multiplier = 3
			step = 5
			desc = "SCHEME_LEARNING_MODIFIER"
		}

		#Their zeal
		ai_value_modifier = {
			who = scope:target
			ai_zeal = -1
			max = 50
		}

		#Opinion
		opinion_modifier = {
			who = scope:target
			opinion_target = scope:owner
			min = -50
			max = 50
			multiplier = 1.5
			step = 5
		}

		#Attraction
		modifier = {
			add = 10
			scope:owner = {
				attraction >= 10
				attraction < 20
			}
			scope:target = { is_attracted_to_gender_of = scope:owner  }
			desc = SCHEME_ATTRACTION
		}
		modifier = {
			add = 20
			scope:owner = {
				attraction >= 20
				attraction < 30
			}
			scope:target = { is_attracted_to_gender_of = scope:owner  }
			desc = SCHEME_ATTRACTION
		}
		modifier = {
			add = 30
			scope:owner = { attraction >= 30 }
			scope:target = { is_attracted_to_gender_of = scope:owner  }
			desc = SCHEME_ATTRACTION
		}

		#Target traits
		modifier = {
			scope:target = { has_trait = zealous }
			desc = "SCHEME_TRAIT_ZEALOUS"
			add = -50
		}
		modifier = {
			scope:target = { has_trait = devoted }
			desc = "SCHEME_TRAIT_DEVOTED"
			add = -30
		}
		modifier = {
			scope:target = { has_trait = order_member }
			desc = "SCHEME_TRAIT_ORDER_MEMBER"
			add = -30
		}
		modifier = {
			scope:target = { has_trait = craven }
			desc = "SCHEME_TRAIT_CRAVEN"
			add = -10
		}
		modifier = {
			scope:target = { has_trait = paranoid }
			desc = "SCHEME_TRAIT_PARANOID"
			add = -20
		}
		modifier = {
			scope:target = { has_trait = lifestyle_reveler }
			desc = "SCHEME_REVELER"
			add = 10
		}
		modifier = {
			scope:target = { has_intrigue_lifestyle_trait_trigger = yes }
			desc = "SCHEME_IS_A_SCHEMER"
			add = 10
		}
		modifier = {
			scope:target = { has_trait = seducer }
			desc = "SCHEME_TRAIT_TARGET_SEDUCER"
			add = 10
		}
		modifier = {
			scope:target = { has_trait = lifestyle_mystic }
			desc = "SCHEME_TRAIT_MYSTIC"
			add = 20
		}
		modifier = {
			scope:target = { has_trait = lifestyle_herbalist }
			desc = "SCHEME_TRAIT_HERBALIST"
			add = 10
		}
		modifier = {
			scope:target = { has_trait = lustful }
			desc = "SCHEME_LUSTFUL_TRAIT"
			add = 5
		}
		modifier = {
			scope:target = { has_trait = deceitful }
			desc = "SCHEME_TRAIT_DECEITFUL"
			add = 5
		}
		modifier = {
			scope:target = { has_trait = ambitious }
			desc = "SCHEME_TRAIT_AMBITIOUS"
			add = 5
		}
		modifier = {
			scope:target = { has_trait = cynical }
			desc = "SCHEME_TRAIT_CYNICAL"
			add = 5
		}
		modifier = {
			scope:target = { has_trait = trusting }
			desc = "SCHEME_TRAIT_TRUSTING"
			add = 5
		}
		modifier = {
			scope:target = { has_trait = excommunicated }
			desc = "SCHEME_TRAIT_EXCOMMUNICATED"
			add = 10
		}
	}

	agent_success_chance = {
		base = 0
		first_valid = {
			modifier = {
				add = 50
				is_spouse_of = scope:target
				desc = "SCHEME_AGENT_IS_SPOUSE"
			}
			modifier = {
				add = 50
				has_relation_best_friend = scope:target
				desc = "SCHEME_AGENT_IS_BEST_FRIEND"
			}
			modifier = {
				add = 50
				has_relation_guardian = scope:target
				desc = "SCHEME_AGENT_IS_GUARDIAN"
			}
			modifier = {
				add = 30
				has_relation_friend = scope:target
				desc = "SCHEME_AGENT_IS_FRIEND"
			}
			modifier = {
				add = 30
				is_concubine_of = scope:target
				desc = "SCHEME_AGENT_IS_CONCUBINE"
			}
			modifier = {
				add = 30
				has_relation_lover = scope:target
				desc = "SCHEME_AGENT_IS_LOVER"
			}
			modifier = {
				add = 30
				scope:target = {
					is_ruler = yes
				}
				has_council_position = councillor_spymaster
				scope:target.cp:councillor_spymaster = this
				desc = "SCHEME_AGENT_IS_SPYMASTER"
			}
			modifier = {
				add = 30
				scope:target = {
					is_ruler = no
				}
				has_council_position = councillor_spymaster
				scope:target.liege.cp:councillor_spymaster = this
				desc = "SCHEME_AGENT_IS_SPYMASTER_IN_MY_COURT"
			}
			modifier = {
				add = 20
				is_close_family_of = scope:target
				desc = "SCHEME_AGENT_IS_CLOSE_KIN"
			}
			modifier = {
				add = 15
				is_powerful_vassal_of = scope:target
				desc = "SCHEME_AGENT_IS_POWERFUL_VASSAL"
			}
			modifier = {
				add = 15
				is_extended_family_of = scope:target
				desc = "SCHEME_AGENT_IS_EXTENDED_FAMILY"
			}
			modifier = {
				add = 10
				scope:target.liege = scope:owner
				desc = "SCHEME_AGENT_IS_COURTIER_MY_COURT"
			}
			modifier = {
				add = 10
				is_ruler = no
				scope:target.liege = this.liege
				desc = "SCHEME_AGENT_IS_FELLOW_COURTIER"
			}
			modifier = {
				add = 5
				desc = "SCHEME_AGENT_IS_COURTIER"
			}
		}
	}

	on_ready = {
		scheme_owner = {
			#DISCOVERY ROLL
			save_scope_value_as = {
				name = discovery_chance
				value = {
					value = 100
					subtract = scope:scheme.scheme_secrecy
				}
			}
			random = {
				chance = scope:discovery_chance
				save_scope_value_as = {
					name = scheme_discovered
					value = yes
				}
			}

			#SUCCESS ROLL
			random = {
				chance = scope:scheme.scheme_success_chance

				save_scope_value_as = {
					name = scheme_successful
					value = yes
				}
			}

			#SECRECY: DO I WANT TO PROCEED?
			if = {
				limit = { use_convert_to_everpreg_witchcraft_secrecy_trigger = yes }
				trigger_event = everpreg_witch.2001
			}
			#CONTINUE WITH OUTCOME ON_ACTION FOR AI TARGETS
			else_if = {
				limit = { scope:target = { is_ai = yes } }

				if = {
					limit = { exists = scope:scheme_successful }
					trigger_event = everpreg_witch.2003 #Success event
				}
				else = {
					trigger_event = {
						# on_action = convert_to_everpreg_witch_failure_outcome
						on_action = convert_to_witchcraft_failure_outcome
					}
				}
			}
			#FOR PLAYER CHARACTER, SEND CHOICE EVENT
			else = {
				scope:target = {
					trigger_event = everpreg_witch.2002
				}
			}
		}
	}

	on_start = {
		#They're already a witch? Let's expose you to each other!
		save_scope_as = scheme
		scheme_owner = { save_scope_as = owner }
		scheme_target = { save_scope_as = target }

		if = {
			limit = {
				scope:target = { any_secret = { secret_type = secret_witch } }
			}
			scope:owner = {
				trigger_event = {
					id = everpreg_witch.2006
					days = { 7 14 }
				}
			}
		}
	}

	on_monthly = {
		save_scope_as = scheme
		scheme_owner = { save_scope_as = owner }
		scheme_target = { save_scope_as = target }
	}

	on_invalidated = {
		if = {
			limit = {
				scope:target = { is_alive = no }
			}
			scope:owner = {
				send_interface_toast = {
					title = convert_to_everpreg_witch_scheme_invalidated_title
					left_icon = scope:target
					custom_description_no_bullet = {
						object = scope:target
						text = scheme_target_died
					}
				}
			}
		}
		if = {
			limit = {
				scope:target = { is_imprisoned = yes }
			}
			scope:target.imprisoner = {
				save_scope_as = other_imprisoner
			}
			scope:owner = {
				send_interface_toast = {
					title = convert_to_everpreg_witch_scheme_invalidated_title
					left_icon = scope:target
					right_icon = scope:other_imprisoner
					custom_description_no_bullet = {
						subject = scope:other_imprisoner
						object = scope:target
						text = scheme_target_imprisoned_by_other
					}
				}
			}
		}
	}

	success_desc = "CONVERT_TO_EVERPREG_WITCHCRAFT_SUCCESS_DESC"
}

