﻿convert_to_witchcraft = {
	# Basic Setup
	skill = learning
	desc = convert_to_witchcraft_general_desc
	success_desc = "CONVERT_TO_WITCHCRAFT_SUCCESS_DESC"
	icon = icon_scheme_convert_to_witchcraft
	illustration = "gfx/interface/illustrations/event_scenes/corridor.dds"
	target_type = character
	is_secret = yes
	maximum_breaches = 5
	is_basic = yes
	cooldown = { months = 2 }
	
	# Parameters
	speed_per_skill_point = -0.25
	speed_per_target_skill_point = 0.5
	base_progress_goal = 185
	maximum_secrecy = 95
	base_maximum_success = 95
	minimum_success = 5
	freeze_scheme_when_traveling = yes
	freeze_scheme_when_traveling_target = yes

	# Core Triggers
	allow = {
		is_witch_trigger = yes
		is_adult = yes
		is_imprisoned = no
		trigger_if = {
			limit = {
				NOT = { government_has_flag = government_is_landless_adventurer }
			}
			is_travelling = no
		}
		scope:target = {
			is_adult = yes
			NOT = { has_trait = witch } #We don't want to expose them if they have the secret, we'll send you a special event instead where you're both exposed!
			is_imprisoned = no
			trigger_if = {
				limit = {
					scope:owner = {
						NOT = { government_has_flag = government_is_landless_adventurer }
					}
				}
				is_travelling = no
			}
		}
	}
	valid = {
		is_incapable = no
		#Have I been blocked from targeting this character?
		custom_description = { #Permanent
			text = witchcraft_scheme_blocked
			subject = scope:target

			NOT = {
				scope:target = {
					has_character_flag = block_convert_to_witchcraft
				}
			}
		}
	}
	use_secrecy = {
		use_convert_to_witchcraft_secrecy_trigger = { OWNER = scope:owner }
	}

	odds_prediction = {
		add = base_odds_prediction_target_is_char_value
		add = odds_skill_contribution_learning_value
		add = odds_convert_to_witchcraft_misc_value
		min = 0
	}
	
	# Base Chances
	base_success_chance = {
		base = 0
		scheme_type_skill_success_chance_modifier = { SKILL = LEARNING }

		#Coven leader
		modifier = {
			scope:owner = {
				house ?= { has_house_modifier = witch_coven }
			}
			desc = SCHEME_WITCH_COVEN
			add = 20
		}

		#Their zeal
		ai_value_modifier = {
			who = scope:target

			ai_zeal = {
				if = {
					limit = {
						scope:target.faith = { trait_is_virtue = witch has_doctrine_parameter = witchcraft_accepted }
					}
					value = 0.25
				}
				else = {
					value = -1
				}
			}
			max = 50
			min = -25
		}

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

		# Countermeasures.
		apply_opportunistic_scheme_success_chance_adjustments_modifier = yes

		#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
				NOR = {
					faith = {
						trait_is_virtue = witch
						has_doctrine_parameter = witchcraft_accepted
					}
				}
			}
			desc = "SCHEME_TRAIT_ZEALOUS"
			add = -50
		}
		modifier = {
			scope:target = {
				has_trait = devoted
				NOR = {
					faith = {
						trait_is_virtue = witch
						has_doctrine_parameter = witchcraft_accepted
					}
				}
			}
			desc = "SCHEME_TRAIT_DEVOTED"
			add = -30
		}
		modifier = {
			scope:target = {
				has_trait = order_member
				NOR = {
					faith = {
						trait_is_virtue = witch
						has_doctrine_parameter = witchcraft_accepted
					}
				}
			}
			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
				NOT = {
					faith = { trait_is_virtue = witch }
				}
			}
			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
		}

		# House Personal Scheme Success Chance on Cultural Parameter
		modifier = {
			add = cultural_house_personal_scheme_success_chance
			desc = KIN_PARAMETER_DESC
			exists = scope:owner.house
			exists = scope:target.house
			scope:owner.culture = {
				has_cultural_parameter = cultural_house_personal_scheme_success_chance
			}
			scope:target.house = scope:owner.house
		}

		# Personal Scheme Shared
		personal_scheme_base_success_chance_modifiers = yes
	}
	base_secrecy = {
		add = secrecy_base_value
		add = countermeasure_apply_secrecy_maluses_value
	}
	
	# On Actions
	on_start = {
		set_variable = {
			name = apply_countermeasures
			value = flag:opportunistic
		}
		#They're already a witch? Let's expose you to each other!
		save_scope_as = scheme
		scheme_owner = { save_scope_as = owner }
		scheme_target_character = { save_scope_as = target }
		if = {
			limit = {
				scope:target = { any_secret = { type = secret_witch } }
			}
			scope:owner = {
				trigger_event = {
					id = witch.2006
					days = { 7 14 }
				}
			}
		}
	}
	on_phase_completed = {
		# Grab our scopes.
		save_scope_as = scheme
		scheme_target_character = { save_scope_as = target }
		scheme_owner = { save_scope_as = owner }
		scope:scheme = {
			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_witchcraft_secrecy_trigger = { OWNER = scope:scheme.scheme_owner }
					}
					trigger_event = 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 = witch.2003 #Success event
					}
					else = {
						trigger_event = {
							on_action = convert_to_witchcraft_failure_outcome
						}
					}
				}
				#FOR PLAYER CHARACTER, SEND CHOICE EVENT
				else = {
					scope:target = {
						trigger_event = witch.2002
					}
				}
			}
		}
	}
	on_monthly = {
		hostile_scheme_monthly_discovery_chance_effect = yes
	}
	on_invalidated = {
		scheme_target_character = {
			save_scope_as = target
		}
		scheme_owner = {
			save_scope_as = owner
		}
		if = {
			limit = {
				scope:target = { is_alive = no }
			}
			scope:owner = {
				send_interface_toast = {
					title = convert_to_witchcraft_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_witchcraft_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
					}
				}
			}
		}
	}
}

