# muslim_county_conquest
# muslim_invasion
# cb_decadence_usurption
# caliphal_subjugation
# decadence_invasion
# shia_caliphate_rising

muslim_county_conquest = {
	name = CB_NAME_COUNTY_CONQUEST
	war_name = WAR_NAME_COUNTY_CONQUEST
	sprite = 16
	truce_days = 1825
	sort_priority = 700

	hostile_against_others = yes
	is_permanent = yes
	check_all_titles = yes # if permanent, setting this to true will check against all of someones titles, including vassal held titles
	can_ask_to_join_war = no
	allowed_to_target_tributaries = no
	press_claim = yes

	can_use_gui = {
		# Attacker
		ROOT = {
			piety >= 50

			# CK2Plus
			can_use_cb_preamble = yes
		}
	}

	can_use = {
		# Attacker
		ROOT = {
			religion_group = muslim
			NOT = { is_vassal_or_below_of = FROM }
			is_nomadic = no # Use the 'pagan_county_conquest' CB instead
			mercenary = no

			# CK2Plus
			NOT = { has_character_modifier = county_conquest_timer }

			# Special Cases
			NOR = {
				trigger_if = {
					limit = {
						OR = {
							has_landed_title = e_ilkhanate
							has_landed_title = e_golden_horde
							has_landed_title = e_chagatai
							has_landed_title = e_mongol_empire
						}
					}

					religion = tengri_pagan
				}

				has_character_flag = horde_seljuk
				has_character_flag = horde_seljuk2
				has_character_flag = alp_arslan
				has_landed_title = e_timurids
			}
		}
	}

	can_use_title = {
		real_tier = COUNT

		holder_scope = {
			OR = {
				character = FROM

				AND = {
					is_vassal_or_below_of = FROM
					NOT = { same_realm = ROOT }
				}
			}
		}

		# Only bordering counties
		location = {
			any_neighbor_province = {
				owner = {
					OR = {
						character = ROOT
						is_vassal_or_below_of = ROOT
					}
				}
			}
		}
	}

	is_valid_title = {
		holder_scope = {
			OR = {
				character = FROM
				is_vassal_or_below_of = FROM
			}
		}
	}

	on_add = {
		attacker = {
			show_scope_change = no

			piety = -50
		}

		fire_haruspicy_event_effect = yes
		anger_china_effect = yes
	}

	on_success_title = {
		log = "[Root.GetBestName] (ID: [Root.GetID]) succeeded with [Root.GetHerHis] muslim county conquest for the [This.GetFullName] against [From.GetBestName] (ID: [From.GetID])"

		if = { # Vassalise one county counts
			limit = {
				holder_scope = {
					real_tier = COUNT
					num_of_count_titles == 1
					lower_real_tier_than = attacker
					is_patrician = no
				}
			}

			holder_scope = {
				show_scope_change = no

				set_defacto_liege = attacker
				pf_liege_change_effect = yes
			}
		}

		else = { # Usurp title under other circumstances
			usurp_title_plus_barony_if_unlanded = {
				target = attacker
				type = invasion
			}

			any_de_jure_vassal_title = { # take all baronies under the one we're fighting for
				show_scope_change = no

				limit = {
					NOT = { de_facto_liege = PREV }

					holder_scope = {
						OR = {
							character = defender
							is_vassal_or_below_of = defender
						}
					}
				}

				usurp_title_plus_barony_if_unlanded = {
					target = attacker
					type = invasion
				}
			}
		}

		attacker = {
			show_scope_change = no

			participation_scaled_prestige = 200
		}

		any_attacker = {
			limit = { NOT = { character = attacker } }
			hidden_effect = { participation_scaled_prestige = 200 }
		}
	}

	on_fail_title = {
		attacker = {
			show_scope_change = no

			prestige = -100

			hidden_effect = {
				add_character_modifier = {
					name = county_conquest_timer
					years = 5
				}
			}
		}

		defender = {
			show_scope_change = no

			participation_scaled_prestige = 50
		}

		any_defender = {
			limit = { NOT = { character = defender } }
			hidden_effect = { participation_scaled_prestige = 50 }
		}
	}

	on_reverse_demand = {
		attacker = {
			show_scope_change = no

			prestige = -200

			transfer_scaled_wealth = {
				to = defender
				value = 4.0
			}

			hidden_effect = {
				if = {
					limit = {
						ai = no
						has_global_flag = hardcore_mode
					}

					add_character_modifier = {
						name = county_conquest_timer
						years = 10
					}
				}
				else = {
					add_character_modifier = {
						name = county_conquest_timer
						years = 5
					}
				}
			}
		}

		defender = {
			show_scope_change = no

			participation_scaled_prestige = 200
		}

		any_defender = {
			limit = { NOT = { character = defender } }
			hidden_effect = { participation_scaled_prestige = 200 }
		}
	}

	attacker_ai_victory_worth = {
		factor = -1 # always accept
	}

	attacker_ai_defeat_worth = {
		factor = 100
	}

	defender_ai_victory_worth = {
		factor = -1 # always accept
	}

	defender_ai_defeat_worth = {
		factor = 100
	}

	ai_will_do = {
		factor = 0.9 # Prefer using CB's without on_add costs

		trigger = {
			ROOT = {
				sufficient_treasury_for_war_trigger = yes
			}

		#	trigger_if = {
		#		limit = {
		#			ROOT = {
		#				is_tribal = yes
		#			}
		#
		#			FROM = {
		#				is_nomadic = yes
		#			}
		#		}
		#
		#		any_direct_de_jure_vassal_title = {
		#			any_direct_de_jure_vassal_title = {
		#				OR = {
		#					holding_type = castle
		#					holding_type = city
		#					holding_type = tribal
		#				}
		#			}
		#		}
		#	}
		#	trigger_else_if = {
		#		limit = {
		#			ROOT = {
		#				is_nomadic = no
		#				is_tribal = no
		#			}
		#
		#			FROM = {
		#				is_nomadic = yes
		#			}
		#
		#		}
		#
		#		any_direct_de_jure_vassal_title = {
		#			any_direct_de_jure_vassal_title = {
		#				OR = {
		#					holding_type = castle
		#					holding_type = city
		#				}
		#			}
		#		}
		#	}

			trigger_if = {
				limit = {
					ROOT = {
						has_character_flag = is_temujin
						has_landed_title = e_mongol_empire
						is_landed = yes
					}
				}

				FROM = {
					NOT = { has_landed_title = e_china_west_governor }
				}
			}
		}
	}
}

# 27 - Disabled in CK2Plus
muslim_invasion = {
	name = CB_NAME_INVASION
	war_name = WAR_NAME_INVASION
	sprite = 8
	truce_days = 3650
	sort_priority = 2000

	hostile_against_others = yes
	is_permanent = no # Disabled in CK2Plus
	is_holy_war = yes
	can_ask_to_join_war = yes
	check_de_jure_tier = KING # this scans all de jure kingdoms for the counties which are held by or vassals(or below) of selected character. Only valid if is_permanent = yes
	allowed_to_target_tributaries = no

	can_use_gui = {
		# Attacker
		ROOT = {
			piety >= 1000
		}
	}

	can_use = {
		always = no # Disabled in CK2Plus

		# Attack
		ROOT = {
			religion_group = muslim

			NOR = {
				religion = FROM
				is_vassal_or_below_of = FROM
			}

			trigger_if = {
				limit = {
					ai = no
					multiplayer = yes
				}

				NOT = {
					has_game_rule = {
						name = multiplayer_invasions
						value = off
					}
				}
			}

			# These use 'tribal_invasion' instead
			is_nomadic = no
			mercenary = no
		}
	}

	can_use_title = {
		# Muslims require the target to have at least 6 counties within the target kingdom
		FROM = {
			num_of_realm_counties = {
				value >= 6
				title = PREV
			}
		}

		# The attacker needs at least one county in the target kingdom, or a border
		any_direct_de_jure_vassal_title = {		# duchy level
			any_direct_de_jure_vassal_title = {	# county level
				OR = {
					holder_scope = { # Own a county
						OR = {
							character = ROOT
							is_vassal_or_below_of = ROOT
						}
					}

					location = {
						any_neighbor_province = { # or share a border
							owner = {
								OR = {
									character = ROOT
									is_vassal_or_below_of = ROOT
								}
							}
						}
					}
				}
			}
		}
	}

	is_valid = {
		# Attacker
		ROOT = {
			religion_group = muslim
			NOT = { religion = FROM }
		}
	}

	is_valid_title = {
		# Defender
		FROM = {
			num_of_realm_counties = {
				value >= 1
				title = PREV
			}
		}
	}

	on_add = {
		attacker = {
			show_scope_change = no

			piety = -1000
		}

		fire_haruspicy_event_effect = yes
		anger_china_effect = yes
	}

	on_success = {
		attacker = {
			show_scope_change = no

			prestige = 200
			participation_scaled_prestige = 200

			if = {
				limit = {
					uses_decadence = yes
					defender = { uses_decadence = no }
				}

				participation_scaled_decadence = -20
			}

			hidden_effect = {
				if = {
					limit = { has_ambition = obj_strengthen_religion }

					change_variable = {
						which = strengthen_religion
						value = 1
					}
				}
			}
		}

		any_attacker = {
			limit = { NOT = { character = attacker } }

			hidden_effect = {
				participation_scaled_prestige = 200

				if = {
					limit = {
						uses_decadence = yes
						defender = { uses_decadence = no }
					}

					participation_scaled_decadence = -20
				}

				if = {
					limit = { has_ambition = obj_strengthen_religion }

					change_variable = {
						which = strengthen_religion
						value = 1
					}
				}
			}
		}

		defender = {
			show_scope_change = no

			prestige = -200
		}
	}

	on_success_title = {
		custom_tooltip = {
			text = other_invasion_succ_tip

			attacker = {
				vassalize_or_take_under_title_destroy_duchies = {
					title = PREV
					enemy = defender
					is_crusade = no # Even if the title holder is not participating in the war, gain holdings occupied by all Crusade participants
					type = invasion
				}

				if = {
					limit = {
						trigger_if = {
							limit = { has_nickname = yes }
							this_has_lame_nickname_trigger = yes
						}
					}

					random_list = {
						10 = { give_nickname = nick_the_holy }
						10 = { give_nickname = nick_the_glorious }
						10 = { give_nickname = nick_the_lionheart }
						10 = { give_nickname = nick_the_great }
						10 = { give_nickname = nick_the_hammer }
						10 = { give_nickname = nick_the_magnificent }
					}
				}
			}
		}
	}

	on_fail = {
		attacker = {
			show_scope_change = no

			prestige = -200
		}

		defender = {
			show_scope_change = no

			prestige = 100
			participation_scaled_prestige = 100

			hidden_effect = {
				roman_victory_triumph_effect = yes

				if = {
					limit = {
						trigger_if = {
							limit = { has_nickname = yes }
							this_has_lame_nickname_trigger = yes
						}
					}

					random_list = {
						10 = { give_nickname = nick_the_holy }
						10 = { give_nickname = nick_the_glorious }
						10 = { give_nickname = nick_the_lionheart }
						10 = { give_nickname = nick_the_great }
						10 = { give_nickname = nick_the_hammer }
						10 = { give_nickname = nick_the_magnificent }
						10 = { give_nickname = nick_the_avenger }
					}
				}
			}
		}

		any_defender = {
			limit = { NOT = { character = defender } }
			hidden_effect = { participation_scaled_prestige = 100 }
		}
	}

	on_invalidation = {
		attacker = {
			show_scope_change = no

			piety = 1000
		}
	}

	on_reverse_demand = {
		attacker = {
			show_scope_change = no

			prestige = -200
			transfer_scaled_wealth = {
				to = defender
				value = 4.0
			}

			if = {
				limit = {
					NOT = {
						any_liege = {
							dynasty = PREV
						}
					}
				}

				decadence = 10
			}
		}

		defender = {
			show_scope_change = no

			prestige = 200
			participation_scaled_prestige = 200

			hidden_effect = {
				roman_victory_triumph_effect = yes

				if = {
					limit = { has_ambition = obj_strengthen_religion }

					change_variable = {
						which = strengthen_religion
						value = 1
					}
				}

				if = {
					limit = {
						trigger_if = {
							limit = { has_nickname = yes }
							this_has_lame_nickname_trigger = yes
						}
					}

					random_list = {
						10 = { give_nickname = nick_the_holy }
						10 = { give_nickname = nick_the_glorious }
						10 = { give_nickname = nick_the_lionheart }
						10 = { give_nickname = nick_the_great }
						10 = { give_nickname = nick_the_hammer }
						10 = { give_nickname = nick_the_magnificent }
						10 = { give_nickname = nick_the_avenger }
					}
				}
			}
		}

		any_defender = {
			limit = { NOT = { character = defender } }

			hidden_effect = {
				participation_scaled_prestige = 200

				if = {
					limit = { has_ambition = obj_strengthen_religion }

					change_variable = {
						which = strengthen_religion
						value = 1
					}
				}
			}
		}
	}

	attacker_ai_victory_worth = {
		factor = 100
	}

	attacker_ai_defeat_worth = {
		factor = 100
	}

	defender_ai_victory_worth = {
		factor = -1 # always accept
	}

	defender_ai_defeat_worth = {
		factor = 150
	}

	ai_will_do = {
		factor = 0.9 # Prefer using CB's without on_add costs

		trigger = {
			trigger_if = {
				limit = {
					ROOT = {
						is_tribal = yes
					}

					FROM = {
						is_nomadic = yes
					}
				}

				any_direct_de_jure_vassal_title = {
					any_direct_de_jure_vassal_title = {
						OR = {
							holding_type = castle
							holding_type = city
							holding_type = tribal
						}
					}
				}
			}
			trigger_else_if = {
				limit = {
					ROOT = {
						is_nomadic = no
						is_tribal = no
					}

					FROM = {
						is_nomadic = yes
					}
				}

				any_direct_de_jure_vassal_title = {
					any_direct_de_jure_vassal_title = {
						OR = {
							holding_type = castle
							holding_type = city
						}
					}
				}
			}
		}
	}
}

cb_decadence_usurption = {
	name = CB_NAME_DECADENCE_USURPTION
	war_name = WAR_NAME_DECADENCE_USURPTION
	sprite = 11
	truce_days = 3650

	is_permanent = yes
	allowed_to_target_tributaries = no

	can_use_gui = {
		# CK2Plus
		# Attacker
		ROOT = {
			can_use_cb_preamble = yes
		}
	}

	can_use = {
		# Attacker
		ROOT = {
			religion_group = muslim
			religion = FROM
			mercenary = no
			holy_order = no
		}

		# Defender
		FROM = {
			trait = decadent
			dynasty = ROOT

			liege_before_war = {
				character = ROOT
			}
		}
	}

	is_valid = {
		# Defender
		FROM = {
			trait = decadent

			liege_before_war = {
				character = ROOT
			}
		}
	}

	is_valid_title = {
		holder = ROOT
	}

	on_add = {
		fire_haruspicy_event_effect = yes
		anger_china_effect = yes
	}

	on_success = {
		attacker = {
			show_scope_change = no

			participation_scaled_piety = 500
			participation_scaled_prestige = 250
		}

		any_attacker = {
			limit = { NOT = { character = attacker } }

			hidden_effect = {
				participation_scaled_piety = 500
				participation_scaled_prestige = 250
			}
		}

		defender = {
			show_scope_change = no

			imprison = attacker
		}
	}

	on_success_title = {
		log = "[Root.GetBestName] (ID: [Root.GetID]) succeeded with [Root.GetHerHis] decadence usurpation against the [This.GetFullName] against [From.GetBestName] (ID: [From.GetID])"

		usurp_title_plus_barony_if_unlanded = {
			target = attacker
			type = invasion
		}
	}

	on_fail = {
		attacker = {
			show_scope_change = no

			piety = -250
			prestige = -125
		}

		defender = {
			show_scope_change = no

			piety = 100
			prestige = 50
		}
	}

	on_reverse_demand = {
		attacker = {
			show_scope_change = no

			transfer_scaled_wealth = {
				to = defender
				value = 2.0
			}

			piety = -500
			prestige = -250
		}

		defender = {
			show_scope_change = no

			piety = 500
			prestige = 250
		}
	}

	attacker_ai_victory_worth = {
		factor = -1 # always accept
	}

	attacker_ai_defeat_worth = {
		factor = 100
	}

	defender_ai_victory_worth = {
		factor = -1 # always accept
	}

	defender_ai_defeat_worth = {
		factor = 100
	}
}
# Caliphs can subjugate people of their own religion
# Disabled in CK2Plus
caliphal_subjugation = {
	name = CB_NAME_PAGAN_SUBJUGATION
	war_name = WAR_NAME_PAGAN_SUBJUGATION
	sprite = 8
	truce_days = 365
	sort_priority = 1000

	hostile_against_others = yes
	is_permanent = no # Disabled in CK2Plus
	can_ask_to_join_war = yes
	check_de_jure_tier = KING # this scans all de jure kingdoms for the counties which are held by or vassals(or below) of selected character. Only valid if is_permanent = yes
	allowed_to_target_tributaries = no

	can_use_gui = {
		# Attacker
		ROOT = {
			piety >= 200
		}
	}

	can_use = {
		always = no # Disabled in CK2Plus

		# Attacker
		ROOT = {
			controls_religion = yes
			religion_group = muslim
			religion = FROM
			is_nomadic = no
			mercenary = no
			NOT = { has_character_modifier = launched_subjugation }

			trigger_if = {
				limit = {
					ai = no
					multiplayer = yes
				}

				NOT = {
					has_game_rule = {
						name = multiplayer_invasions
						value = off
					}
				}
			}

			# Should use 'tribal_invasion' instead
			trigger_if = {
				limit = { has_horde_culture = yes }
				NOT = { has_dlc = "Horse Lords" }
			}
		}

		# Defender
		FROM = {
			NOT = { is_offmap_governor = yes }
		}
	}

	can_use_title = {
		# Defender
		FROM = {
			num_of_realm_counties = {
				value >= 1
				title = PREV
			}
		}
	}

	is_valid_title = {
		# Defender
		FROM = {
			num_of_realm_counties = {
				value >= 1
				title = PREV
			}
		}
	}

	on_add = {
		attacker = {
			show_scope_change = no

			piety = -200

			add_character_modifier = {
				name = launched_subjugation
				years = 10
				hidden = yes
			}
		}

		fire_haruspicy_event_effect = yes
		anger_china_effect = yes
	}

	on_success = {
		attacker = {
			show_scope_change = no

			prestige = 100
			participation_scaled_prestige = 100
			decadence = -5
		}

		any_attacker = {
			limit = { NOT = { character = attacker } }
			hidden_effect = { participation_scaled_prestige = 100 }
		}

		defender = {
			show_scope_change = no

			prestige = -200
		}
	}

	on_success_title = {
		custom_tooltip = {
			text = pagan_subjugation_tip

			attacker = {
				subjugate_or_take_under_title = { # If the target only has territory within the kingdom, he is simply vassalized
					title = PREV
					enemy = defender
				}
			}
		}
	}

	on_fail = {
		attacker = {
			show_scope_change = no

			prestige = -100
		}

		defender = {
			show_scope_change = no

			prestige = 50
			participation_scaled_prestige = 50
		}

		any_defender = {
			limit = { NOT = { character = defender } }
			hidden_effect = { participation_scaled_prestige = 50 }
		}
	}

	on_reverse_demand = {
		attacker = {
			show_scope_change = no

			prestige = -200

			transfer_scaled_wealth = {
				to = defender
				value = 2.0
			}
		}

		defender = {
			show_scope_change = no

			prestige = 100
			participation_scaled_prestige = 100
			roman_victory_triumph_effect = yes
		}

		any_defender = {
			limit = { NOT = { character = defender } }
			hidden_effect = { participation_scaled_prestige = 100 }
		}
	}

	attacker_ai_victory_worth = {
		factor = -1 # always accept
	}

	attacker_ai_defeat_worth = {
		factor = 100
	}

	defender_ai_victory_worth = {
		factor = -1 # always accept
	}

	defender_ai_defeat_worth = {
		factor = 100
	}

	ai_will_do = {
		factor = 0.9 # Prefer using CB's without on_add costs
	}
}

# Disabled in CK2Plus
decadence_invasion = {
	name = CB_NAME_INVASION
	war_name = WAR_NAME_DEC_INVASION
	sprite = 7
	truce_days = 3650

	is_permanent = no # Disabled in CK2Plus
	hostile_against_others = yes
	can_ask_to_join_war = no

	can_use = {
		always = no # Disabled in CK2Plus

		# Attacker
		ROOT = {
			has_character_flag = decadence_invader
		}
	}

	on_add = {
		fire_haruspicy_event_effect = yes
		anger_china_effect = yes
	}

	on_success = {
		# Attackers
		attacker = {
			show_scope_change = no

			prestige = 200
			piety = 100
			occupy_minors_of_occupied_settlements = defender

			gain_all_occupied_titles = {
				who = defender
				type = revolt
			}

			give_nickname = nick_the_conqueror
			participation_scaled_prestige = 200
			participation_scaled_piety = 100

			hidden_effect = {
				disband_event_forces = decadence_revolters
			}
		}

		any_attacker = {
			limit = { NOT = { character = attacker } }

			hidden_effect = {
				participation_scaled_prestige = 200
				participation_scaled_piety = 100
			}
		}

		# Defender
		defender = {
			show_scope_change = no

			prestige = -200

			if = { # reset crown authority to minimum
				limit = { NOT = { has_dlc = "Conclave" } }

				any_demesne_title = {
					limit = { is_crown_law_title = yes }

					set_title_flag = non_manual_law_change # No prestige loss
					add_law = crown_authority_0
					clr_title_flag = non_manual_law_change # No prestige loss
				}
			}

			primary_title = {
				show_scope_change = no

				holder_scope = {
				show_scope_change = no

					any_demesne_title = { # eligible duke and king tier titles usurped
						show_scope_change = no

						limit = {
							higher_real_tier_than = COUNT
							NOT = { real_tier = PREVPREV }
						}

						usurp_title_plus_barony_if_unlanded = {
							target = attacker
							type = revolt
						}

						hidden_effect = {
							if = {
								limit = {
									NOT = { culture = attacker }
								}

								conquest_culture = attacker
							}
						}
					}

					any_demesne_title = { # top titles destroyed
						show_scope_change = no

						limit = { real_tier = PREVPREV }

						destroy_landed_title = THIS
					}
				}
			}

			set_defacto_liege = attacker
			imprison = attacker

			hidden_effect = {
				if = {
					limit = { has_nickname = no }

					random_list = {
						10 = { give_nickname = nick_the_decadent }
						10 = { give_nickname = nick_the_unready }
						10 = { give_nickname = nick_the_ill_ruler }
					}
				}

			}
		}

		hidden_effect = {
			any_player = { # Inform human players
				limit = {
					NOR = {
						character = defender
						dynasty = defender
						is_vassal_or_below_of = defender
					}

					trigger_if = {
						limit = { # Don't bother with insignificant overthrowals
							defender = { higher_real_tier_than = DUKE }
						}

						# Unless the player borders them
						shares_realm_border_with = defender
					}
				}

				narrative_event = {
					id = 91241 # The ruling dynasty has been overthrown by ...
				}
			}

			check_if_reconquista_finished_effect = yes

			defender = {
				landless_pope_effect = yes
			}
		}
	}

	on_fail = {
		attacker = {
			show_scope_change = no

			prestige = -200
			hidden_effect = { disband_event_forces = decadence_revolters}
		}

		defender = {
			show_scope_change = no

			prestige = 100
			participation_scaled_prestige = 100
		}

		any_defender = {
			limit = { NOT = { character = defender } }
			hidden_effect = { participation_scaled_prestige = 100 }
		}
	}

	on_reverse_demand = {
		attacker = {
			show_scope_change = no

			prestige = -200
			set_defacto_liege = defender
			imprison = defender

			transfer_scaled_wealth = {
				to = defender
				value = 8.0
			}

			hidden_effect = { disband_event_forces = decadence_revolters }
		}

		defender = {
			show_scope_change = no

			prestige = 200
			if = {
				limit = {
					ai = no
					is_ironman = yes
					NOT = { has_character_flag = achievement_decadent_warrior }
				}

				set_character_flag = achievement_decadent_warrior
			}
		}
	}

	on_reverse_demand_title = {
		attacker = {
			show_scope_change = no

			remove_claim = PREV
		}
	}

	attacker_ai_victory_worth = {
		factor = 100
	}

	attacker_ai_defeat_worth = {
		factor = 100
	}

	defender_ai_victory_worth = {
		factor = -1 # always accept
	}

	defender_ai_defeat_worth = {
		factor = 150
	}
}

# The special CB for the Rise of the Shi'a Caliphate
shia_caliphate_rising = {
	name = CB_NAME_SHIA_CALIPHATE_RISING
	war_name = WAR_NAME_SHIA_CALIPHATE_RISING
	sprite = 8
	truce_days = 365

	hostile_against_others = no
	check_de_jure_tier = KING # this scans all de jure kingdoms for the counties which are held by or vassals(or below) of selected character
	apply_short_occ_mod = no # Do not apply the 'recently_conquered' modifier to Holdings

	can_use = {
		# Attacker
		ROOT = {
			has_character_flag = shia_caliphate_pretender
		}
	}

	is_valid = {
		# Attacker
		ROOT = {
			has_character_flag = shia_caliphate_pretender
		}
	}

	is_valid_title = {
		# Defender
		FROM = {
			num_of_realm_counties = {
				value >= 1
				title = PREV
			}
		}

		d_shiite = {
			has_holder = no
		}
	}

	on_add = {
		fire_haruspicy_event_effect = yes
		anger_china_effect = yes
	}

	on_success = {
		attacker = {
			show_scope_change = no

			piety = 500

			religion_authority = {
				name = rise_of_the_shia_caliphate
			}

			clr_character_flag = shia_caliphate_pretender
		}

		defender = {
			show_scope_change = no

			piety = -500

			# CK2Plus
			imperial_decadence_plus_2_effect = yes

			religion_authority = {
				name = shia_victorious1
			}
		}

		clr_global_flag = shia_caliphate_revolt_ongoing
	}

	on_success_title = {
		log = "[Root.GetBestName] (ID: [Root.GetID]) succeeded with [Root.GetHerHis] Shia caliphate rising for the [This.GetFullName] against [From.GetBestName] (ID: [From.GetID])"

		custom_tooltip = {
			text = other_invasion_succ_tip

			d_shiite = {
				usurp_title = {
					target = attacker
					type = holy_war
				}
			}

			defender = {
				while = {
					count = 5

					random_realm_province = {
						limit = {
							de_jure_liege_or_above = PREVPREV
							religion_group = muslim
							NOT = { religion = attacker }
							held_under_PREV = yes
						}

						religion = attacker
					}
				}
			}

			attacker = {
				remove_trait = shiite_claimant
				occupy_minors_of_occupied_settlements = defender

				gain_all_occupied_titles = {
					who = defender
					type = revolt
				}

				if = {
					limit = {
						PREV = {
							trigger_if = {
								limit = { has_holder = yes }
								holder = defender
							}
						}
					}

					usurp_title = {
						target = PREV
						type = revolt
					}
				}

				if = {
					limit = { lower_real_tier_than = KING }

					create_title = {
						tier = KING
						landless = no
						temporary = no
						custom_created = yes
						culture = attacker
						holder = attacker
						name = SHIA_CUSTOM_FALLBACK
						base_title = PREV
						copy_title_laws = yes
					}
				}

				vassalize_or_take_under_title = {
					title = PREV
					enemy = defender
					is_religious = yes
					type = revolt
				}

				any_demesne_title = {
					limit = { real_tier = BARON }
					set_title_flag = refill_levy
				}

				wealth = 500
			}

			defender = {
				if = {
					limit = { is_vassal_or_below_of = attacker }

					imprison = attacker
				}
			}
		}
	}

	on_fail = {
		attacker = {
			show_scope_change = no

			piety = -250
			clr_character_flag = shia_caliphate_pretender
		}

		defender = {
			show_scope_change = no

			piety = 250
		}

		clr_global_flag = shia_caliphate_revolt_ongoing
	}

	on_reverse_demand = {
		attacker = {
			show_scope_change = no

			piety = -500
			clr_character_flag = shia_caliphate_pretender
			imprison = defender
		}

		defender = {
			show_scope_change = no

			piety = 250
			participation_scaled_piety = 250
			imperial_decadence_minus_2_effect = yes
		}

		any_defender = {
			limit = { NOT = { character = defender } }
			hidden_effect = { participation_scaled_piety = 250 }
		}

		clr_global_flag = shia_caliphate_revolt_ongoing
	}

	on_attacker_leader_death = {
		attacker = {
			clr_character_flag = shia_caliphate_pretender
		}

		clr_global_flag = shia_caliphate_revolt_ongoing
		end_war = invalid
	}

	on_invalidation = {
		log = "CB(shia_caliphate_rising): INVALIDATED: [Root.GetTitledFirstName] of [Root.PrimaryTitle.GetBaseName] (ID: [Root.GetID]) vs. [From.GetTitledFirstName] of [From.PrimaryTitle.GetBaseName] (ID: [From.GetID])"
		clr_global_flag = shia_caliphate_revolt_ongoing

	}

	attacker_ai_victory_worth = {
		factor = -1
	}

	attacker_ai_defeat_worth = {
		factor = 100
	}

	defender_ai_victory_worth = {
		factor = -1 # always accept
	}

	defender_ai_defeat_worth = {
		factor = 100
	}
}

