###########################################
#
# Devil worshiper decisions for Monks and Mystics
#
###########################################

targeted_decisions = {

	# Power: Summon familiar
	devil_worshipers_summon_familiar = {
		filter = self
		ai_target_filter = self
		ai_check_interval = 12

		is_in_society = yes

		potential = {
			has_dlc = "Mystics"
			is_devil_worshiper_trigger = yes
			society_rank >= 2
			is_incapable = no
			prisoner = no
		}

		allow = {
			has_society_currency_major_trigger = yes

			custom_tooltip = {
				text = devil_worshipers_summon_familiar_cd_tooltip

				NOT = { has_character_modifier = summon_familiar_cooldown }
			}
		}

		effect = {
			increase_visibility_effect = yes
			detract_society_currency_major_effect = yes

			add_character_modifier = {
				name = summon_familiar_cooldown
				years = 5
				hidden = yes
			}

			character_event = { id = MNM.7815 }
		}

		ai_will_do = {
			factor = 1

			trigger = {
				NOR = {
					has_character_modifier = wolf_familiar
					has_character_modifier = cat_familiar
					has_character_modifier = owl_familiar
					has_character_modifier = raven_familiar
				}
			}
		}
	}

	# Power: Tainted touch
	the_devil_worshipers_tainted_touch = {
		ai_target_filter = realm
		ai_check_interval = 6

		is_in_society = yes

		from_potential = {
			is_devil_worshiper_trigger = yes
			society_rank > 1
			is_incapable = no
			prisoner = no

			trigger_if = {
				limit = { ai = yes }

				has_society_currency_major_trigger = yes

				OR = {
					war = yes
					num_of_rivals >= 1
				}
			}
		}

		potential = {
			# Ai requirements
			trigger_if = {
				limit = { FROM = { ai = yes } }

				character_disease_trigger = yes

				# Makes sure the AI does good choices
				OR = {
					is_foe = FROM
					war_with = FROM
					holds_favor_on = FROM

					# Unfaithful spouse
					trigger_if = {
						limit = { is_married = FROM }

						any_lover = {
							NOT = { character = FROM }
						}
					}

					any_lover = {
						OR = {
							is_married = FROM # Lover of my spouse
							is_lover = FROM # Lover of my lover
						}
					}
				}

				NOR = {
					has_character_flag = developing_illness
					has_character_flag = disease_not_serious
					has_character_modifier = curse_cooldown_timer
				}
			}
			# Player requirements
			trigger_else = {
				is_within_diplo_range = FROM
			}
		}

		allow = {
			FROM = { has_society_currency_major_trigger = yes }

			trigger_if = {
				limit = { FROM = { ai = no } }

				OR = {
					same_realm = FROM
					is_foe = FROM
					same_society_as = FROM
					war_with = FROM
				}
			}

			custom_tooltip = {
				text = the_devil_worshipers_tainted_touch_allow_2_tt

				NOT = { has_character_modifier = curse_cooldown_timer }
			}

			custom_tooltip = {
				text = the_devil_worshipers_tainted_touch_allow_tt

				character_disease_trigger = no

				NOR = {
					has_character_flag = developing_illness
					has_character_flag = disease_not_serious
				}
			}
		}

		effect = {
			add_character_modifier = {
				name = curse_cooldown_timer
				years = 10
				hidden = yes
			}

			FROM = {
				show_scope_change = no

				save_event_target_as = curser
				increase_visibility_effect = yes
				detract_society_currency_major_effect = yes
			}

			custom_tooltip = {
				text = the_devil_worshipers_tainted_touch_tooltip

				if = {
					limit = { has_dlc = "Reapers" }

					character_event = {
						id = MNM.7819
						days = 3
					}
				}
				else = {
					character_event = {
						id = MNM.7819
						days = 14
						random = 14
					}
				}
			}
		}

		ai_will_do = {
			factor = 1
		}
	}

	# Power: dark divorce
	devil_worshipers_dark_divorce = {
		filter = spouse
		ai_target_filter = spouse
		ai_check_interval = 120

		is_in_society = yes

		from_potential = {
			is_devil_worshiper_trigger = yes
			society_rank > 2
			is_married = yes
			prisoner = no
			is_incapable = no
		}

		potential = {
			ai = yes
			is_within_diplo_range = FROM
			NOT = { has_character_flag = being_dark_divorced }

			# Reasons allowing dark divorce for ai
			trigger_if = {
				limit = { FROM = { ai = yes } }

				OR = {
					reverse_opinion = {
						who = FROM
						value < 0
					}

					trigger_if = {
						limit = { FROM = { is_ruler = yes } }

						is_female = yes

						FROM = {
							NOT = {
								current_heir = {
									dynasty = PREV
								}
							}
						}

						OR = {
							practical_age >= 45
							fertility < 0.30
						}
					}

					is_rival = FROM
					has_character_modifier = adulterer
					has_character_modifier = adulteress
					has_character_modifier = incestuous_adulterer
					has_character_modifier = incestuous_adulteress
					is_any_kinslayer_trigger = yes
					trait = lunatic
					trait = possessed
					trait = cruel
					trait = cannibal

					AND = {
						trait = wroth
						trait = drunkard
					}

					AND = {
						trait = zealous
						is_devil_worshiper_trigger = no
					}
				}

				# Stopping the ai from making stupid choices
				NOR = {
					is_friend = FROM
					is_lover = FROM
					is_pregnant = yes
				}
			}
		}

		allow = {
			FROM = {
				has_society_currency_minor_trigger = yes
				NOT = { has_character_modifier = recently_did_dark_divorce }
			}
		}

		effect = {
			set_character_flag = being_dark_divorced
			save_event_target_as = dark_divorce_target

			FROM = {
				show_scope_change = no

				increase_visibility_effect = yes
				# save_event_target_as = dark_divorce_spell_caster

				add_character_modifier = {
					name = recently_did_dark_divorce
					years = 2
				}

				character_event = {
					id = MNM.7801
					days = 1
				}
			}
		}

		ai_will_do = {
			factor = 0.01

			mult_modifier = {
				factor = 0.5
				FROM = { is_benevolent_trigger = yes }
			}

			mult_modifier = {
				factor = 100
				FROM = { is_evil_trigger = yes }
			}

			mult_modifier = {
				factor = 0.01
				is_heir = yes
			}
		}
	}

	# Power: Dark healing
	devil_worshipers_dark_healing = {
		filter = self
		ai_target_filter = self
		ai_check_interval = 6

		is_in_society = yes

		potential = {
			is_devil_worshiper_trigger = yes
			society_rank >= 3

			NOR = {
				has_character_flag = dark_healing_in_effect
				has_character_modifier = dark_healing_recent
			}
		}

		allow = {
			has_society_currency_medium_trigger = yes

			custom_tooltip = {
				text = devil_worshipers_dark_healing_tooltip

				OR = {
					is_ill = yes
					has_symptom_trigger = yes
					has_injury_trigger = yes
					is_maimed_trigger = yes
					trait = infirm
					trait = mangled
					trait = eunuch
					trait = blinded
					trait = incapable
				}
			}
		}

		effect = {
			detract_society_currency_medium_effect = yes
			increase_visibility_effect = yes
			set_character_flag = dark_healing_in_effect
			character_event = { id = MNM.7118 }
		}

		ai_will_do = {
			factor = 0.5

			mult_modifier = {
				factor = 2

				OR = {
					is_ill = yes
					is_maimed_trigger = yes
					has_injury_trigger = yes
					trait = infirm
					trait = mangled
					trait = eunuch
					trait = blinded
					trait = incapable
				}
			}
		}
	}

	# Power: Demonic Possession
	devil_worshipers_demonic_possession = {
		filter = sub_realm
		ai_target_filter = sub_realm
		ai_check_interval = 12

		is_in_society = yes

		from_potential = {
			is_devil_worshiper_trigger = yes
			society_rank > 1
		}

		potential = {
			ai = yes

			OR = {
				host = { character = FROM }
				vassal_of = FROM
			}
		}

		allow = {
			FROM = {
				prisoner = no
				is_incapable = no
				has_society_currency_minor_trigger = yes

				custom_tooltip = {
					text = is_accessible

					trigger_if = {
						limit = { is_inaccessible_trigger = yes }

						in_seclusion = yes
						at_location = ROOT

						ROOT = { in_seclusion = yes }
					}
				}
			}

			ROOT = {
				is_incapable = no

				custom_tooltip = {
					text = possess_courtier_already_done

					NOR = {
						trait = possessed
						trait = lunatic
						has_character_flag = possessing_courtier

						has_opinion_modifier = {
							name = opinion_loyal_servant
							who = FROM
						}
					}
				}
			}
		}

		effect = {
			set_character_flag = possessing_courtier
			save_event_target_as = possess_courtier_target

			FROM = {
				show_scope_change = no

				# save_event_target_as = possess_courtier_spell_caster
				detract_society_currency_minor_effect = yes

				if = {
					limit = { ROOT = { is_quest_target_of = FROM } }

					increase_visibility_minor_effect = yes
				}
				else = {
					increase_visibility_effect = yes
				}

				character_event = {
					id = MNM.7841
					days = 3
					random = 7
				}
			}
		}

		ai_will_do = {
			factor = 0.1

			mult_modifier = {
				factor = 0.5
				FROM = { is_benevolent_trigger = yes }
			}

			mult_modifier = {
				factor = 0.25
				is_landed = no
			}

			mult_modifier = {
				factor = 3
				among_most_powerful_vassals = 5
			}
		}
	}

	# Action: Devil worshiper recruit
	devil_worshiper_recruit = {
		ai_target_filter = realm
		ai_check_interval = 24

		is_in_society = yes

		from_potential = {
			is_devil_worshiper_trigger = yes
			is_adult = yes
			prisoner = no
			is_incapable = no
			NOT = { has_character_modifier = recruitment_timer }

			trigger_if = {
				limit = { ai = yes }

				OR = {
					society_rank == 2
					society_rank == 3
				}
			}
		}

		potential = {
			# AI only checks realm, so by definition in range
			trigger_if = {
				limit = { FROM = { ai = no } }
				is_within_diplo_range = FROM
			}

			# Blocks so AI recruits sensible people (who might say no)
			trigger_else = {
				OR = {
					is_friend = FROM
					is_lover = FROM
					is_close_relative = FROM
					trait = trusting
					trait = drunkard
					trait = possessed
					trait = lunatic
					has_impious_trait_trigger = yes

					trigger_if = {
						limit = { FROM = { society_member_of = the_satanists } }
						interested_in_society = the_satanists
					}
					trigger_else_if = {
						limit = { FROM = { society_member_of = the_cold_ones } }
						interested_in_society = the_cold_ones
					}
					trigger_else_if = {
						limit = { FROM = { society_member_of = the_cult_of_kali } }
						interested_in_society = the_cult_of_kali
					}
					trigger_else_if = {
						limit = { FROM = { society_member_of = the_trollcrafters } }
						interested_in_society = the_trollcrafters
					}
					trigger_else_if = {
						limit = { FROM = { society_member_of = the_plaguebringers } }
						interested_in_society = the_plaguebringers
					}
					trigger_else_if = {
						limit = { FROM = { society_member_of = the_vodouns } }
						interested_in_society = the_vodouns
					}
					trigger_else_if = {
						limit = { FROM = { society_member_of = the_bacchants } }
						interested_in_society = the_bacchants
					}

					# CK2Plus
					trigger_else_if = {
						limit = { FROM = { society_member_of = arab_jinn_sorcerers } }
						interested_in_society = arab_jinn_sorcerers
					}
					trigger_else_if = {
						limit = { FROM = { society_member_of = cult_of_titan } }
						interested_in_society = cult_of_titan
					}
					trigger_else_if = {
						limit = { FROM = { society_member_of = cult_of_apep } }
						interested_in_society = cult_of_apep
					}
					trigger_else_if = {
						limit = { FROM = { society_member_of = the_cult_of_balor } }
						interested_in_society = the_cult_of_balor
					}
					trigger_else_if = {
						limit = { FROM = { society_member_of = cult_of_angra_mainyu } }
						interested_in_society = cult_of_angra_mainyu
					}
				}

				NOT = { trait = zealous }

				# AI cannot invite other AIs when society is full
				trigger_if = {
					limit = { ai = yes }

					trigger_if = {
						limit = { FROM = { society_member_of = the_satanists } }
						can_join_society = the_satanists
					}
					trigger_else_if = {
						limit = { FROM = { society_member_of = the_cold_ones } }
						can_join_society = the_cold_ones
					}
					trigger_else_if = {
						limit = { FROM = { society_member_of = the_cult_of_kali } }
						can_join_society = the_cult_of_kali
					}
					trigger_else_if = {
						limit = { FROM = { society_member_of = the_trollcrafters } }
						can_join_society = the_trollcrafters
					}
					trigger_else_if = {
						limit = { FROM = { society_member_of = the_plaguebringers } }
						can_join_society = the_plaguebringers
					}
					trigger_else_if = {
						limit = { FROM = { society_member_of = the_vodouns } }
						can_join_society = the_vodouns
					}
					trigger_else_if = {
						limit = { FROM = { society_member_of = the_bacchants } }
						can_join_society = the_bacchants
					}

					# CK2Plus
					trigger_else_if = {
						limit = { FROM = { society_member_of = arab_jinn_sorcerers } }
						can_join_society = arab_jinn_sorcerers
					}
					trigger_else_if = {
						limit = { FROM = { society_member_of = cult_of_titan } }
						can_join_society = cult_of_titan
					}
					trigger_else_if = {
						limit = { FROM = { society_member_of = cult_of_apep } }
						can_join_society = cult_of_apep
					}
					trigger_else_if = {
						limit = { FROM = { society_member_of = the_cult_of_balor } }
						can_join_society = the_cult_of_balor
					}
					trigger_else_if = {
						limit = { FROM = { society_member_of = cult_of_angra_mainyu } }
						can_join_society = cult_of_angra_mainyu
					}
				}
			}

			is_adult = yes
			prisoner = no
			is_incapable = no
			is_in_society = no
		}

		allow = {
			ROOT = {
				trigger_if = {
					limit = { FROM = { society_member_of = the_satanists } }
					has_satanists_prerequisites = yes
				}
				trigger_else_if = {
					limit = { FROM = { society_member_of = the_cold_ones } }
					has_cold_ones_prerequisites = yes
				}
				trigger_else_if = {
					limit = { FROM = { society_member_of = the_cult_of_kali } }
					has_cult_of_kali_prerequisites = yes
				}
				trigger_else_if = {
					limit = { FROM = { society_member_of = the_trollcrafters } }
					has_trollcrafters_prerequisites = yes
				}
				trigger_else_if = {
					limit = { FROM = { society_member_of = the_plaguebringers } }
					has_plaguebringers_prerequisites = yes
				}
				trigger_else_if = {
					limit = { FROM = { society_member_of = the_vodouns } }
					has_vodouns_prerequisites = yes
				}
				trigger_else_if = {
					limit = { FROM = { society_member_of = the_bacchants } }
					has_bacchants_prerequisites = yes
				}

				# CK2Plus
				trigger_else_if = {
					limit = { FROM = { society_member_of = arab_jinn_sorcerers } }
					has_jinn_sorceror_prerequisites = yes
				}
				trigger_else_if = {
					limit = { FROM = { society_member_of = cult_of_titan } }
					has_cult_of_titan_prerequisites = yes
				}
				trigger_else_if = {
					limit = { FROM = { society_member_of = cult_of_apep } }
					has_cult_of_apep_prerequisites = yes
				}
				trigger_else_if = {
					limit = { FROM = { society_member_of = the_cult_of_balor } }
					has_cult_of_balor_prerequisites = yes
				}
				trigger_else = {
					hidden_trigger = { FROM = { society_member_of = cult_of_angra_mainyu } }
					has_cult_of_angra_mainyu_prerequisites = yes
				}

				is_inaccessible_trigger = no

				custom_tooltip = {
					text = devil_worshiper_recruit_block_tooltip

					trigger_if = {
						limit = { has_character_flag = satanists_attempted_recruitment }
						interested_in_society = the_satanists
					}
					trigger_else_if = {
						limit = { has_character_flag = cold_ones_attempted_recruitment }
						interested_in_society = the_cold_ones
					}
					trigger_else_if = {
						limit = { has_character_flag = cult_of_kali_attempted_recruitment }
						interested_in_society = the_cult_of_kali
					}
					trigger_else_if = {
						limit = { has_character_flag = trollcrafters_attempted_recruitment }
						interested_in_society = the_trollcrafters
					}
					trigger_else_if = {
						limit = { has_character_flag = plaguebringers_attempted_recruitment }
						interested_in_society = the_plaguebringers
					}
					trigger_else_if = {
						limit = { has_character_flag = vodouns_attempted_recruitment }
						interested_in_society = the_vodouns
					}
					trigger_else_if = {
						limit = { has_character_flag = bacchants_attempted_recruitment }
						interested_in_society = the_bacchants
					}

					# CK2Plus
					trigger_else_if = {
						limit = { has_character_flag = jinn_attempted_recruitment }
						interested_in_society = arab_jinn_sorcerers
					}
					trigger_else_if = {
						limit = { has_character_flag = titancult_attempted_recruitment }
						interested_in_society = cult_of_titan
					}
					trigger_else_if = {
						limit = { has_character_flag = apepcult_attempted_recruitment }
						interested_in_society = cult_of_apep
					}
					trigger_else_if = {
						limit = { has_character_flag = cult_of_balor_attempted_recruitment }
						interested_in_society = the_cult_of_balor
					}
					trigger_else_if = {
						limit = { has_character_flag = cult_of_angra_mainyu_attempted_recruitment }
						interested_in_society = cult_of_angra_mainyu
					}

					NOR = {
						has_character_flag = being_recruited_by_the_bacchants
						has_character_flag = being_recruited_by_the_cult_of_kali
						has_character_flag = being_recruited_by_the_plaguebringers
						has_character_flag = being_recruited_by_the_satanists
						has_character_flag = being_recruited_by_the_trollcrafters
						has_character_flag = being_recruited_by_the_vodouns

						# CK2Plus
						has_character_flag = being_recruited_by_the_jinn
						has_character_flag = being_recruited_by_the_titancult
						has_character_flag = being_recruited_by_the_apepcult
						has_character_flag = being_recruited_by_the_cult_of_balor
						has_character_flag = being_recruited_by_cult_of_angra_mainyu
					}
				}
			}

			FROM = {
				is_inaccessible_trigger = no

				custom_tooltip = {
					text = recruit_delay_timer_tooltip

					NOT = { has_character_modifier = recruitment_delay_timer }
				}
			}
		}

		effect = {
			hidden_effect = {
				FROM = {
					trigger_switch = {
						on_trigger = society_member_of

						the_satanists = {
							ROOT = {
								set_character_flag = satanists_attempted_recruitment
								set_character_flag = being_recruited_by_the_satanists
							}
						}

						the_cold_ones = {
							ROOT = {
								set_character_flag = cold_ones_attempted_recruitment
								set_character_flag = being_recruited_by_the_cold_ones
							}
						}

						the_cult_of_kali = {
							ROOT = {
								set_character_flag = cult_of_kali_attempted_recruitment
								set_character_flag = being_recruited_by_the_cult_of_kali
							}
						}

						the_bacchants = {
							ROOT = {
								set_character_flag = bacchants_attempted_recruitment
								set_character_flag = being_recruited_by_the_bacchants
							}
						}

						the_plaguebringers = {
							ROOT = {
								set_character_flag = plaguebringers_attempted_recruitment
								set_character_flag = being_recruited_by_the_plaguebringers
							}
						}

						the_vodouns = {
							ROOT = {
								set_character_flag = vodouns_attempted_recruitment
								set_character_flag = being_recruited_by_the_vodouns
							}
						}

						the_trollcrafters = {
							ROOT = {
								set_character_flag = trollcrafters_attempted_recruitment
								set_character_flag = being_recruited_by_the_trollcrafters
							}
						}

						# CK2Plus
						arab_jinn_sorcerers = {
							ROOT = {
								set_character_flag = jinn_attempted_recruitment
								set_character_flag = being_recruited_by_the_jinn
							}
						}

						cult_of_titan = {
							ROOT = {
								set_character_flag = titancult_attempted_recruitment
								set_character_flag = being_recruited_by_the_titancult
							}
						}

						cult_of_apep = {
							ROOT = {
								set_character_flag = apepcult_attempted_recruitment
								set_character_flag = being_recruited_by_the_apepcult
							}
						}

						the_cult_of_balor = {
							ROOT = {
								set_character_flag = cult_of_balor_attempted_recruitment
								set_character_flag = being_recruited_by_the_cult_of_balor
							}
						}

						cult_of_angra_mainyu = {
							ROOT = {
								set_character_flag = cult_of_angra_mainyu_attempted_recruitment
								set_character_flag = being_recruited_by_cult_of_angra_mainyu
							}
						}
					}

					save_event_target_as = satanists_recruiter

					if = {
						limit = { ai = yes }

						add_character_modifier = {
							name = recruitment_timer
							years = 2
							hidden = yes
						}
					}

					add_character_modifier = {
						name = recruitment_delay_timer
						months = 3
						hidden = yes
					}
				}

				character_event = {
					id = MNM.7001 # Recruitment chain
					days = 3
				}

				letter_event = {
					id = MNM.7030 # Delayed back up, in case recruitment fails somehow
					years = 1
				}
			}
		}

		ai_will_do = {
			factor = 1

			trigger = {
				# Don't recruit characters interested in something else
				trigger_if = {
					limit = { is_interested_in_any_society = yes }

					trigger_if = {
						limit = { FROM = { society_member_of = the_satanists } }
						interested_in_society = the_satanists
					}
					trigger_else_if = {
						limit = { FROM = { society_member_of = the_cold_ones } }
						interested_in_society = the_cold_ones
					}
					trigger_else_if = {
						limit = { FROM = { society_member_of = the_cult_of_kali } }
						interested_in_society = the_cult_of_kali
					}
					trigger_else_if = {
						limit = { FROM = { society_member_of = the_trollcrafters } }
						interested_in_society = the_trollcrafters
					}
					trigger_else_if = {
						limit = { FROM = { society_member_of = the_plaguebringers } }
						interested_in_society = the_plaguebringers
					}
					trigger_else_if = {
						limit = { FROM = { society_member_of = the_vodouns } }
						interested_in_society = the_vodouns
					}
					trigger_else_if = {
						limit = { FROM = { society_member_of = the_bacchants } }
						interested_in_society = the_bacchants
					}

					# CK2Plus
					trigger_else_if = {
						limit = { FROM = { society_member_of = arab_jinn_sorcerers } }
						interested_in_society = arab_jinn_sorcerers
					}
					trigger_else_if = {
						limit = { FROM = { society_member_of = cult_of_titan } }
						interested_in_society = the_trollcrafters
					}
					trigger_else_if = {
						limit = { FROM = { society_member_of = cult_of_apep } }
						interested_in_society = cult_of_apep
					}
					trigger_else_if = {
						limit = { FROM = { society_member_of = the_cult_of_balor } }
						interested_in_society = the_cult_of_balor
					}
					trigger_else = {
						FROM = { society_member_of = cult_of_angra_mainyu }
						interested_in_society = cult_of_angra_mainyu
					}
				}
			}

			mult_modifier = {
				factor = 0.2 # Slow down
				FROM = {
					society = { num_of_society_members > 20 }
				}
			}

			mult_modifier = {
				factor = 10 # Recruit interested parties

				trigger_if = {
					limit = { FROM = { society_member_of = the_satanists } }
					interested_in_society = the_satanists
				}
				trigger_else_if = {
					limit = { FROM = { society_member_of = the_cold_ones } }
					interested_in_society = the_cold_ones
				}
				trigger_else_if = {
					limit = { FROM = { society_member_of = the_cult_of_kali } }
					interested_in_society = the_cult_of_kali
				}
				trigger_else_if = {
					limit = { FROM = { society_member_of = the_trollcrafters } }
					interested_in_society = the_trollcrafters
				}
				trigger_else_if = {
					limit = { FROM = { society_member_of = the_plaguebringers } }
					interested_in_society = the_plaguebringers
				}
				trigger_else_if = {
					limit = { FROM = { society_member_of = the_vodouns } }
					interested_in_society = the_vodouns
				}
				trigger_else_if = {
					limit = { FROM = { society_member_of = the_bacchants } }
					interested_in_society = the_bacchants
				}

				# CK2Plus
				trigger_else_if = {
					limit = { FROM = { society_member_of = arab_jinn_sorcerers } }
					interested_in_society = arab_jinn_sorcerers
				}
				trigger_else_if = {
					limit = { FROM = { society_member_of = cult_of_titan } }
					interested_in_society = the_trollcrafters
				}
				trigger_else_if = {
					limit = { FROM = { society_member_of = cult_of_apep } }
					interested_in_society = cult_of_apep
				}
				trigger_else_if = {
					limit = { FROM = { society_member_of = the_cult_of_balor } }
					interested_in_society = the_cult_of_balor
				}
				trigger_else = {
					FROM = { society_member_of = cult_of_angra_mainyu }
					interested_in_society = cult_of_angra_mainyu
				}
			}
		}
	}

	# Action: Sacrifice prisoner
	prisoner_dark_sacrifice = {
		filter = court
		ai_target_filter = court
		ai_check_interval = 12

		is_in_society = yes
		only_playable = yes

		from_potential = {
			is_devil_worshiper_trigger = yes
			is_adult = yes
			prisoner = no
			is_incapable = no
		}

		potential = {
			prisoner = yes
			host = { character = FROM }
			NOT = { has_character_flag = demon_child_non_pagan }
		}

		allow = {
			diplomatic_immunity = no
		}

		effect = {
			death = { death_reason = death_missing }

			FROM = {
				show_scope_change = no

				save_event_target_as = satanist
				increase_visibility_minor_effect = yes
				minor_soul_corruption_effect = yes

				hidden_effect = { murder_bloodline_check_effect = yes }

				# Head of Religion
				if = {
					limit = {
						ROOT = { controls_religion = yes }
					}

					character_event = { id = MNM.7500 }

					# Check quests to resolve, add extra currency and play special sound effect
					if = { # Priestly
						limit = { has_quest = quest_the_devil_worshipers_sacrifice_holy_person }

						clr_quest = quest_the_devil_worshipers_sacrifice_holy_person
						add_society_currency_major_effect = yes
					}

					else_if = { # Virgin
						limit = {
							has_quest = quest_the_devil_worshipers_sacrifice_virgin
							ROOT = { is_virgin_trigger = yes }
						}

						clr_quest = quest_the_devil_worshipers_sacrifice_virgin
						add_society_currency_major_effect = yes
					}

					else_if = { # Dwarf
						limit = {
							has_quest = quest_the_devil_worshipers_sacrifice_dwarf
							ROOT = { trait = dwarf }
						}

						clr_quest = quest_the_devil_worshipers_sacrifice_dwarf
						add_society_currency_major_effect = yes
					}

					else_if = { # Ruler
						limit = {
							has_quest = quest_the_devil_worshipers_sacrifice_ruler
							ROOT = { is_landed = yes }
						}

						clr_quest = quest_the_devil_worshipers_sacrifice_ruler
						add_society_currency_major_effect = yes
					}

					else = { # No quest so add default
						add_society_currency_medium_effect = yes
					}
				}

				# Holy Man
				else_if = {
					limit = {
						ROOT = {
							OR = {
								is_priest = yes
								is_ascetic_trigger = yes
							}
						}
					}

					character_event = { id = MNM.7500 }

					# Check quests to resolve, add extra currency and play special sound effect
					if = { # Priestly
						limit = { has_quest = quest_the_devil_worshipers_sacrifice_holy_person }

						clr_quest = quest_the_devil_worshipers_sacrifice_holy_person
						add_society_currency_medium_effect = yes
					}

					else_if = { # Virgin
						limit = {
							has_quest = quest_the_devil_worshipers_sacrifice_virgin
							ROOT = { is_virgin_trigger = yes }
						}
						clr_quest = quest_the_devil_worshipers_sacrifice_virgin
						add_society_currency_medium_effect = yes
					}

					else_if = { # Dwarf
						limit = {
							has_quest = quest_the_devil_worshipers_sacrifice_dwarf
							ROOT = { trait = dwarf }
						}

						clr_quest = quest_the_devil_worshipers_sacrifice_dwarf
						add_society_currency_medium_effect = yes
					}

					else_if = { # Ruler
						limit = {
							has_quest = quest_the_devil_worshipers_sacrifice_ruler
							ROOT = { is_landed = yes }
						}

						clr_quest = quest_the_devil_worshipers_sacrifice_ruler
						add_society_currency_medium_effect = yes
					}

					else = { # No quest so add default
						add_society_currency_minor_effect = yes
					}
				}

				# Dwarf
				else_if = {
					limit = {
						ROOT = { trait = dwarf }
					}

					character_event = { id = MNM.7502 }

					# Check quests to resolve, add extra currency and play special sound effect
					if = { # Dwarf
						limit = { has_quest = quest_the_devil_worshipers_sacrifice_dwarf }

						clr_quest = quest_the_devil_worshipers_sacrifice_dwarf
						add_society_currency_medium_effect = yes
					}

					else_if = { # Virgin
						limit = {
							has_quest = quest_the_devil_worshipers_sacrifice_virgin
							ROOT = { is_virgin_trigger = yes }
						}

						clr_quest = quest_the_devil_worshipers_sacrifice_virgin
						add_society_currency_medium_effect = yes
					}

					else_if = { # Ruler
						limit = {
							has_quest = quest_the_devil_worshipers_sacrifice_ruler
							ROOT = { is_landed = yes }
						}

						clr_quest = quest_the_devil_worshipers_sacrifice_ruler
						add_society_currency_medium_effect = yes
					}

					else = { # No quest so add default
						add_society_currency_minor_effect = yes
					}
				}

				# Regular character
				else = {
					if = {
						limit = { ROOT = { is_adult = no } }
						character_event = { id = MNM.7503 }
					}
					else_if = {
						limit = { ROOT = { is_virgin_trigger = yes } }
						character_event = { id = MNM.7504 }
					}
					else = {
						character_event = { id = MNM.7505 }
					}

					# Check quests to resolve, add extra currency and play special sound effect
					if = { # Virgin
						limit = {
							has_quest = quest_the_devil_worshipers_sacrifice_virgin
							ROOT = { is_virgin_trigger = yes }
						}

						clr_quest = quest_the_devil_worshipers_sacrifice_virgin
						add_society_currency_minor_effect = yes
					}

					else_if = { # Ruler
						limit = {
							has_quest = quest_the_devil_worshipers_sacrifice_ruler
							ROOT = { is_landed = yes }
						}

						clr_quest = quest_the_devil_worshipers_sacrifice_ruler
						add_society_currency_minor_effect = yes
					}

					else = { # No quest so add default
						add_society_currency_trivial_effect = yes
					}
				}
			}

			# CleanSlate: There exists a devil_worshippers_sacrifice_child sound_effect, but it is unused in vanilla
			if = {
				limit = {
					OR = {
						controls_religion = yes
						is_priest = yes
						is_ascetic_trigger = yes
					}
				}

				trigger_switch = {
					on_trigger = is_female

					yes = { FROM = { sound_effect = devil_worshippers_sacrifice_holy_woman } }
					no = { FROM = { sound_effect = devil_worshippers_sacrifice_holy_man } }
				}
			}

			else_if = {
				limit = { is_virgin_trigger = yes }

				trigger_switch = {
					on_trigger = is_female

					yes = { FROM = { sound_effect = devil_worshippers_sacrifice_virgin_female } }
					no = { FROM = { sound_effect = devil_worshippers_sacrifice_virgin_male } }
				}
			}

			else_if = {
				limit = { trait = dwarf }

				trigger_switch = {
					on_trigger = is_female

					yes = { FROM = { sound_effect = devil_worshippers_sacrifice_dwarf_female } }
					no = { FROM = { sound_effect = devil_worshippers_sacrifice_dwarf_male } }
				}
			}

			else = {
				trigger_switch = {
					on_trigger = is_female

					yes = { FROM = { sound_effect = devil_worshippers_sacrifice_ruler_female } }
					no = { FROM = { sound_effect = devil_worshippers_sacrifice_ruler_male } }
				}
			}

			long_character_event = { id = MNM.7506 }
		}

		ai_will_do = {
			factor = 0.5

			mult_modifier = {
				factor = 0.01

				is_landed = no
				is_priest = no
				is_ascetic_trigger = no
				is_virgin_trigger = no
				NOT = { trait = dwarf }
			}
		}
	}

	#Action: Demonic impregnation
	DW_demonic_impregnation = {
		filter = court_including_me
		ai_target_filter = court_including_me
		ai_check_interval = 120

		is_in_society = yes
		only_playable = yes

		from_potential = {
			is_devil_worshiper_trigger = yes

			trigger_if = {
				limit = { has_quest = quest_the_devil_worshipers_demonic_impregnation }
				society_rank >= 3
			}
			trigger_else = {
				society_rank >= 4
			}

			is_adult = yes
			prisoner = no
			is_incapable = no
		}

		potential = {
			is_female = yes
			host = { character = FROM }
			is_pregnant = no
			is_adult = yes
			practical_age < 45

			FROM = {
				OR = {
					character = ROOT
					has_quest = quest_the_devil_worshipers_demonic_impregnation
				}
			}
		}

		allow = {
			FROM = { has_society_currency_major_trigger = yes }
			is_female = yes
			is_pregnant = no
			is_devil_worshiper_trigger = yes
		}

		effect = {
			FROM = {
				show_scope_change = no

				increase_visibility_effect = yes
				detract_society_currency_major_effect = yes

				character_event = { id = MNM.7507 }
			}
		}

		ai_will_do = {
			factor = 0.01

			mult_modifier = {
				factor = 100
				has_quest = quest_the_devil_worshipers_demonic_impregnation
			}
		}
	}

	# Action: Prolong Life/Absorb Lifeforce
	DW_prolong_life = {
		filter = dynasty
		ai_target_filter = dynasty
		ai_check_interval = 12

		is_in_society = yes
		only_playable = yes

		from_potential = {
			society_rank == 4
			is_devil_worshiper_trigger = yes
			is_adult = yes
			prisoner = no
			is_incapable = no
		}

		potential = {
			is_child_of = FROM
			is_adult = no
			host = { character = FROM }
			NOT = { has_character_flag = demon_child_non_pagan }
		}

		allow = {
			FROM = { has_society_currency_major_trigger = yes }
		}

		effect = {
			FROM = {
				show_scope_change = no

				increase_visibility_effect = yes
				detract_society_currency_major_effect = yes

				character_event = { id = MNM.7509 }
			}
		}

		ai_will_do = {
			factor = 0.1

			trigger = {
				NOT = { has_character_modifier = stolen_life_major }
			}

			mult_modifier = {
				factor = 10
				NOR = {
					has_character_modifier = stolen_life_minor
					has_character_modifier = stolen_life_medium
					has_character_modifier = stolen_life_major
				}
			}
		}
	}

	# Action: corrupt a priest
	devil_worshipers_corrupt_priest = {
		ai_target_filter = realm
		ai_check_interval = 12

		is_in_society = yes
		only_playable = yes

		from_potential = {
			is_devil_worshiper_trigger = yes
			society_rank > 1
		}

		potential = {
			trigger_if = {
				limit = { FROM = { ai = no } }
				is_within_diplo_range = FROM
			}

			ai = yes
			religion = FROM

			OR = {
				FROM = {
					has_quest = quest_devil_worshipers_corrupt_priest
					quest_target = { character = ROOT }
				}

				AND = {
					same_realm = FROM
					is_ruler = yes
					government = theocracy_government

				#	OR = {
				#		AND = {
				#			is_landed = yes
				#
				#			capital_holding = {
				#				holding_type = temple
				#			}
				#		}
				#
				#		AND = {
				#			tier = baron
				#
				#			liege = {
				#				any_demesne_province = {
				#					owned_by = PREV
				#
				#					any_province_holding = {
				#						holder = ROOT
				#						holding_type = temple
				#					}
				#				}
				#			}
				#		}
				#	}
				}
			}
		}

		allow = {
			FROM = {
				prisoner = no
				is_incapable = no

				OR = {
					has_society_currency_tiny_trigger = yes

					custom_tooltip = {
						text = corrupt_priest_has_quest

						has_quest = quest_devil_worshipers_corrupt_priest
					}
				}

				custom_tooltip = {
					text = is_accessible

					trigger_if = {
						limit = { is_inaccessible_trigger = yes }

						in_seclusion = yes
						at_location = ROOT

						ROOT = {
							in_seclusion = yes
						}
					}
				}

				OR = {
					custom_tooltip = {
						text = corrupt_priest_not_recently_attempted

						ROOT = {
							NOR = {
								has_character_flag = attempted_corrupt_priest

								has_opinion_modifier = {
									name = opinion_successful_corruption
									who = FROM
								}

								has_opinion_modifier = {
									name = opinion_failed_corruption
									who = FROM
								}
							}
						}
					}

					custom_tooltip = {
						text = corrupt_priest_has_quest

						has_quest = quest_devil_worshipers_corrupt_priest
					}
				}
			}

			ROOT = {
				prisoner = no
				is_incapable = no
				is_inaccessible_trigger = no
			}
		}

		effect = {
			custom_tooltip = { text = corrupt_priest_effect_TOOLTIP }
			save_event_target_as = corrupt_priest_target
			set_character_flag = attempted_corrupt_priest

			FROM = {
				show_scope_change = no

				# save_event_target_as = corrupt_priest_spell_caster

				if = {
					limit = {
						has_quest = quest_devil_worshipers_corrupt_priest
						ROOT = { is_quest_target_of = FROM }
					}

					increase_visibility_minor_effect = yes
				}
				else = {
					increase_visibility_effect = yes
					detract_society_currency_tiny_effect = yes
				}

				character_event = {
					id = MNM.7826
					days = 3
					random = 7
				}
			}
		}

		ai_will_do = {
			factor = 0.1

			mult_modifier = {
				factor = 0.5
				is_benevolent_trigger = yes
			}

			mult_modifier = {
				factor = 2
				is_evil_trigger = yes
			}

			mult_modifier = {
				factor = 50
				FROM = { is_quest_target_of = ROOT }
			}

			mult_modifier = {
				factor = 0.5
				NOT = { vassal_of = FROM }
			}
		}
	}

	devil_worshipers_induction = {
		filter = court
		ai_target_filter = court
		ai_check_interval = 12

		is_in_society = yes
		# TODO: Should this be restricted to only_playable or are we fine with courtiers torturing their liege's prisoners?

		from_potential = {
			is_devil_worshiper_trigger = yes
			society_rank >= 2
			is_inaccessible_trigger = no
			is_incapable = no
			prisoner = no

			trigger_if = {
				limit = { ai = yes }

				trigger_if = {
					limit = { society_member_of = the_satanists }

					NOT = {
						is_society_rank_full = {
							society = the_satanists
							rank = 1
						}
					}
				}
				trigger_else_if = {
					limit = { society_member_of = the_cold_ones }

					NOT = {
						is_society_rank_full = {
							society = the_cold_ones
							rank = 1
						}
					}
				}
				trigger_else_if = {
					limit = { society_member_of = the_plaguebringers }

					NOT = {
						is_society_rank_full = {
							society = the_plaguebringers
							rank = 1
						}
					}
				}
				trigger_else_if = {
					limit = { society_member_of = the_cult_of_kali }

					NOT = {
						is_society_rank_full = {
							society = the_cult_of_kali
							rank = 1
						}
					}
				}
				trigger_else_if = {
					limit = { society_member_of = the_trollcrafters }

					NOT = {
						is_society_rank_full = {
							society = the_trollcrafters
							rank = 1
						}
					}
				}
				trigger_else_if = {
					limit = { society_member_of = the_vodouns }

					NOT = {
						is_society_rank_full = {
							society = the_vodouns
							rank = 1
						}
					}
				}
				trigger_else_if = {
					limit = { society_member_of = the_bacchants }

					NOT = {
						is_society_rank_full = {
							society = the_bacchants
							rank = 1
						}
					}
				}

				# CK2Plus
				trigger_else_if = {
					limit = { society_member_of = arab_jinn_sorcerers }

					NOT = {
						is_society_rank_full = {
							society = arab_jinn_sorcerers
							rank = 1
						}
					}
				}
				trigger_else_if = {
					limit = { society_member_of = cult_of_titan }

					NOT = {
						is_society_rank_full = {
							society = cult_of_titan
							rank = 1
						}
					}
				}
				trigger_else_if = {
					limit = { society_member_of = cult_of_apep }

					NOT = {
						is_society_rank_full = {
							society = cult_of_apep
							rank = 1
						}
					}
				}
				trigger_else_if = {
					limit = { society_member_of = the_cult_of_balor }

					NOT = {
						is_society_rank_full = {
							society = the_cult_of_balor
							rank = 1
						}
					}
				}
				trigger_else = {
					society_member_of = cult_of_angra_mainyu

					NOT = {
						is_society_rank_full = {
							society = cult_of_angra_mainyu
							rank = 1
						}
					}
				}
			}
		}

		potential = {
			ai = yes
			prisoner = yes
			is_adult = yes
			is_incapable = no

			trigger_if = {
				limit = {
					FROM = { society_member_of = the_satanists }
				}

				OR = {
					religion_group = christian
					secret_religion_group = christian
					religion_group = jewish_group
					secret_religion_group = jewish_group
					religion_openly_zun_or_reformed_trigger = yes
					religion_secretly_zun_or_reformed_trigger = yes
				}
			}
			trigger_else_if = {
				limit = {
					FROM = { society_member_of = the_cold_ones }
				}

				OR = {
					religion_openly_baltic_or_reformed_trigger = yes
					religion_secretly_baltic_or_reformed_trigger = yes
					religion_openly_slavic_or_reformed_trigger = yes
					religion_secretly_slavic_or_reformed_trigger = yes
					religion_openly_finnish_or_reformed_trigger = yes
					religion_secretly_finnish_or_reformed_trigger = yes
				}
			}
			trigger_else_if = {
				limit = {
					FROM = { society_member_of = the_plaguebringers }
				}

				OR = {
					religion_openly_tengri_or_reformed_trigger = yes
					religion_secretly_tengri_or_reformed_trigger = yes
				}
			}
			trigger_else_if = {
				limit = {
					FROM = { society_member_of = the_cult_of_kali }
				}

				OR = {
					religion = hindu
					secret_religion = hindu
				}
			}

			trigger_else_if = {
				limit = {
					FROM = { society_member_of = the_trollcrafters }
				}

				OR = {
					religion_openly_norse_or_reformed_trigger = yes
					religion_secretly_norse_or_reformed_trigger = yes
				}
			}
			trigger_else_if = {
				limit = {
					FROM = { society_member_of = the_vodouns }
				}

				OR = {
					religion_openly_west_african_or_reformed_trigger = yes
					religion_secretly_west_african_or_reformed_trigger = yes
				}
			}
			trigger_else_if = {
				limit = {
					FROM = { society_member_of = the_bacchants }
				}

				OR = {
					religion_openly_hellenic_or_reformed_trigger = yes
					religion_secretly_hellenic_or_reformed_trigger = yes
				}
			}

			# CK2Plus
			trigger_else_if = {
				limit = {
					FROM = {
						society_member_of = the_cult_of_balor
					}
				}

				OR = {
					religion_openly_celtic_or_reformed_trigger = yes
					religion_secretly_celtic_or_reformed_trigger = yes
				}
			}
			trigger_else_if = {
				limit = {
					FROM = {
						society_member_of = cult_of_angra_mainyu
					}
				}

				OR = {
					religion_group = zoroastrian_group
					secret_religion_group = zoroastrian_group
				}

				NOR = {
					religion = yazidi
					secret_religion = yazidi
				}
			}
			trigger_else_if = {
				limit = {
					FROM = {
						society_member_of = arab_jinn_sorcerers
					}
				}

				OR = {
					religion_group = muslim
					secret_religion_group = muslim
					religion = arabic_pagan
					secret_religion = arabic_pagan
				}
			}
			trigger_else_if = {
				limit = {
					FROM = {
						society_member_of = cult_of_titan
					}
				}

				OR = {
					religion_openly_hellenic_or_reformed_trigger = yes
					religion_secretly_hellenic_or_reformed_trigger = yes
				}
			}
			trigger_else_if = {
				limit = {
					FROM = {
						society_member_of = cult_of_apep
					}
				}

				OR = {
					religion = egyptian_pagan
					secret_religion = egyptian_pagan
				}
			}
		}

		allow = {
			FROM = { society_currency >= 25 }
			is_adult = yes
			NOT = { same_society_as = FROM }
			NOT = { trait = zealous }
			NOT = { has_character_modifier = recent_induction_attempt }
		}

		effect = {
			save_event_target_as = dw_induction_target

			FROM = {
				show_scope_change = no

				change_society_currency = -25
				increase_visibility_minor_effect = yes
				character_event = { id = MNM.7121 }
			}
		}

		ai_will_do = {
			factor = 1

			trigger = {
				NOT = { is_rival = FROM }

				# Don't recruit unimportant unrelated characters
				trigger_if = {
					limit = {
						NOT = { dynasty = FROM }
					}

					is_ruler = yes
				}
			}
		}
	}

}

title_decisions = {

	# Execute desecrate temple mission
	devil_worshiper_desecrate_temple_decision = {
		# filter = realm_owned # CleanSlate: Nonfunctional
		ai_target_filter = realm_owned
		ai_check_interval = 12

		is_in_society = yes
		only_playable = yes

		from_potential = {
			has_dlc = "Mystics"
			is_devil_worshiper_trigger = yes
			has_quest = quest_devil_worshipers_desecrate_temple
			prisoner = no
			is_incapable = no
			NOT = { has_character_flag = desecration_in_progress }
		}

		potential = {
			lower_real_tier_than = DUKE

			OR = {
				is_quest_target_of = FROM

				location = {
					capital_holding = {
						is_quest_target_of = FROM
					}
				}
			}
		}

		allow = {
			FROM = { has_quest = quest_devil_worshipers_desecrate_temple }

			OR = {
				is_quest_target_of = FROM

				location = {
					capital_holding = {
						is_quest_target_of = FROM
					}
				}
			}
		}

		effect = {
			custom_tooltip = { text = devil_worshiper_desecrate_temple_decision_tt }

			FROM = {
				show_scope_change = no

				increase_visibility_minor_effect = yes
				set_character_flag = desecration_in_progress

				if = {
					limit = { has_landed_title = ROOT }

					ROOT = {
						show_scope_change = no

						add_holding_modifier = {
							name = desecrated_temple
							years = 5
						}
					}

					sound_effect = devil_worshippers_desecrate_temple
					clr_quest = quest_devil_worshipers_desecrate_temple
					add_society_currency_medium_effect = yes
				}

				else = {
					character_event = {
						id = MNM.7112
						days = 7
					}
				}
			}
		}

		ai_will_do = {
			factor = 1
		}
	}

}

society_decisions = {
	# Power: Invite disciple of devil
	devil_worshipers_invite_disciple_of_devil = {
		ai = no # The ai can have the event triggered on_yearly_pulse

		potential = {
			has_dlc = "Mystics"
			is_devil_worshiper_trigger = yes
			society_rank >= 3
			NOT = { has_character_flag = disciple_arriving }
		}

		allow = {
			has_society_currency_minor_trigger = yes
			is_inaccessible_trigger = no
		}

		effect = {
			# increase_visibility_effect = yes
			set_character_flag = disciple_arriving
			detract_society_currency_minor_effect = yes

			custom_tooltip = {
				text = devil_worshipers_invite_disciple_of_devil_tt

				character_event = {
					id = MNM.7822
					days = 7
				}
			}
		}

		ai_will_do = {
			factor = 0

		#	factor = 0.001
		#
		#	mult_modifier = {
		#		factor = 0.1
		#		any_courtier = {
		#			is_devil_worshiper_trigger = yes # Less likely to invite if there is already someone else at court
		#		}
		#	}
		}
	}

}