###########################################
#
# Society decisions for monastic orders
#
###########################################

decisions = {
	create_sufi_ibadi = {
		only_playable = yes
		is_high_prio = yes
		ai_check_interval = 120 #check only once every 120 months.
		
		potential = {
			has_dlc = "Mystics"
			age = 16
			has_sufi_societies_religion_ibadi = yes
			NOT = { 
				monastic_order_ibadi = {
					society_has_members = yes								
				}
			}
		}
		
		allow = {
			is_in_society = no
			NOT = { trait = incapable }
			OR = {
				trait = mystic
				trait = faqih
				trait = hafiz
				has_education_learning_trigger = yes
			}
			is_landed = yes
			learning = 15
			is_inaccessible_trigger = no
			scaled_wealth = 0.75
			piety = 1000
		}
		
		effect = {
			scaled_wealth = -0.75
			piety = -1000
			hidden_tooltip = {
				join_society = monastic_order_ibadi
				set_society_grandmaster = yes # Set character as Grand Master
				add_society_currency_massive_effect = yes
					spawn_sufi_effect = yes
					new_character = { join_society = monastic_order_ibadi }
					spawn_sufi_effect = yes
					new_character = { join_society = monastic_order_ibadi }
					spawn_sufi_effect = yes
					new_character = { join_society = monastic_order_ibadi }
					spawn_sufi_effect = yes
					new_character = { join_society = monastic_order_ibadi }
					spawn_sufi_effect = yes
					new_character = { join_society = monastic_order_ibadi }
					spawn_sufi_effect = yes
					new_character = { join_society = monastic_order_ibadi }
				any_vassal = {
					limit = {
						ai = yes
						can_join_society = monastic_order_ibadi
					}
					random = { chance = 25 join_society = monastic_order_ibadi }
				}
				any_neighbor_independent_ruler = {
					limit = {
						ai = yes
						can_join_society = monastic_order_ibadi
					}
					random = { chance = 15 join_society = monastic_order_ibadi }
				}
				any_player = {
					limit = {
						OR = {
							religion_group = ROOT
							culture_group = ROOT
							is_within_diplo_range = ROOT
						}
					}
					narrative_event = { id = SUFI.25029 } #make this
				}
			}
		}
		
		revoke_allowed = {
			always = no
		}
		
		ai_will_do = {
			factor = 1
		}
	}
	create_sufi_shiite = {
		only_playable = yes
		is_high_prio = yes
		ai_check_interval = 120 #check only once every 120 months.
		
		potential = {
			has_dlc = "Mystics"
			age = 16
			has_sufi_societies_religion_shiite = yes
			NOT = { 
				monastic_order_shiite = {
					society_has_members = yes								
				}
			}
		}
		
		allow = {
			is_in_society = no
			NOT = { trait = incapable }
			OR = {
				trait = mystic
				trait = faqih
				trait = hafiz
				has_education_learning_trigger = yes
			}
			is_landed = yes
			learning = 15
			is_inaccessible_trigger = no
			scaled_wealth = 0.75
			piety = 1000
		}
		
		effect = {
			scaled_wealth = -0.75
			piety = -1000
			hidden_tooltip = {
				join_society = monastic_order_shiite
				set_society_grandmaster = yes # Set character as Grand Master
				add_society_currency_massive_effect = yes
					spawn_sufi_effect = yes
					new_character = { join_society = monastic_order_shiite }
					spawn_sufi_effect = yes
					new_character = { join_society = monastic_order_shiite }
					spawn_sufi_effect = yes
					new_character = { join_society = monastic_order_shiite }
					spawn_sufi_effect = yes
					new_character = { join_society = monastic_order_shiite }
					spawn_sufi_effect = yes
					new_character = { join_society = monastic_order_shiite }
					spawn_sufi_effect = yes
					new_character = { join_society = monastic_order_shiite }
				any_vassal = {
					limit = {
						ai = yes
						can_join_society = monastic_order_shiite
					}
					random = { chance = 25 join_society = monastic_order_shiite }
				}
				any_neighbor_independent_ruler = {
					limit = {
						ai = yes
						can_join_society = monastic_order_shiite
					}
					random = { chance = 15 join_society = monastic_order_shiite }
				}
				any_player = {
					limit = {
						OR = {
							religion_group = ROOT
							culture_group = ROOT
							is_within_diplo_range = ROOT
						}
					}
					narrative_event = { id = SUFI.25028 }
				}
			}
		}
		
		revoke_allowed = {
			always = no
		}
		
		ai_will_do = {
			factor = 1
		}
	}
	create_sufi_sunni = {
		only_playable = yes
		is_high_prio = yes
		ai_check_interval = 120 #check only once every 120 months.
		
		potential = {
			has_dlc = "Mystics"
			age = 16
			has_sufi_societies_religion_sunni = yes
			NOT = { 
				monastic_order_sunni = {
					society_has_members = yes								
				}
			}
		}
		
		allow = {
			is_in_society = no
			NOT = { trait = incapable }
			OR = {
				trait = mystic
				trait = faqih
				trait = hafiz
				has_education_learning_trigger = yes
			}
			is_landed = yes
			learning = 15
			is_inaccessible_trigger = no
			scaled_wealth = 0.75
			piety = 1000
		}
		
		effect = {
			scaled_wealth = -0.75
			piety = -1000
			hidden_tooltip = {
				join_society = monastic_order_sunni
				set_society_grandmaster = yes # Set character as Grand Master
				add_society_currency_massive_effect = yes
					spawn_sufi_effect = yes
					new_character = { join_society = monastic_order_sunni }
					spawn_sufi_effect = yes
					new_character = { join_society = monastic_order_sunni }
					spawn_sufi_effect = yes
					new_character = { join_society = monastic_order_sunni }
					spawn_sufi_effect = yes
					new_character = { join_society = monastic_order_sunni }
					spawn_sufi_effect = yes
					new_character = { join_society = monastic_order_sunni }
					spawn_sufi_effect = yes
					new_character = { join_society = monastic_order_sunni }
				any_vassal = {
					limit = {
						ai = yes
						can_join_society = monastic_order_sunni
					}
					random = { chance = 25 join_society = monastic_order_sunni }
				}
				any_neighbor_independent_ruler = {
					limit = {
						ai = yes
						can_join_society = monastic_order_sunni
					}
					random = { chance = 15 join_society = monastic_order_sunni }
				}
				any_player = {
					limit = {
						OR = {
							religion_group = ROOT
							culture_group = ROOT
							is_within_diplo_range = ROOT
						}
					}
					narrative_event = { id = SUFI.25027 } #make this
				}
			}
		}
		
		revoke_allowed = {
			always = no
		}
		
		ai_will_do = {
			factor = 1
		}
	}
	monastic_orders_stop_celibate_sufi = {
		only_playable = yes
		ai_check_interval = 12
		
		potential = {
			has_dlc = "Mystics"
			is_ruler = yes
			# is_sufi_member_trigger = no
			# society_rank >= 2
			OR = {
				trait = sufi_zahid
				AND = {
					trait = celibate
					is_sufi_member_trigger = yes
					has_global_flag = HIPEMF_ACTIVE
				}
			}
		}

		allow = {
			OR = {
				trait = sufi_zahid
				trigger_if = {
					limit = {
						has_global_flag = HIPEMF_ACTIVE
					}
					trait = celibate
				}
			}
			NOT = { has_character_modifier = promise_of_celibacy }
			trigger_if = {
				limit = {
					is_sufi_member_trigger = yes
				}
				society_currency = 100
			}
		}

		effect = {
			tooltip = {
				if = {
					limit = {
						has_global_flag = HIPEMF_ACTIVE
						trait = celibate
					}
					remove_trait = celibate
				}
				else = { remove_trait = sufi_zahid }
			}
			character_event = {
				id = SUFI.4091
			}
		}
		
		ai_will_do = {
			factor = 0.05
			modifier = {
				factor = 5
				is_sufi_member_trigger = no
			}
		}
	}

}

society_decisions = {
	monastic_orders_create_sufis = {
		ai_check_interval = 12
		potential = {
			AI = yes
			is_sufi_member_trigger = yes
			society_rank = 4
		}

		allow = {
			num_of_society_members < 10 
		}

		effect = {
			top_liege = {
				random_realm_lord = {
					random_list = {
						33 = {
							create_character = {
								random_traits = yes
								dynasty = none
								religion = ROOT
								female = no
								age = 22
								health = 6
							}
							new_character = { save_event_target_as = ascetic }
						}
						33 = {
							create_character = {
								random_traits = yes
								dynasty = none
								religion = ROOT
								female = no
								age = 42
								health = 6
							}
							new_character = { save_event_target_as = ascetic }
						}
						33 = {
							create_character = {
								random_traits = yes
								dynasty = none
								religion = ROOT
								female = no
								age = 65
								health = 6
							}
							new_character = { save_event_target_as = ascetic }
						}
					}
			
					event_target:ascetic = {
						join_root_sufi_order_society = yes
					
						#Set correct education
						random = {
							chance = 50
							remove_education_effect = yes
							random_list = {
								30 = { add_trait = detached_priest }
								60 = { add_trait = martial_cleric }
								60 = { add_trait = scholarly_theologian }
								30 = { add_trait = mastermind_theologian }
							}
						}
			
						#Up  learning
						random_list = {
							25 = { change_learning = 1 }
							25 = { change_learning = 2 }
							25 = { change_learning = 3 }
							25 = { change_learning = 4 }
							25 = { change_learning = 5 }
							25 = { change_learning = 6 }
						}
			
						#Set some interesting traits 
			
						#Nun/monk traits
						# add_trait = hafiz
						# add_trait = hajjaj
						# add_trait = mystic
						remove_trait = cynical
			
						#Nice congential
						# random_list = {
							# 10 = {
								# add_trait = fair
								# remove_trait = ugly
							# }
							# 5 = {
								# add_trait = genius
								# remove_trait = imbecile
								# remove_trait = quick
								# remove_trait = slow
							# }
							# 10 = {
								# add_trait = quick
								# remove_trait = imbecile
								# remove_trait = genius
								# remove_trait = slow
							# }
							# 5 = {
								# add_trait = strong
								# remove_trait = weak
							# }
							# 100 = { }
						# }
			
						#Lifestyle
						remove_lifestyle_trait_effect = yes
						random_list = {
							50 = { }
							15 = { add_trait = faqih }
							10 = { add_trait = theologian }
							15 = { add_trait = mystic }
						}
			
						random = {
							chance = 33
							add_trait = sufi_zahid
						}
						#Virtues
						remove_trait = lustful
						remove_trait = wroth
						remove_trait = gluttonous
						remove_trait = cruel
						random = {
							chance = 20
							remove_trait = envious
							add_trait = kind
						}
						random = {
							chance = 20
							remove_trait = greedy
							add_trait = charitable
						}
						random = {
							chance = 10
							add_trait = temperate
							lose_weight_small_effect = yes
							weight_trait_check_effect = yes
						}
						random = {
							chance = 5
							add_trait = patient
							remove_trait = wroth
						}
						random = {
							chance = 10
							add_trait = humble
							remove_trait = proud
						}
						random = {
							chance = 5
							remove_trait = slothful
							remove_trait = diligent
						}
			
						#Misc traits
						remove_trait = deceitful
						remove_trait = arbitrary
						remove_trait = cynical
						random = {
							chance = 10
							add_trait = honest
						}
						random = {
							chance = 10
							add_trait = just
						}
						random = {
							chance = 15
							add_trait = erudite
						}
						random = {
							chance = 10
							add_trait = content
							remove_trait = ambitious
						}
						if = {
							limit = { has_dlc = "Reapers" }
							random = {
								chance = 10
								add_trait = physician
							}
						}
			
						#Nicknames
						# random_list = {
							# 10 = {
								# give_nickname = nick_the_holy
							# }
							# 10 = { 
								# modifier = {
									# factor = 0
									# NAND = {
										# trait = kind
										# trait = charitable
										# trait = humble
									# }
								# }
								# give_nickname = nick_the_wali
							# }
							# 10 = { 
								# modifier = {
									# factor = 0
									# NAND = {
										# trait = kind
										# trait = charitable
									# }
								# }
								# give_nickname = nick_the_kind
							# }
							# 10 = { 
								# modifier = {
									# factor = 0
									# NAND = {
										# trait = charitable
										# trait = just
									# }
								# }
								# give_nickname = nick_the_good
							# }
							# 10 = { 
								# modifier = {
									# factor = 0
									# OR = {
										# is_smart_trigger = yes
										# trait = just
										# trait = patient
										# trait = scholar
									# }
								# }
								# give_nickname = nick_the_wise
							# }
							# 50 = { }
						# }
						# character_event = { id = SUFI.4433 }	
					}
				}
			}
		}
		
		ai_will_do = {
			factor = 1
		}
	}
	
	monastic_orders_invite_ascetic_sufi = {
		only_playable = yes
		
		potential = {
			has_dlc = "Mystics"
			society_rank >= 3
			is_sufi_member_trigger = yes
			NOT = { has_character_flag = ascetic_arriving }
			NOT = { has_character_modifier = recently_invited_sufi}
		}

		allow = {
			has_society_currency_medium_trigger = yes
			is_inaccessible_trigger = no
		}

		effect = {
			set_character_flag = ascetic_arriving
			detract_society_currency_medium_effect = yes
			
			custom_tooltip = {
				text = monastic_orders_invite_ascetic_sufi_tt
				character_event = { id = SUFI.4432 days = 7 }
			}
			add_character_modifier = {
				name = recently_invited_sufi
				duration = 365
			}
		}

		revoke_allowed = {
			always = no
		}

		ai_will_do = {
			factor = 0.001
			modifier = {
				factor = 0.1
				any_courtier = { is_sufi_member_trigger = yes } #Less likely to invite if there is already someone else at court
			}
			modifier = {
				any_courtier = { has_job_title = job_spiritual learning = 16 }
				factor = 0.01
			}
		}
	}
	request_to_rank_up_within_sufi_society = {
		only_playable = yes

		hide_in_decisions_list = yes # This is shown in the Society View
		
		ai_check_interval = 12
		
		potential = {
			hidden_tooltip = {
				society_rank < 4
				days_in_society > 365
				#has_dlc = "Mystics"
				is_in_society = yes
				OR = { #Players can always rank up (if they have the power)
					ai = no
					AND = {
						ai = yes
						society_can_rank_up = yes
					}
				}
			}
		}

		allow = {
			#Rank requirements. IMPORTANT!!! If you change the requirements, the customizable loc keys "GetSocietyRankUpTooltip" 1, 2, 3, and 4 must be updated, as it displays these requirements.
			custom_tooltip = { # Sufficient currency
				text = request_to_rank_up_within_society_currency_tt
				OR = {
					AND = {
						society_rank == 1
						society_currency >= 750
					}
					AND = {
						society_rank == 2
						society_currency >= 1000
					}
					society_currency >= 2000 # rank 3
				}
			}
			custom_tooltip = {
				text = request_to_rank_up_within_sufi_society_cynical_tt
				OR = {
					AND = {
						society_rank == 1
						NOT = {
							trait = cruel
						}
					}
					AND = {
						society_rank == 2
						NOR = {
							trait = cruel
							trait = cynical
						}
					}
					AND = {
						society_rank == 3
						NOR = {
							trait = cruel
							trait = cynical
							trait = greedy
							trait = gluttonous
							trait = slothful
							trait = envious
							trait = wroth
							trait = cruel
							trait = proud
						}
					}
				}
			}
			custom_tooltip = {
				text = request_to_rank_up_within_sufi_society_virtues_tt
				OR = {
					AND = {
						society_rank == 1
						OR = {
							trait = humble
							trait = charitable
							trait = chaste
							trait = kind
							trait = temperate
							trait = patient
							trait = diligent
						}
					}
					AND = {
						society_rank == 2
						calc_true_if = {
							amount = 2
							trait = humble
							trait = charitable
							trait = chaste
							trait = kind
							trait = temperate
							trait = patient
							trait = diligent
						}
					}
					AND = {
						society_rank == 3
						calc_true_if = {
							amount = 3
							trait = humble
							trait = charitable
							trait = chaste
							trait = kind
							trait = temperate
							trait = patient
							trait = diligent
						}
					}
				}
			}

			custom_tooltip = {
				text = must_not_have_sent_request_already_tooltip 
				NOT = { has_character_flag = has_sent_request_to_rank_up }
			}

			custom_tooltip = {
				text = must_be_allowed_to_rank_up_tooltip 
				days_at_current_society_rank >= 1095 #IMPORTANT! Update tooltip.
			}

			custom_tooltip = {
				text = must_have_grandmaster_tooltip #You must have a grand master
				any_society_member = {
					is_society_grandmaster = yes
					same_society_as = ROOT
				}
			}
		}

		effect = {
			#Rank up cost
			if = {
				limit = { society_rank == 1 }
				change_society_currency = -750
			}
			if = {
				limit = { society_rank == 2 }
				change_society_currency = -1000
			}
			if = {
				limit = { society_rank == 3 }
				change_society_currency = -2000
			}

			#Perform rank up
			hidden_tooltip = {
				save_event_target_as = rank_up_target
				set_character_flag = has_sent_request_to_rank_up
				character_event = { id = SUFI.10002 days = 20 random = 10 } # sends hidden delayed event to self, which then sends request to Leader of the society
			}
		}

		revoke_allowed = {
			always = no
		}
		
		ai_will_do = {
			factor = 1

			modifier = {
				factor = 0.5 #Slow down
			}
			modifier = {
				factor = 0.5
				trait = content
			}
			modifier = {
				factor = 2 
				trait = ambitious
			}
		}
	}
	monastic_orders_go_celibate_sufi = {
		
		potential = {
			is_sufi_member_trigger = yes
			society_rank >= 2
			NOR = { 
				trait = sufi_zahid
				AND = {
					trait = celibate
					has_global_flag = HIPEMF_ACTIVE
				}
			}
		}

		allow = {
			NOR = {
				trait = sufi_zahid
				trait = celibate
				trait = hedonist
				has_character_modifier = in_meditation
			}
			society_currency = 100
		}

		effect = {
			tooltip = {
				if = {
					limit = {
						has_global_flag = HIPEMF_ACTIVE
					}
					add_trait = celibate
				}
				else = { add_trait = sufi_zahid }
			}
			character_event = {
				id = SUFI.4090
			}
			change_society_currency = -100
		}
		
		ai_will_do = {
			factor = 0
		}
	}

	# monastic_orders_stop_celibate_sufi = {
		
		# potential = {
			# is_sufi_member_trigger = yes
			# society_rank >= 2
			# trait = sufi_zahid
		# }

		# allow = {
			# trait = sufi_zahid
		# }

		# effect = {
			# tooltip = {
				# remove_trait = sufi_zahid
			# }
			# character_event = {
				# id = SUFI.4091
			# }
		# }
		
		# ai_will_do = {
			# factor = 0
		# }
	# }

	monastic_orders_donate_to_charity_sufi = {
		only_playable = yes
		
		potential = {
			is_sufi_member_trigger = yes
			OR = {
				has_quest = quest_monastic_order_donate_to_charity
				NOT = { has_character_modifier = recently_donated_to_charity}
			}
			NOT = { has_character_flag = donate_to_charity_cooldown }
		}

		allow = {
			wealth = 100
		}

		effect = {
			set_character_flag = donate_to_charity_cooldown
			tooltip = {
				wealth = -100
				if = {
					limit = { has_quest = quest_monastic_order_donate_to_charity }
					add_society_currency_medium_effect = yes
				}
				if = {
					limit = { NOT = { has_quest = quest_monastic_order_donate_to_charity } }
					add_society_currency_minor_effect = yes
				}
				add_character_modifier = {
					modifier = recently_donated_to_charity
					days = 360
				}
				if = {
					limit = { 
						NOR = {
							trait = charitable
							trait = greedy 
						} 
					}
					random = {
						chance = 30
						add_trait = charitable
					}
				}
				if = {
					limit = { trait = greedy }
					random = {
						chance = 40
						remove_trait = greedy
					}
				}
			}
			hidden_effect = {
				if = {
					limit = {
						is_society_grandmaster = no
					}
					random_society_member = {
						limit = {
							same_society_as = ROOT
							is_society_grandmaster = yes
						}
						character_event = {
							id = SUFI.4013
						}
					}
				}
				else_if = {
					limit = {
						is_society_grandmaster = yes
						any_society_member = {
							same_society_as = ROOT
							is_society_grandmaster = no
						}
					}
					random_society_member = {
						limit = {
							same_society_as = ROOT
							is_society_grandmaster = no
						}
						character_event = {
							id = SUFI.4013
						}
					}
				}
				else = {
					wealth = -100
					if = {
						limit = { NOT = { has_quest = quest_monastic_order_donate_to_charity } }
						add_society_currency_minor_effect = yes
					}
					
					if = {
						limit = { has_quest = quest_monastic_order_donate_to_charity }
						clr_quest = quest_monastic_order_donate_to_charity
						sound_effect = monastic_orders_donate_charity
						hidden_effect = { monastic_order_purity_effect = yes }
						add_society_currency_medium_effect = yes
					}

					add_character_modifier = {
						modifier = recently_donated_to_charity
						days = 360
					}
					if = {
						limit = { NOT = { trait = greedy } }
						random = {
							chance = 30
							add_trait = charitable
						}
					}
					if = {
						limit = { trait = greedy }
						random = {
							chance = 40
							remove_trait = greedy
						}
					}
					clr_character_flag = donate_to_charity_cooldown
				}
			}
		}
	}
	monastic_order_meditation_sufi = {
		
		potential = {
			has_dlc = "Mystics"
			is_sufi_member_trigger = yes
			has_quest = quest_monastic_order_meditation
		}

		allow = {
			has_quest = quest_monastic_order_meditation
			custom_tooltip = {
				text = monastic_order_meditation_allow_tt
				OR = {
					NOT = { has_character_flag = holy_seclusion_timer }
					had_character_flag = { flag = holy_seclusion_timer days = 1000 }
				}
			}
		}

		effect = {
			add_character_modifier = {
				name = in_meditation
				duration = -1
			}
			hidden_effect = { character_event = { id = SUFI.4403 } }
		}

		revoke_allowed = {
			always = no
		}
		
		ai_will_do = {
			factor = 0.1

			modifier = {
				factor = 0.01
				war = yes
			}
			modifier = {
				factor = 0.1
				OR = {
					trait = gregarious
					trait = socializer
				}
			}
			modifier = {
				factor = 5
				is_virtous = yes
			}
		}
	}

	# monastic_order_rejoin_world = {

		# potential = {
			# has_dlc = "Mystics"
			# OR = {
				# has_character_modifier = doing_penance
				# has_character_modifier = in_meditation
			# }
		# }

		# allow = {
			# OR = {
				# has_character_modifier = doing_penance
				# has_character_modifier = in_meditation
			# }
			# piety = 100
		# }

		# effect = {
			# remove_character_modifier = doing_penance
			# remove_character_modifier = in_meditation
			# hidden_effect = {
				# clr_character_flag = success_seculison_desc_A #Flags from 4426
				# clr_character_flag = success_seculison_desc_B
				# clr_character_flag = success_seculison_desc_C
			# }
			# piety = -100
		# }

		# revoke_allowed = { always = no }

		# ai_will_do = {
			# factor = 0
		# }
	# }
}

targetted_decisions = {
	monastic_orders_spiritual_guidance_sufi = {  ### Monastic Order Rank 2 power : targeted decision to remove one of target's vices
		ai_check_interval = 12
		potential = {
			NOT = { trait = incapable }
			OR = {
				same_realm = FROM
				same_society_as = FROM
			}
			is_within_diplo_range = FROM
			religion = FROM
		}
		
		from_potential = {
			has_DLC = "Mystics"
			society_rank >= 2
			is_sufi_member_trigger = yes
			is_adult = yes
			NOT = { trait = incapable }
		}
		
		allow = {
			FROM = {
				has_society_currency_medium_trigger = yes	###requires 300SocCur
				is_inaccessible_trigger = no
				prisoner = no
				in_command = no
			}
			is_inaccessible_trigger = no
			prisoner = no
			in_command = no
			same_realm = FROM
			OR = {
				is_landed = yes
				is_patrician = yes
				is_close_relative = FROM
			}
			NOT = {
				has_opinion_modifier = {	###opinion modifier 10yrs cooldown
					who =  FROM
					modifier = opinion_spiritual_guidance
				}
			}
			custom_tooltip = {
				text = spiritual_guidance_tooltip
				OR ={
					AND = {
						trait = lustful
						FROM = { NOT = { trait = lustful } }
					}
					AND = {
						trait = gluttonous
						FROM = { NOT = { trait = gluttonous } }
					}
					AND = {
						trait = greedy
						FROM = { NOT = { trait = greedy } }
					}
					AND = {
						trait = slothful
						FROM = { NOT = { trait = slothful } }
					}
					AND = {
						trait = wroth
						FROM = { NOT = { trait = wroth } }
					}
					AND = {
						trait = envious
						FROM = { NOT = { trait = envious } }
					}
					AND = {
						trait = proud
						FROM = { NOT = { trait = proud } }
					}
				}
			}
		}
		
		effect = {
			FROM = {
				detract_society_currency_medium_effect = yes	###lose 300SocCur
			}
			random_list = {				###Will randomly remove one sin that target has and you don't
				10 = {
					modifier = {
						factor = 0
						OR = {
							NOT = { trait = lustful }
							FROM = { trait = lustful }
						}
					}
					set_character_flag = spiritual_guidance_lustful
					remove_trait = lustful
				}
				10 = {
					modifier = {
						factor = 0
						OR = {
							NOT = { trait = gluttonous }
							FROM = { trait = gluttonous }
						}
					}
					set_character_flag = spiritual_guidance_gluttonous
					remove_trait = gluttonous
				}
				10 = {
					modifier = {
						factor = 0
						OR = {
							NOT = { trait = greedy }
							FROM = { trait = greedy }
						}
					}
					set_character_flag = spiritual_guidance_greedy
					remove_trait = greedy
				}
				10 = {
					modifier = {
						factor = 0
						OR = {
							NOT = { trait = slothful }
							FROM = { trait = slothful }
						}
					}
					set_character_flag = spiritual_guidance_slothful
					remove_trait = slothful
				}
				10 = {
					modifier = {
						factor = 0
						OR = {
							NOT = { trait = wroth }
							FROM = { trait = wroth }
						}
					}
					set_character_flag = spiritual_guidance_wroth
					remove_trait = wroth
				}
				10 = {
					modifier = {
						factor = 0
						OR = {
							NOT = { trait = envious }
							FROM = { trait = envious }
						}
					}
					set_character_flag = spiritual_guidance_envious
					remove_trait = envious
				}
				10 = {
					modifier = {
						factor = 0
						OR = {
							NOT = { trait = proud }
							FROM = { trait = proud }
						}
					}
					set_character_flag = spiritual_guidance_proud
					remove_trait = proud
				}
			}
			opinion = {										###opinion mostly serves as a 10 years cooldown ; +5 Opinion
				who = FROM
				modifier = opinion_spiritual_guidance
				months = 120
			}
			FROM = { character_event = { id = SUFI.4950 } }
			character_event = { id = SUFI.4951 }
		}
		
		revoke_allowed = {
		always = no
		}
		
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0.1
			}
			modifier = {
				factor = 0
				NOT = {
					AND = {
						is_close_relative = FROM						###AI will only target landed relatives in the same realm
						same_realm = FROM
						OR = {
							is_landed = yes
							is_patrician = yes
						}
					}
				}
			}
		}
	}
	
	monastic_orders_teach_virtue_sufi = {  ### Monastic Order Rank 3 power : targeted decision to give target a virtue
		ai_check_interval = 12
		potential = {
			NOT = { trait = incapable }
			OR = {
				same_realm = FROM
				same_society_as = FROM
			}
			is_within_diplo_range = FROM
		}
		
		from_potential = {
			has_DLC = "Mystics"
			society_rank >= 3
			is_sufi_member_trigger = yes
			is_adult = yes
			NOT = { trait = incapable }
			religion = ROOT
		}
		
		allow = {
			FROM = {
				has_society_currency_major_trigger = yes	###requires 500SocCur
				is_inaccessible_trigger = no
				prisoner = no
				in_command = no
			}
			is_inaccessible_trigger = no
			prisoner = no
			in_command = no
			same_realm = FROM
			OR = {
				is_landed = yes
				is_patrician = yes
				is_close_relative = FROM
			}
			NOT = {
				has_opinion_modifier = {	###opinion modifier 10yrs cooldown
					who =  FROM
					modifier = opinion_teach_virtue
				}
			}
			custom_tooltip = {
				text = teach_virtue_tooltip
				OR ={
					# AND = {
						# NOT = { trait = chaste }
						# FROM = { trait = chaste }
					# }
					AND = {
						NOT = { trait = temperate }
						FROM = { trait = temperate }
					}
					AND = {
						NOT = { trait = charitable }
						FROM = { trait = charitable }
					}
					AND = {
						NOT = { trait = diligent }
						FROM = { trait = diligent }
					}
					AND = {
						NOT = { trait = patient }
						FROM = { trait = patient }
					}
					AND = {
						NOT = { trait = kind }
						FROM = { trait = kind }
					}
					AND = {
						NOT = { trait = humble }
						FROM = { trait = humble }
					}
				}
			}
		}
		
		effect = {
			FROM = {
				detract_society_currency_major_effect = yes	###lose 500SocCur
			}
			random_list = {				###Will randomly add one virtue that you have and target doesn't
				# 10 = {
					# modifier = {
						# factor = 0
						# OR = {
							# trait = chaste
							# FROM = { NOT = { trait = chaste } }
						# }
					# }
					# set_character_flag = teach_virtue_chaste
					# add_trait = chaste
				# }
				10 = {
					modifier = {
						factor = 0
						OR = {
							trait = temperate
							FROM = { NOT = { trait = temperate } }
						}
					}
					set_character_flag = teach_virtue_temperate
					add_trait = temperate
				}
				10 = {
					modifier = {
						factor = 0
						OR = {
							trait = charitable
							FROM = { NOT = { trait = charitable } }
						}
					}
					set_character_flag = teach_virtue_charitable
					add_trait = charitable
				}
				10 = {
					modifier = {
						factor = 0
						OR = {
							trait = diligent
							FROM = { NOT = { trait = diligent } }
						}
					}
					set_character_flag = teach_virtue_diligent
					add_trait = diligent
				}
				10 = {
					modifier = {
						factor = 0
						OR = {
							trait = patient
							FROM = { NOT = { trait = patient } }
						}
					}
					set_character_flag = teach_virtue_patient
					add_trait = patient
				}
				10 = {
					modifier = {
						factor = 0
						OR = {
							trait = kind
							FROM = { NOT = { trait = kind } }
						}
					}
					set_character_flag = teach_virtue_kind
					add_trait = kind
				}
				10 = {
					modifier = {
						factor = 0
						OR = {
							trait = humble
							FROM = { NOT = { trait = humble } }
						}
					}
					set_character_flag = teach_virtue_humble
					add_trait = humble
				}
			}
			opinion = {										###opinion mostly serves as a 10 years cooldown ; +10 Opinion
				who = FROM
				modifier = opinion_teach_virtue
				months = 120
			}
			FROM = { character_event = { id = SUFI.4960 } }
			character_event = { id = SUFI.4961 }
		}
		
		revoke_allowed = {
		always = no
		}
		
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0.1
			}
			modifier = {
				factor = 0
				NOT = {
					AND = {
						is_close_relative = FROM						###AI will only target landed relatives in the same realm
						same_realm = FROM
						OR = {
							is_landed = yes
							is_patrician = yes
						}
					}
				}
			}
		}
	}
	monastic_orders_send_decadent = {
		ai_check_interval = 12
		filter = home_court
		ai_target_filter = home_court
		
		potential = {
			trait = decadent
			dynasty = from
			is_sufi_member_trigger = no
			religion_group = muslim
			is_heretic = no
		}
		
		from_potential = {
			has_DLC = "Mystics"
			is_adult = yes
			religion_group = muslim
			is_heretic = no
		}
		
		allow = {
			NOT = { trait = incapable }
			FROM = { NOT = { trait = incapable } }
			is_inaccessible_trigger = no
			is_ruler = no
			is_in_society = no
			trait = decadent
			
		}
		
		effect = {
			FROM = { scaled_wealth = -0.4 }
			if = {
				limit = {
					has_sufi_societies_religion_sunni = yes
				}
				join_society = monastic_order_sunni
			}
			else_if = {
				limit = {
					has_sufi_societies_religion_shiite = yes
				}
				join_society = monastic_order_shiite
			}
			else_if = {
				limit = {
					has_sufi_societies_religion_ibadi = yes
				}
				join_society = monastic_order_ibadi
			}
			opinion = {
				who = FROM
				modifier = opinion_disgruntled
				months = 120
			}
		}
		
		revoke_allowed = {
		always = no
		}
		
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0.1
			}
			modifier = {
				factor = 0
				NOT = {
					FROM = { scaled_wealth = 0.5 }
				}
			}
			modifier = {
				factor = 0
				OR = {
					AND = {
						has_sufi_societies_religion_sunni = yes
						ai = yes
						is_society_rank_full = { 
							society = monastic_order_sunni
							rank = 1
						}
					}
					AND = {
						has_sufi_societies_religion_shiite = yes
						ai = yes
						is_society_rank_full = { 
							society = monastic_order_shiite
							rank = 1
						}
					}
					AND = {
						has_sufi_societies_religion_ibadi = yes
						ai = yes
						is_society_rank_full = { 
							society = monastic_order_ibadi
							rank = 1
						}
					}
				
				}
			}
		}
	}
}

title_decisions = {
	# Monastic Order Rank 4 Power - Convert County
	monastic_order_convert_county_sufi = {
		only_playable = yes
		ai_check_interval = 3
		
		from_potential = {
			has_dlc = "Mystics"
			is_ruler = yes
			is_sufi_member_trigger = yes
			society_rank == 4
		}
		
		potential = {
			tier = COUNT
			location = { NOT = { religion = FROM } }
			holder_scope = {
				OR = {
					is_liege_or_above = FROM
					character = FROM
				}
			}
		}
		
		allow = {
			FROM = {
				society_currency >= 1000
			}
			location = {
				NOT = { religion = FROM }
				owner = { NOT = { religion = PREV } } # Cannot convert counties of owners who has that religion
			}
		}
		
		effect = {
			FROM = {
				change_society_currency = -1000
				hidden_tooltip = { character_event = { id = SUFI.4990 } }
			}
			location = {
				religion = FROM
				add_province_modifier = {
					name = religious_tension
					years = 2
				}
			}
			hidden_tooltip = {
				if = { # Notify county owner
					limit = {
						holder_scope = { NOT = { character = FROM } }
					}
					holder_scope = { character_event = { id = SUFI.4991 } }
				}
			}
		}
		
		ai_will_do = {
			factor = 1
		}
	}
}