# major_soul_corruption_effect
# minor_soul_corruption_effect

# join_from_devil_worshiper_society_effect
# remove_demonic_blessing_effect
# add_prolong_life_effect
# join_prev_devil_worshiper_society_effect

# increase_visibility_effect
# increase_visibility_minor_effect
# decrease_visibility_effect

major_soul_corruption_effect = {
	custom_tooltip = {
		text = major_soul_corruption_effect_tooltip

		if = {
			limit = {
				NAND = {
					trait = cruel
					trait = arbitrary
					trait = deceitful
					trait = possessed
				}
			}

			random_list = {
				20 = {
					trigger = {
						trait = kind

						NOR = {
							trait = cruel
							has_character_flag = corruption_remove_kind
						}
					}

					set_character_flag = corruption_remove_kind

					character_event = {
						id = MNM.7050 # Soul Corruption event
						days = 3
						random = 27
					}
				}

				20 = {
					trigger = {
						NOR = {
							trait = kind
							trait = cruel
							has_character_flag = corruption_add_cruel
						}
					}

					set_character_flag = corruption_add_cruel

					character_event = {
						id = MNM.7050 # Soul Corruption event
						days = 3
						random = 27
					}
				}

				15 = {
					trigger = {
						trait = just

						NOR = {
							trait = arbitrary
							has_character_flag = corruption_remove_just
						}
					}

					set_character_flag = corruption_remove_just

					character_event = {
						id = MNM.7050 # Soul Corruption event
						days = 3
						random = 27
					}
				}

				15 = {
					trigger = {
						NOR = {
							trait = just
							trait = arbitrary
							has_character_flag = corruption_add_arbitrary
						}
					}

					set_character_flag = corruption_add_arbitrary

					character_event = {
						id = MNM.7050 # Soul Corruption event
						days = 3
						random = 27
					}
				}

				10 = {
					trigger = {
						trait = honest

						NOR = {
							trait = deceitful
							has_character_flag = corruption_remove_honest
						}
					}

					set_character_flag = corruption_remove_honest

					character_event = {
						id = MNM.7050 # Soul Corruption event
						days = 3
						random = 27
					}
				}

				10 = {
					trigger = {
						NOR = {
							trait = honest
							trait = deceitful
							has_character_flag = corruption_add_deceitful
						}
					}

					set_character_flag = corruption_add_deceitful

					character_event = {
						id = MNM.7050 # Soul Corruption event
						days = 3
						random = 27
					}
				}

				5 = {
					trigger = {
						NOR = {
							trait = possessed
							has_character_flag = corruption_add_possessed
						}
					}

					set_character_flag = corruption_add_possessed

					character_event = {
						id = MNM.7050 # Soul Corruption event
						days = 3
						random = 27
					}
				}

				50 = { }
			}
		}

		random_list = { # Risk of getting weaker
			10 = {
				trigger = {
					NOT = { trait = stressed }
				}

				character_event = {
					id = MNM.7051 # Soul corruption adds stress
					days = 32
					random = 5
				}
			}

			5 = {
				trigger = {
					NOT = { trait = lunatic }
				}

				character_event = {
					id = MNM.7052 # Soul corruption adds lunatic
					days = 32
					random = 5
				}
			}

			5 = {
				trigger = {
					NOT = { trait = stutter }
				}

				character_event = {
					id = MNM.7053 # Soul corruption adds stutter
					days = 32
					random = 5
				}
			}

			5 = {
				trigger = {
					NOT = { trait = clubfooted }
				}

				character_event = {
					id = MNM.7054 # Soul corruption adds clubfooted
					days = 32
					random = 5
				}
			}

			5 = {
				trigger = { NOR = { trait = hunchback } }
				character_event = { id = MNM.7055 days = 32 random = 5 } # Soul corruption adds hunchback
			}

			5 = {
				trigger = {
					NOT = { trait = ugly }
				}

				character_event = {
					id = MNM.7056 # Soul corruption adds ugly
					days = 32
					random = 5
				}
			}

			5 = {
				trigger = {
					NOR = {
						trait = frail
						trait = weak
						trait = strong
					}
				}

				character_event = {
					id = MNM.7059 # Soul corruption adds frail
					days = 32
					random = 5
				}
			}

			40 = {
				# trigger = {
				#	health >= 3
				#
				#	NOR = {
				#		has_character_modifier = corrupting_magic_minor
				#		has_character_modifier = corrupting_magic_major
				#	}
				# }

				character_event = {
					id = MNM.7057 # Soul corruption adds corrupting_magic_major
					days = 32
					random = 5
				}
			}

			220 = { # High visibility (ability abuse) increases the risk of getting weaker
				mult_modifier = {
					factor = 0.9
					check_variable = { which = visibility_value value >= 10 }
				}

				mult_modifier = {
					factor = 0.9
					check_variable = { which = visibility_value value >= 15 }
				}

				mult_modifier = {
					factor = 0.9
					check_variable = { which = visibility_value value >= 20 }
				}

				mult_modifier = {
					factor = 0.9
					check_variable = { which = visibility_value value >= 25 }
				}

				mult_modifier = {
					factor = 0.9
					check_variable = { which = visibility_value value >= 30 }
				}

				mult_modifier = {
					factor = 0.9
					check_variable = { which = visibility_value value >= 35 }
				}

				mult_modifier = {
					factor = 0.9
					check_variable = { which = visibility_value value >= 40 }
				}
			}
		}

		random = {
			chance = 2

			set_character_flag = has_it_coming

			character_event = {
				id = MNM.7855 # Demon hunters come after you...
				days = 30
				random = 50
			}
		}
	}
}

minor_soul_corruption_effect = {
	custom_tooltip = {
		text = minor_soul_corruption_effect_tooltip

		if = {
			limit = {
				NAND = {
					trait = cruel
					trait = arbitrary
					trait = deceitful
					trait = possessed
				}
			}

			random_list = {
				10 = {
					trigger = {
						trait = kind

						NOR = {
							trait = cruel
							has_character_flag = corruption_remove_kind
						}
					}

					set_character_flag = corruption_remove_kind

					character_event = {
						id = MNM.7050 # Soul Corruption event
						days = 3
						random = 27
					}
				}

				5 = {
					trigger = {
						NOR = {
							trait = kind
							trait = cruel
							has_character_flag = corruption_add_cruel
						}
					}

					set_character_flag = corruption_add_cruel

					character_event = {
						id = MNM.7050 # Soul Corruption event
						days = 3
						random = 27
					}
				}

				10 = {
					trigger = {
						trait = just

						OR = {
							trait = arbitrary
							has_character_flag = corruption_remove_just
						}
					}

					set_character_flag = corruption_remove_just

					character_event = {
						id = MNM.7050 # Soul Corruption event
						days = 3
						random = 27
					}
				}

				5 = {
					trigger = {
						NOR = {
							trait = just
							trait = arbitrary
							has_character_flag = corruption_add_arbitrary
						}
					}

					set_character_flag = corruption_add_arbitrary

					character_event = {
						id = MNM.7050 # Soul Corruption event
						days = 3
						random = 27
					}
				}

				10 = {
					trigger = {
						trait = honest

						NOR = {
							trait = deceitful
							has_character_flag = corruption_remove_honest
						}
					}

					set_character_flag = corruption_remove_honest

					character_event = {
						id = MNM.7050 # Soul Corruption event
						days = 3
						random = 27
					}
				}

				5 = {
					trigger = {
						NOR = {
							trait = honest
							trait = deceitful
							has_character_flag = corruption_add_deceitful
						}
					}

					set_character_flag = corruption_add_deceitful

					character_event = {
						id = MNM.7050 # Soul Corruption event
						days = 3
						random = 27
					}
				}

				5 = {
					trigger = {
						NOR = {
							trait = possessed
							has_character_flag = corruption_add_possessed
						}
					}

					set_character_flag = corruption_add_possessed

					character_event = {
						id = MNM.7050 # Soul Corruption event
						days = 3
						random = 27
					}
				}

				80 = { }
			}
		}

		random_list = { # Risk of getting weaker
			15 = {
				trigger = {
					NOT = { trait = stressed }
				}

				character_event = {
					id = MNM.7051 # Soul Corruption adds stress
					days = 32
					random = 5
				}
			}

			5 = {
				trigger = {
					NOT = { trait = lunatic }
				}

				character_event = {
					id = MNM.7052 # Soul Corruption adds lunatic
					days = 32
					random = 5
				}
			}

			5 = {
				trigger = {
					NOT = { trait = stutter }
				}

				character_event = {
					id = MNM.7053 # Soul Corruption adds stutter
					days = 32
					random = 5
				}
			}

			5 = {
				trigger = {
					NOT = { trait = clubfooted }
				}

				character_event = {
					id = MNM.7054 # Soul Corruption adds clubfooted
					days = 32
					random = 5
				}
			}

			5 = {
				trigger = {
					NOT = { trait = hunchback }
				}

				character_event = {
					id = MNM.7055 # Soul Corruption adds hunchback
					days = 32
					random = 5
				}
			}

			5 = {
				trigger = {
					NOT = { trait = ugly }
				}

				character_event = {
					id = MNM.7056 # Soul Corruption adds ugly
					days = 32
					random = 5
				}
			}

			5 = {
				trigger = {
					NOR = {
						trait = frail
						trait = weak
						trait = strong
					}
				}

				character_event = {
					id = MNM.7059 # Soul Corruption adds frail
					days = 32
					random = 5
				}
			}

			50 = {
				# trigger = {
				#	health >= 3
				#
				#	NOR = {
				#		has_character_modifier = corrupting_magic_minor
				#		has_character_modifier = corrupting_magic_major
				#	}
				# }

				character_event = {
					id = MNM.7058 # Soul Corruption adds corrupting_magic_minor
					days = 32
					random = 5
				}
			}

			450 = { # High visibility (ability abuse) increases the risk of getting weaker
				mult_modifier = {
					factor = 0.9
					check_variable = { which = visibility_value value >= 10 }
				}

				mult_modifier = {
					factor = 0.9
					check_variable = { which = visibility_value value >= 15 }
				}

				mult_modifier = {
					factor = 0.9
					check_variable = { which = visibility_value value >= 20 }
				}

				mult_modifier = {
					factor = 0.9
					check_variable = { which = visibility_value value >= 25 }
				}

				mult_modifier = {
					factor = 0.9
					check_variable = { which = visibility_value value >= 30 }
				}

				mult_modifier = {
					factor = 0.9
					check_variable = { which = visibility_value value >= 35 }
				}

				mult_modifier = {
					factor = 0.9
					check_variable = { which = visibility_value value >= 40 }
				}
			}
		}
	}
}

join_from_devil_worshiper_society_effect = {
	FROM = {
		trigger_switch = {
			on_trigger = society_member_of

			the_satanists		 = { ROOT = { join_society = the_satanists } }
			the_cold_ones		 = { ROOT = { join_society = the_cold_ones } }
			the_plaguebringers	 = { ROOT = { join_society = the_plaguebringers } }
			the_cult_of_kali	 = { ROOT = { join_society = the_cult_of_kali } }
			the_trollcrafters	 = { ROOT = { join_society = the_trollcrafters } }
			the_bacchants		 = { ROOT = { join_society = the_bacchants } }
			the_vodouns			 = { ROOT = { join_society = the_vodouns } }

			# CK2Plus
			the_cult_of_balor	 = { ROOT = { join_society = the_cult_of_balor } }
			cult_of_angra_mainyu = { ROOT = { join_society = cult_of_angra_mainyu } }
			arab_jinn_sorcerers	 = { ROOT = { join_society = arab_jinn_sorcerers } }
			cult_of_titan		 = { ROOT = { join_society = cult_of_titan } }
			cult_of_apep		 = { ROOT = { join_society = cult_of_apep } }
		}
	}
}

remove_demonic_blessing_effect = {
	trigger_switch = {
		on_trigger = has_character_modifier

		blessing_of_azazel = { remove_character_modifier = blessing_of_azazel }
		blessing_of_avnas  = { remove_character_modifier = blessing_of_avnas }
		blessing_of_belial = { remove_character_modifier = blessing_of_belial }
		blessing_of_mammon = { remove_character_modifier = blessing_of_mammon }
		blessing_of_vetis  = { remove_character_modifier = blessing_of_vetis }
	}
}

add_prolong_life_effect = {
	if = {
		limit = {
			NOR = {
				has_character_modifier = stolen_life_minor
				has_character_modifier = stolen_life_medium
				has_character_modifier = stolen_life_major
			}
		}

		random_list = {
			10 = {
				add_character_modifier = {
					name = stolen_life_minor
					years = 10
				}
			}

			10 = {
				add_character_modifier = {
					name = stolen_life_medium
					years = 10
				}
			}

			10 = {
				add_character_modifier = {
					name = stolen_life_major
					years = 10
				}
			}
		}
	}
	else_if = {
		limit = {
			OR = {
				has_character_modifier = stolen_life_minor
				has_character_modifier = stolen_life_medium
			}
		}

		hidden_effect = {
			remove_character_modifier = stolen_life_minor
			remove_character_modifier = stolen_life_medium
		}

		add_character_modifier = {
			name = stolen_life_major
			years = 10
		}
	}
	else = {
		add_character_modifier = {
			name = stolen_life_major
			years = 10
		}
	}
}

join_prev_devil_worshiper_society_effect = {
	if = {
		limit = { PREV = { society_member_of = the_satanists } }
		join_society = the_satanists
	}
	else_if = {
		limit = { PREV = { society_member_of = the_cold_ones } }
		join_society = the_cold_ones
	}
	else_if = {
		limit = { PREV = { society_member_of = the_plaguebringers } }
		join_society = the_plaguebringers
	}
	else_if = {
		limit = { PREV = { society_member_of = the_cult_of_kali } }
		join_society = the_cult_of_kali
	}
	else_if = {
		limit = { PREV = { society_member_of = the_trollcrafters } }
		join_society = the_trollcrafters
	}
	else_if = {
		limit = { PREV = { society_member_of = the_bacchants } }
		join_society = the_bacchants
	}
	else_if = {
		limit = { PREV = { society_member_of = the_vodouns } }
		join_society = the_vodouns
	}
	else_if = {
		limit = { PREV = { society_member_of = the_cult_of_balor } }
		join_society = the_cult_of_balor
	}
	else_if = {
		limit = { PREV = { society_member_of = cult_of_angra_mainyu } }
		join_society = cult_of_angra_mainyu
	}
	else_if = {
		limit = { PREV = { society_member_of = arab_jinn_sorcerers } }
		join_society = arab_jinn_sorcerers
	}
	else_if = {
		limit = { PREV = { society_member_of = cult_of_titan } }
		join_society = cult_of_titan
	}
	else_if = {
		limit = { PREV = { society_member_of = cult_of_apep } }
		join_society = cult_of_apep
	}
}

increase_visibility_effect = {
	hidden_effect = {
		change_variable = {
			which = visibility_value
			value = 5
		}

		if = {
			limit = {
				check_variable = {
					which = visibility_value
					value >= 15
				}

				NOR = {
					has_character_modifier = under_suspicion
					has_character_modifier = highly_suspect
				}
			}

			add_character_modifier = {
				name = under_suspicion
				duration = -1
			}

			character_event = {
				id = MNM.6662 # Inform player of suspicion
				days = 1
			}
		}

		if = {
			limit = {
				NOT = { has_character_modifier = highly_suspect }

				check_variable = {
					which = visibility_value
					value >= 25
				}
			}

			remove_character_modifier = under_suspicion

			add_character_modifier = {
				name = highly_suspect
				duration = -1
			}

			character_event = {
				id = MNM.6663 # Inform player of suspicion
				days = 1
			}

			liege = {
				set_character_flag = secret_societies_interference

				character_event = {
					id = MNM.6661 # Clear above flag
					years = 3
					random = 1095 # 3 years
				}
			}
		}

		if = { # Too visible? You auto-reveal yourself if you are independent
			limit = {
				independent = yes
				is_ruler = yes
				NOT = { has_character_flag = self_reveal }

				check_variable = {
					which = visibility_value
					value >= 40
				}
			}

			set_character_flag = self_reveal

			character_event = {
				id = MNM.6668 # Be outed and possible excommunicated
				days = 1
			}
		}
	}
}

increase_visibility_minor_effect = {
	hidden_effect = {
		change_variable = {
			which = visibility_value
			value = 2
		}

		if = {
			limit = {
				check_variable = {
					which = visibility_value
					value >= 15
				}

				NOR = {
					has_character_modifier = under_suspicion
					has_character_modifier = highly_suspect
				}
			}

			add_character_modifier = {
				name = under_suspicion
				duration = -1
			}

			character_event = {
				id = MNM.6662 # Inform player of suspicion
				days = 1
			}
		}

		if = {
			limit = {
				NOT = { has_character_modifier = highly_suspect }

				check_variable = {
					which = visibility_value
					value >= 25
				}
			}

			remove_character_modifier = under_suspicion

			add_character_modifier = {
				name = highly_suspect
				duration = -1
			}

			character_event = {
				id = MNM.6663 # Inform player of suspicion
				days = 1
			}

			liege = {
				set_character_flag = secret_societies_interference

				character_event = {
					id = MNM.6661 # Clear above flag
					years = 3
					random = 1095 # 3 years
				}
			}
		}

		if = { # Too visible? You auto-reveal yourself if you are independent
			limit = {
				independent = yes
				is_ruler = yes
				NOT = { has_character_flag = self_reveal }

				check_variable = {
					which = visibility_value
					value >= 40
				}
			}

			set_character_flag = self_reveal

			character_event = {
				id = MNM.6668 # Be outed and possible excommunicated
				days = 1
			}
		}
	}
}

decrease_visibility_effect = {
	hidden_effect = {
		if = {
			limit = {
				check_variable = {
					which = visibility_value
					value >= 1
				}
			}

			random_list = {
				50 = {
					change_variable = {
						which = visibility_value
						value = -1
					}
				}

				20 = {
					change_variable = {
						which = visibility_value
						value = -2
					}

					mult_modifier = {
						factor = 1.5

						OR = {
							trait = master_schemer
							trait = deceitful
							trait = patient
							trait = paranoid
						}
					}

					mult_modifier = {
						factor = 1.25
						intrigue >= 12
					}

					mult_modifier = {
						factor = 1.25
						intrigue >= 14
					}

					mult_modifier = {
						factor = 1.25
						intrigue >= 16
					}
				}

				15 = {
					change_variable = {
						which = visibility_value
						value = -3
					}

					mult_modifier = {
						factor = 1.5

						OR = {
							trait = master_schemer
							trait = deceitful
							trait = patient
							trait = paranoid
						}
					}

					mult_modifier = {
						factor = 1.25
						intrigue >= 12
					}

					mult_modifier = {
						factor = 1.25
						intrigue >= 14
					}

					mult_modifier = {
						factor = 1.25
						intrigue >= 16
					}
				}

				10 = {
					change_variable = {
						which = visibility_value
						value = -4
					}

					mult_modifier = {
						factor = 1.5

						OR = {
							trait = master_schemer
							trait = deceitful
							trait = patient
							trait = paranoid
						}
					}

					mult_modifier = {
						factor = 1.25
						intrigue >= 12
					}

					mult_modifier = {
						factor = 1.25
						intrigue >= 14
					}

					mult_modifier = {
						factor = 1.25
						intrigue >= 16
					}
				}

				5 = {
					change_variable = {
						which = visibility_value
						value = -5
					}

					mult_modifier = {
						factor = 1.5

						OR = {
							trait = master_schemer
							trait = deceitful
							trait = patient
							trait = paranoid
						}
					}

					mult_modifier = {
						factor = 1.25
						intrigue >= 12
					}

					mult_modifier = {
						factor = 1.25
						intrigue >= 14
					}

					mult_modifier = {
						factor = 1.25
						intrigue >= 16
					}
				}
			}
		}

		if = {
			limit = {
				check_variable = {
					which = visibility_value
					value < 0 # Safety
				}
			}
			set_variable = {
				which = visibility_value
				value = 0
			}
		}
	}

	if = {
		limit = {
			check_variable = {
				which = visibility_value
				value < 25
			}

			has_character_modifier = highly_suspect
		}

		remove_character_modifier = highly_suspect

		add_character_modifier = {
			name = under_suspicion
			duration = -1
		}

		character_event = { id = MNM.6664 } # Inform player of removed suspicion
	}

	if = {
		limit = {
			check_variable = {
				which = visibility_value
				value < 15
			}

			has_character_modifier = under_suspicion
		}

		remove_character_modifier = under_suspicion
		character_event = { id = MNM.6665 } # Inform player of removed suspicion
	}
}