namespace = kccwaxwane

### Religions in China

# Wax & Wane of Catholicism
character_event = {
	id = kccwaxwane.0001
	hide_window = yes
	
	is_triggered_only = yes
	
	has_dlc = "Jade Dragon"
	only_playable = yes
	
	trigger = {
		has_landed_title = e_china_west_governor
	}
	
	after = {
		if = {
			limit = {
				check_variable = { which = "global_chinese_catholics" value = 20 }
				NOT = { has_global_flag = catholic_china_one }
			}
			set_global_flag = catholic_china_one
			set_global_flag = kcc_waxwane_catholics
			any_playable_ruler = { narrative_event = { id = kccspread.0003 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_catholics" value = 40 }
				NOT = { has_global_flag = catholic_china_two }
			}
			set_global_flag = catholic_china_two
			set_global_flag = kcc_waxwane_catholics
			any_playable_ruler = { narrative_event = { id = kccspread.0004 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_catholics" value = 100 }
				NOT = { has_global_flag = catholic_china_three }
			}
			set_global_flag = catholic_china_three
			set_global_flag = kcc_waxwane_catholics
			any_playable_ruler = { narrative_event = { id = kccspread.0005 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_catholics" value = 180 }
				NOT = { has_global_flag = catholic_china_four }
				kcc_nontaoist_majority_trigger = yes
			}
			kcc_drop_other_religion_effect = yes
			set_global_flag = catholic_china_four
			set_global_flag = kcc_waxwane_catholics
			any_playable_ruler = { narrative_event = { id = kccspread.0007 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_catholics" value = 180 }
				NOT = { has_global_flag = catholic_china_four }
			}
			set_global_flag = catholic_china_four
			set_global_flag = kcc_waxwane_catholics
			any_playable_ruler = { narrative_event = { id = kccspread.0006 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_catholics" value = 100 } }
				has_global_flag = catholic_china_three
			}
			clr_global_flag = catholic_china_three
			set_global_flag = kcc_waxwane_catholics
			any_playable_ruler = { narrative_event = { id = kccspread.0008 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_catholics" value = 40 } }
				has_global_flag = catholic_china_two
			}
			clr_global_flag = catholic_china_two
			set_global_flag = kcc_waxwane_catholics
			any_playable_ruler = { narrative_event = { id = kccspread.0009 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_catholics" value = 20 } }
				has_global_flag = catholic_china_one
			}
			clr_global_flag = catholic_china_one
			set_global_flag = kcc_waxwane_catholics
			any_playable_ruler = { narrative_event = { id = kccspread.0010 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_catholics" value = 0 } }
				has_global_flag = catholics_in_china
			}
			clr_global_flag = catholics_in_china
			set_variable = { which = "global_chinese_catholics" value = 0 }
			set_global_flag = kcc_waxwane_catholics
			any_playable_ruler = { narrative_event = { id = kccspread.0011 days = 1 } }
		}
	}
	
	weight_multiplier = {
		days = 17
		modifier = {
			factor = 0
			NOT = { has_global_flag = catholics_in_china }
		}
		modifier = {
			factor = 0
			1513 = {
				OR = {
					has_province_modifier = kcc_china_persecuted_christians
					has_province_modifier = kcc_china_persecuted_latins
					has_province_modifier = kcc_china_persecuted_catholics
				}
			}
		}
		modifier = {
			factor = 2
			offmap_china = { offmap_has_like = likes_christians }
		}
		modifier = {
			factor = 5
			offmap_china = { offmap_ruler = { religion = catholic } }
			NOR = {
				has_global_flag = catholic_china_two
				has_global_flag = catholic_china_three
				has_global_flag = catholic_china_four
			}
		}
		modifier = {
			factor = 4
			offmap_china = { offmap_ruler = { religion = catholic } }
			NOR = {
				has_global_flag = catholic_china_three
				has_global_flag = catholic_china_four
			}
		}
		modifier = {
			factor = 1.5
			offmap_china = { offmap_ruler = { religion = catholic } }
			NOT = { has_global_flag = catholic_china_four }
		}
		modifier = {
			factor = 0
			offmap_china = { offmap_ruler = { religion = catholic } }
			has_global_flag = catholic_china_four
		}
	}
	
	option = { #No change
	
		ai_chance = {
			factor = 30
		}
	}
	
	option = { #Wax
		if = {
			limit = {
				offmap_china = {
					OR = {
						offmap_ruler = { religion = catholic }
						offmap_china = { offmap_has_like = likes_christians }
					}
				}
			}
			change_variable = { which = "global_chinese_catholics" value = 2 }
		}
		else = {
			change_variable = { which = "global_chinese_catholics" value = 1 }
		}
		
		ai_chance = {
			factor = 60
			modifier = {
				factor = 1.1
				any_province = {
					OR = {
						region = custom_eastern_access
						region = world_india
					}
					religion = catholic
					culture = mongol
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = catholic
						OR = {
							culture = khitan
							culture = tangut
							culture = jurchen
							culture_group = chinese_group
						}
					}
				}
			}
			modifier = {
				factor = 1.2
				any_province = {
					OR = {
						region = custom_eastern_access
						region = world_india
					}
					religion = catholic
					OR = {
						culture = khitan
						culture = tangut
						culture = jurchen
					}
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = catholic
						culture_group = chinese_group
					}
				}
			}
			modifier = {
				factor = 1.3
				any_province = {
					OR = {
						region = custom_eastern_access
						region = world_india
					}
					religion = catholic
					culture_group = chinese_group
				}
			}
			modifier = {
				factor = 5
				OR = {
					offmap_china = { offmap_has_like = likes_christians }
					offmap_china = { offmap_ruler = { religion = catholic } }
				}
			}
			modifier = {
				factor = 1.5
				offmap_china = { offmap_ruler = { religion = catholic } }
				offmap_china = { offmap_ruler = { culture_group = chinese_group } }
			}
			modifier = {
				factor = 1.5
				offmap_china = { offmap_ruler = { religion = catholic } }
				offmap_china = { has_status = china_golden_age }
			}
			modifier = {
				factor = 0.2
				offmap_china = { offmap_ruler = { religion = catholic } }
				offmap_china = {
					OR = {
						has_status = china_unrest
						has_status = china_famine
						has_status = china_plague
					}
				}
			}
			modifier = {
				factor = 0.01
				offmap_china = { offmap_ruler = { religion = catholic } }
				offmap_china = {
					OR = {
						has_status = china_civil_war
						has_status = china_mongol_invasion
						has_status = china_jurchen_invasion
					}
				}
			}
			modifier = {
				factor = 3
				offmap_china = { offmap_ruler = { NOT = { religion = catholic } } }
				offmap_china = {
					OR = {
						has_status = china_unrest
						has_status = china_civil_war
					}
				}
			}
			modifier = {
				factor = 2
				OR = {
					AND = {
						offmap_china = { offmap_has_like = likes_indians }
						k_papal_state = { holder_scope = { culture_group = indo_aryan_group } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_dravidians }
						k_papal_state = { holder_scope = { culture_group = dravidian_group } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_tibetans }
						k_papal_state = { holder_scope = { culture_group = tibetan_group } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_germanics }
						k_papal_state = { holder_scope = {
							OR = {
								culture_group = north_germanic
								culture_group = central_germanic
								culture_group = west_germanic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_latino_iberians }
						k_papal_state = { holder_scope = {
							OR = {
								culture_group = latin
								culture_group = iberian
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_byzantines }
						k_papal_state = { holder_scope = { culture_group = byzantine } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_celts }
						k_papal_state = { holder_scope = { culture_group = celtic } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_finno_ugrics }
						k_papal_state = { holder_scope = {
							OR = {
								culture_group = finno_ugric
								culture_group = magyar
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_altaics }
						k_papal_state = { holder_scope = { culture_group = altaic } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_balto_slavics }
						k_papal_state = { holder_scope = {
							OR = {
								culture_group = baltic
								culture_group = east_slavic
								culture_group = west_slavic
								culture_group = south_slavic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_arabs }
						k_papal_state = { holder_scope = { culture_group = arabic } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_iranians }
						k_papal_state = { holder_scope = { culture_group = iranian } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_africans }
						k_papal_state = { holder_scope = {
							OR = {
								culture_group = west_african
								culture_group = east_african
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_mesoamericans }
						k_papal_state = { holder_scope = { culture_group = mesoamerican } }
					}
				}
			}
			modifier = {
				factor = 1.5
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = catholic
					any_realm_province = {
						region = custom_eastern_access
					}
					NOR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
					OR = {
						has_character_modifier = peace_deal_with_china
						has_character_modifier = chinese_imperial_trade_contract
						has_character_modifier = chinese_favored_in_trade
						has_offmap_currency = { offmap = offmap_china value = 1000 }
					}
				}
			}
			modifier = {
				factor = 0.33
				OR = {
					offmap_china = { offmap_ruler = { religion_group = muslim } }
					AND = {
						offmap_china = { offmap_ruler = { religion_group = christian } }
						offmap_china = { offmap_ruler = { NOT = { religion = catholic } } }
					}
					offmap_china = {
						offmap_ruler = {
							religion_group = pagan_group
							has_religion_feature = religion_dogmatic
						}
					}
				}
			}
			modifier = {
				factor = 1.33
				offmap_china = { offmap_ruler = { NOT = { religion = catholic } } }
				has_global_flag = pope_moved_to_china
			}
			modifier = {
				factor = 4
				offmap_china = { offmap_ruler = { religion = catholic } }
				has_global_flag = pope_moved_to_china
			}
		}
	}
	
	option = { #Wane
		if = {
			limit = {
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = catholic
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
			change_variable = { which = "global_chinese_catholics" value = -2 }
		}
		else = {
			change_variable = { which = "global_chinese_catholics" value = -1 }
		}
	
		ai_chance = {
			factor = 30
			modifier = {
				factor = 0
				offmap_china = { offmap_ruler = { religion = catholic } }
			}
			modifier = {
				factor = 0
				offmap_china = { offmap_has_like = likes_christians }
			}
			modifier = {
				factor = 0.1
				1513 = { has_province_modifier = kcc_recent_catholic_mission }
			}
			modifier = {
				factor = 2
				OR = {
					AND = {
						offmap_china = { offmap_has_dislike = likes_indians }
						k_papal_state = { holder_scope = { culture_group = indo_aryan_group } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_dravidians }
						k_papal_state = { holder_scope = { culture_group = dravidian_group } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_tibetans }
						k_papal_state = { holder_scope = { culture_group = tibetan_group } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_germanics }
						k_papal_state = { holder_scope = {
							OR = {
								culture_group = north_germanic
								culture_group = central_germanic
								culture_group = west_germanic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_latino_iberians }
						k_papal_state = { holder_scope = {
							OR = {
								culture_group = latin
								culture_group = iberian
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_byzantines }
						k_papal_state = { holder_scope = { culture_group = byzantine } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_celts }
						k_papal_state = { holder_scope = { culture_group = celtic } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_finno_ugrics }
						k_papal_state = { holder_scope = {
							OR = {
								culture_group = finno_ugric
								culture_group = magyar
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_altaics }
						k_papal_state = { holder_scope = { culture_group = altaic } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_balto_slavics }
						k_papal_state = { holder_scope = {
							OR = {
								culture_group = baltic
								culture_group = east_slavic
								culture_group = west_slavic
								culture_group = south_slavic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_arabs }
						k_papal_state = { holder_scope = { culture_group = arabic } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_iranians }
						k_papal_state = { holder_scope = { culture_group = iranian } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_africans }
						k_papal_state = { holder_scope = {
							OR = {
								culture_group = west_african
								culture_group = east_african
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_mesoamericans }
						k_papal_state = { holder_scope = { culture_group = mesoamerican } }
					}
				}
			}
			modifier = {
				factor = 1.5
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = catholic
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
		}
	}
}

# Wax & Wane of Catharism
character_event = {
	id = kccwaxwane.0002
	hide_window = yes
	
	is_triggered_only = yes
	
	has_dlc = "Jade Dragon"
	only_playable = yes
	
	trigger = {
		has_landed_title = e_china_west_governor
	}
	
	after = {
		if = {
			limit = {
				check_variable = { which = "global_chinese_cathars" value = 20 }
				NOT = { has_global_flag = cathar_china_one }
			}
			set_global_flag = cathar_china_one
			set_global_flag = kcc_waxwane_cathars
			any_playable_ruler = { narrative_event = { id = kccspread.0003 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_cathars" value = 40 }
				NOT = { has_global_flag = cathar_china_two }
			}
			set_global_flag = cathar_china_two
			set_global_flag = kcc_waxwane_cathars
			any_playable_ruler = { narrative_event = { id = kccspread.0004 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_cathars" value = 100 }
				NOT = { has_global_flag = cathar_china_three }
			}
			set_global_flag = cathar_china_three
			set_global_flag = kcc_waxwane_cathars
			any_playable_ruler = { narrative_event = { id = kccspread.0005 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_cathars" value = 180 }
				NOT = { has_global_flag = cathar_china_four }
				kcc_nontaoist_majority_trigger = yes
			}
			kcc_drop_other_religion_effect = yes
			set_global_flag = cathar_china_four
			set_global_flag = kcc_waxwane_cathars
			any_playable_ruler = { narrative_event = { id = kccspread.0007 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_cathars" value = 180 }
				NOT = { has_global_flag = cathar_china_four }
			}
			set_global_flag = cathar_china_four
			set_global_flag = kcc_waxwane_cathars
			any_playable_ruler = { narrative_event = { id = kccspread.0006 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_cathars" value = 100 } }
				has_global_flag = cathar_china_three
			}
			clr_global_flag = cathar_china_three
			set_global_flag = kcc_waxwane_cathars
			any_playable_ruler = { narrative_event = { id = kccspread.0008 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_cathars" value = 40 } }
				has_global_flag = cathar_china_two
			}
			clr_global_flag = cathar_china_two
			set_global_flag = kcc_waxwane_cathars
			any_playable_ruler = { narrative_event = { id = kccspread.0009 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_cathars" value = 20 } }
				has_global_flag = cathar_china_one
			}
			clr_global_flag = cathar_china_one
			set_global_flag = kcc_waxwane_cathars
			any_playable_ruler = { narrative_event = { id = kccspread.0010 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_cathars" value = 0 } }
				has_global_flag = cathars_in_china
			}
			clr_global_flag = cathars_in_china
			set_variable = { which = "global_chinese_cathars" value = 0 }
			set_global_flag = kcc_waxwane_cathars
			any_playable_ruler = { narrative_event = { id = kccspread.0011 days = 1 } }
		}
	}
	
	weight_multiplier = {
		days = 17
		modifier = {
			factor = 0
			NOR = { has_global_flag = cathars_in_china }
		}
		modifier = {
			factor = 0
			1513 = {
				OR = {
					has_province_modifier = kcc_china_persecuted_christians
					has_province_modifier = kcc_china_persecuted_latins
					has_province_modifier = kcc_china_persecuted_cathars
				}
			}
		}
		modifier = {
			factor = 2
			offmap_china = { offmap_has_like = likes_christians }
		}
		modifier = {
			factor = 5
			offmap_china = { offmap_ruler = { religion = cathar } }
			NOR = {
				has_global_flag = cathar_china_two
				has_global_flag = cathar_china_three
				has_global_flag = cathar_china_four
			}
		}
		modifier = {
			factor = 4
			offmap_china = { offmap_ruler = { religion = cathar } }
			NOR = {
				has_global_flag = cathar_china_three
				has_global_flag = cathar_china_four
			}
		}
		modifier = {
			factor = 1.5
			offmap_china = { offmap_ruler = { religion = cathar } }
			NOT = { has_global_flag = cathar_china_four }
		}
		modifier = {
			factor = 0
			offmap_china = { offmap_ruler = { religion = cathar } }
			has_global_flag = cathar_china_four
		}
		modifier = {
			factor = 1.33
			offmap_china = { offmap_ruler = { is_female = yes } }
		}
	}
	
	option = { #No change
	
		ai_chance = {
			factor = 30
		}
	}
	
	option = { #Wax
		if = {
			limit = {
				offmap_china = {
					OR = {
						offmap_ruler = { religion = cathar }
						offmap_china = { offmap_has_like = likes_christians }
					}
				}
			}
			change_variable = { which = "global_chinese_cathars" value = 2 }
		}
		else = {
			change_variable = { which = "global_chinese_cathars" value = 1 }
		}
		
		ai_chance = {
			factor = 60
			modifier = {
				factor = 1.1
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = cathar
						culture = mongol
					}
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = cathar
						OR = {
							culture = khitan
							culture = tangut
							culture = jurchen
							culture_group = chinese_group
						}
					}
				}
			}
			modifier = {
				factor = 1.2
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = cathar
						OR = {
							culture = khitan
							culture = tangut
							culture = jurchen
						}
					}
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = cathar
						culture_group = chinese_group
					}
				}
			}
			modifier = {
				factor = 1.3
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = cathar
						culture_group = chinese_group
					}
				}
			}
			modifier = {
				factor = 5
				OR = {
					offmap_china = { offmap_has_like = likes_christians }
					offmap_china = { offmap_ruler = { religion = cathar } }
				}
			}
			modifier = {
				factor = 1.5
				AND = {
					offmap_china = { offmap_ruler = { religion = cathar } }
					offmap_china = { offmap_ruler = { culture_group = chinese_group } }
				}
			}
			modifier = {
				factor = 1.5
				AND = {
					offmap_china = { offmap_ruler = { religion = cathar } }
					offmap_china = { has_status = china_golden_age }
				}
			}
			modifier = {
				factor = 0.2
				AND = {
					offmap_china = { offmap_ruler = { religion = cathar } }
					offmap_china = {
						OR = {
							has_status = china_unrest
							has_status = china_famine
							has_status = china_plague
						}
					}
				}
			}
			modifier = {
				factor = 0.01
				AND = {
					offmap_china = { offmap_ruler = { religion = cathar } }
					offmap_china = {
						OR = {
							has_status = china_civil_war
							has_status = china_mongol_invasion
							has_status = china_jurchen_invasion
						}
					}
				}
			}
			modifier = {
				factor = 3
				AND = {
					offmap_china = { offmap_ruler = { NOT = { religion = cathar } } }
					offmap_china = {
						OR = {
							has_status = china_unrest
							has_status = china_civil_war
						}
					}
				}
			}
			modifier = {
				factor = 1.5
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = cathar
					any_realm_province = {
						region = custom_eastern_access
					}
					NOR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
					OR = {
						has_character_modifier = peace_deal_with_china
						has_character_modifier = chinese_imperial_trade_contract
						has_character_modifier = chinese_favored_in_trade
						has_offmap_currency = { offmap = offmap_china value = 1000 }
					}
				}
			}
			modifier = {
				factor = 0.33
				OR = {
					offmap_china = { offmap_ruler = { religion_group = muslim } }
					AND = {
						offmap_china = { offmap_ruler = { religion_group = christian } }
						offmap_china = { offmap_ruler = { NOT = { religion = cathar } } }
					}
					offmap_china = {
						offmap_ruler = {
							religion_group = pagan_group
							has_religion_feature = religion_dogmatic
						}
					}
				}
			}
			modifier = {
				factor = 1.33
				offmap_china = { offmap_ruler = { is_female = yes } }
			}
		}
	}
	
	option = { #Wane
		if = {
			limit = {
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = cathar
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
			change_variable = { which = "global_chinese_cathars" value = -2 }
		}
		else = {
			change_variable = { which = "global_chinese_cathars" value = -1 }
		}
	
		ai_chance = {
			factor = 30
			modifier = {
				factor = 0
				offmap_china = { offmap_ruler = { religion = cathar } }
			}
			modifier = {
				factor = 0
				offmap_china = { offmap_has_like = likes_christians }
			}
			modifier = {
				factor = 0.1
				1513 = { has_province_modifier = kcc_recent_cathar_mission }
			}
			modifier = {
				factor = 2
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = cathar
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
		}
	}
}

# Wax & Wane of Fraticelli
character_event = {
	id = kccwaxwane.0003
	hide_window = yes
	
	is_triggered_only = yes
	
	has_dlc = "Jade Dragon"
	only_playable = yes
	
	trigger = {
		has_landed_title = e_china_west_governor
	}
	
	after = {
		if = {
			limit = {
				check_variable = { which = "global_chinese_fraticellis" value = 20 }
				NOT = { has_global_flag = fraticelli_china_one }
			}
			set_global_flag = fraticelli_china_one
			set_global_flag = kcc_waxwane_fraticellis
			any_playable_ruler = { narrative_event = { id = kccspread.0003 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_fraticellis" value = 40 }
				NOT = { has_global_flag = fraticelli_china_two }
			}
			set_global_flag = fraticelli_china_two
			set_global_flag = kcc_waxwane_fraticellis
			any_playable_ruler = { narrative_event = { id = kccspread.0004 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_fraticellis" value = 100 }
				NOT = { has_global_flag = fraticelli_china_three }
			}
			set_global_flag = fraticelli_china_three
			set_global_flag = kcc_waxwane_fraticellis
			any_playable_ruler = { narrative_event = { id = kccspread.0005 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_fraticellis" value = 180 }
				NOT = { has_global_flag = fraticelli_china_four }
				kcc_nontaoist_majority_trigger = yes
			}
			kcc_drop_other_religion_effect = yes
			set_global_flag = fraticelli_china_four
			set_global_flag = kcc_waxwane_fraticellis
			any_playable_ruler = { narrative_event = { id = kccspread.0007 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_fraticellis" value = 180 }
				NOT = { has_global_flag = fraticelli_china_four }
			}
			set_global_flag = fraticelli_china_four
			set_global_flag = kcc_waxwane_fraticellis
			any_playable_ruler = { narrative_event = { id = kccspread.0006 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_fraticellis" value = 100 } }
				has_global_flag = fraticelli_china_three
			}
			clr_global_flag = fraticelli_china_three
			set_global_flag = kcc_waxwane_fraticellis
			any_playable_ruler = { narrative_event = { id = kccspread.0008 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_fraticellis" value = 40 } }
				has_global_flag = fraticelli_china_two
			}
			clr_global_flag = fraticelli_china_two
			set_global_flag = kcc_waxwane_fraticellis
			any_playable_ruler = { narrative_event = { id = kccspread.0009 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_fraticellis" value = 20 } }
				has_global_flag = fraticelli_china_one
			}
			clr_global_flag = fraticelli_china_one
			set_global_flag = kcc_waxwane_fraticellis
			any_playable_ruler = { narrative_event = { id = kccspread.0010 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_fraticellis" value = 0 } }
				has_global_flag = fraticellis_in_china
			}
			clr_global_flag = fraticellis_in_china
			set_variable = { which = "global_chinese_fraticellis" value = 0 }
			set_global_flag = kcc_waxwane_fraticellis
			any_playable_ruler = { narrative_event = { id = kccspread.0011 days = 1 } }
		}
	}
	
	weight_multiplier = {
		days = 17
		modifier = {
			factor = 0
			NOR = { has_global_flag = fraticellis_in_china }
		}
		modifier = {
			factor = 0
			1513 = {
				OR = {
					has_province_modifier = kcc_china_persecuted_christians
					has_province_modifier = kcc_china_persecuted_fraticellis
					has_province_modifier = kcc_china_persecuted_latins
				}
			}
		}
		modifier = {
			factor = 2
			offmap_china = { offmap_has_like = likes_christians }
		}
		modifier = {
			factor = 5
			offmap_china = { offmap_ruler = { religion = fraticelli } }
			NOR = {
				has_global_flag = fraticelli_china_two
				has_global_flag = fraticelli_china_three
				has_global_flag = fraticelli_china_four
			}
		}
		modifier = {
			factor = 4
			offmap_china = { offmap_ruler = { religion = fraticelli } }
			NOR = {
				has_global_flag = fraticelli_china_three
				has_global_flag = fraticelli_china_four
			}
		}
		modifier = {
			factor = 1.5
			offmap_china = { offmap_ruler = { religion = fraticelli } }
			NOT = { has_global_flag = fraticelli_china_four }
		}
		modifier = {
			factor = 0
			offmap_china = { offmap_ruler = { religion = fraticelli } }
			has_global_flag = fraticelli_china_four
		}
	}
	
	option = { #No change
	
		ai_chance = {
			factor = 30
		}
	}
	
	option = { #Wax
		if = {
			limit = {
				offmap_china = {
					OR = {
						offmap_ruler = { religion = fraticelli }
						offmap_china = { offmap_has_like = likes_christians }
					}
				}
			}
			change_variable = { which = "global_chinese_fraticellis" value = 2 }
		}
		else = {
			change_variable = { which = "global_chinese_fraticellis" value = 1 }
		}
		
		ai_chance = {
			factor = 60
			modifier = {
				factor = 1.1
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = fraticelli
						culture = mongol
					}
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = fraticelli
						OR = {
							culture = khitan
							culture = tangut
							culture = jurchen
							culture_group = chinese_group
						}
					}
				}
			}
			modifier = {
				factor = 1.2
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = fraticelli
						OR = {
							culture = khitan
							culture = tangut
							culture = jurchen
						}
					}
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = fraticelli
						culture_group = chinese_group
					}
				}
			}
			modifier = {
				factor = 1.3
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = fraticelli
						culture_group = chinese_group
					}
				}
			}
			modifier = {
				factor = 5
				OR = {
					offmap_china = { offmap_has_like = likes_christians }
					offmap_china = { offmap_ruler = { religion = fraticelli } }
				}
			}
			modifier = {
				factor = 1.5
				AND = {
					offmap_china = { offmap_ruler = { religion = fraticelli } }
					offmap_china = { offmap_ruler = { culture_group = chinese_group } }
				}
			}
			modifier = {
				factor = 1.5
				AND = {
					offmap_china = { offmap_ruler = { religion = fraticelli } }
					offmap_china = { has_status = china_golden_age }
				}
			}
			modifier = {
				factor = 0.2
				AND = {
					offmap_china = { offmap_ruler = { religion = fraticelli } }
					offmap_china = {
						OR = {
							has_status = china_unrest
							has_status = china_famine
							has_status = china_plague
						}
					}
				}
			}
			modifier = {
				factor = 0.01
				AND = {
					offmap_china = { offmap_ruler = { religion = fraticelli } }
					offmap_china = {
						OR = {
							has_status = china_civil_war
							has_status = china_mongol_invasion
							has_status = china_jurchen_invasion
						}
					}
				}
			}
			modifier = {
				factor = 3
				AND = {
					offmap_china = { offmap_ruler = { NOT = { religion = fraticelli } } }
					offmap_china = {
						OR = {
							has_status = china_unrest
							has_status = china_civil_war
						}
					}
				}
			}
			modifier = {
				factor = 2
				OR = {
					AND = {
						offmap_china = { offmap_has_like = likes_indians }
						d_fraticelli = { holder_scope = { culture_group = indo_aryan_group } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_dravidians }
						d_fraticelli = { holder_scope = { culture_group = dravidian_group } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_tibetans }
						d_fraticelli = { holder_scope = { culture_group = tibetan_group } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_germanics }
						d_fraticelli = { holder_scope = {
							OR = {
								culture_group = north_germanic
								culture_group = central_germanic
								culture_group = west_germanic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_latino_iberians }
						d_fraticelli = { holder_scope = {
							OR = {
								culture_group = latin
								culture_group = iberian
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_byzantines }
						d_fraticelli = { holder_scope = { culture_group = byzantine } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_celts }
						d_fraticelli = { holder_scope = { culture_group = celtic } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_finno_ugrics }
						d_fraticelli = { holder_scope = {
							OR = {
								culture_group = finno_ugric
								culture_group = magyar
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_altaics }
						d_fraticelli = { holder_scope = { culture_group = altaic } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_balto_slavics }
						d_fraticelli = { holder_scope = {
							OR = {
								culture_group = baltic
								culture_group = east_slavic
								culture_group = west_slavic
								culture_group = south_slavic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_arabs }
						d_fraticelli = { holder_scope = { culture_group = arabic } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_iranians }
						d_fraticelli = { holder_scope = { culture_group = iranian } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_africans }
						d_fraticelli = { holder_scope = {
							OR = {
								culture_group = west_african
								culture_group = east_african
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_mesoamericans }
						d_fraticelli = { holder_scope = { culture_group = mesoamerican } }
					}
				}
			}
			modifier = {
				factor = 1.5
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = fraticelli
					any_realm_province = {
						region = custom_eastern_access
					}
					NOR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
					OR = {
						has_character_modifier = peace_deal_with_china
						has_character_modifier = chinese_imperial_trade_contract
						has_character_modifier = chinese_favored_in_trade
						has_offmap_currency = { offmap = offmap_china value = 1000 }
					}
				}
			}
			modifier = {
				factor = 0.33
				OR = {
					offmap_china = { offmap_ruler = { religion_group = muslim } }
					AND = {
						offmap_china = { offmap_ruler = { religion_group = christian } }
						offmap_china = { offmap_ruler = { NOT = { religion = fraticelli } } }
					}
					offmap_china = {
						offmap_ruler = {
							religion_group = pagan_group
							has_religion_feature = religion_dogmatic
						}
					}
				}
			}
			modifier = {
				factor = 1.33
				AND = {
					offmap_china = { offmap_ruler = { NOT = { religion = fraticelli } } }
					has_global_flag = fraticelli_pope_moved_to_china
				}
			}
			modifier = {
				factor = 4
				AND = {
					offmap_china = { offmap_ruler = { religion = fraticelli } }
					has_global_flag = fraticelli_pope_moved_to_china
				}
			}
		}
	}
	
	option = { #Wane
		if = {
			limit = {
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = fraticelli
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
			change_variable = { which = "global_chinese_fraticellis" value = -2 }
		}
		else = {
			change_variable = { which = "global_chinese_fraticellis" value = -1 }
		}
	
		ai_chance = {
			factor = 30
			modifier = {
				factor = 0
				offmap_china = { offmap_ruler = { religion = fraticelli } }
			}
			modifier = {
				factor = 0
				offmap_china = { offmap_has_like = likes_christians }
			}
			modifier = {
				factor = 0.1
				1513 = { has_province_modifier = kcc_recent_fraticelli_mission }
			}
			modifier = {
				factor = 2
				OR = {
					AND = {
						offmap_china = { offmap_has_dislike = likes_indians }
						d_fraticelli = { holder_scope = { culture_group = indo_aryan_group } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_dravidians }
						d_fraticelli = { holder_scope = { culture_group = dravidian_group } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_tibetans }
						d_fraticelli = { holder_scope = { culture_group = tibetan_group } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_germanics }
						d_fraticelli = { holder_scope = {
							OR = {
								culture_group = north_germanic
								culture_group = central_germanic
								culture_group = west_germanic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_latino_iberians }
						d_fraticelli = { holder_scope = {
							OR = {
								culture_group = latin
								culture_group = iberian
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_byzantines }
						d_fraticelli = { holder_scope = { culture_group = byzantine } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_celts }
						d_fraticelli = { holder_scope = { culture_group = celtic } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_finno_ugrics }
						d_fraticelli = { holder_scope = {
							OR = {
								culture_group = finno_ugric
								culture_group = magyar
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_altaics }
						d_fraticelli = { holder_scope = { culture_group = altaic } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_balto_slavics }
						d_fraticelli = { holder_scope = {
							OR = {
								culture_group = baltic
								culture_group = east_slavic
								culture_group = west_slavic
								culture_group = south_slavic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_arabs }
						d_fraticelli = { holder_scope = { culture_group = arabic } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_iranians }
						d_fraticelli = { holder_scope = { culture_group = iranian } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_africans }
						d_fraticelli = { holder_scope = {
							OR = {
								culture_group = west_african
								culture_group = east_african
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_mesoamericans }
						d_fraticelli = { holder_scope = { culture_group = mesoamerican } }
					}
				}
			}
			modifier = {
				factor = 2
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = fraticelli
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
		}
	}
}

# Wax & Wane of Waldensianism
character_event = {
	id = kccwaxwane.0004
	hide_window = yes
	
	is_triggered_only = yes
	
	has_dlc = "Jade Dragon"
	only_playable = yes
	
	trigger = {
		has_landed_title = e_china_west_governor
	}
	
	after = {
		if = {
			limit = {
				check_variable = { which = "global_chinese_waldensians" value = 20 }
				NOT = { has_global_flag = waldensian_china_one }
			}
			set_global_flag = waldensian_china_one
			set_global_flag = kcc_waxwane_waldensians
			any_playable_ruler = { narrative_event = { id = kccspread.0003 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_waldensians" value = 40 }
				NOT = { has_global_flag = waldensian_china_two }
			}
			set_global_flag = waldensian_china_two
			set_global_flag = kcc_waxwane_waldensians
			any_playable_ruler = { narrative_event = { id = kccspread.0004 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_waldensians" value = 100 }
				NOT = { has_global_flag = waldensian_china_three }
			}
			set_global_flag = waldensian_china_three
			set_global_flag = kcc_waxwane_waldensians
			any_playable_ruler = { narrative_event = { id = kccspread.0005 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_waldensians" value = 180 }
				NOT = { has_global_flag = waldensian_china_four }
				kcc_nontaoist_majority_trigger = yes
			}
			kcc_drop_other_religion_effect = yes
			set_global_flag = waldensian_china_four
			set_global_flag = kcc_waxwane_waldensians
			any_playable_ruler = { narrative_event = { id = kccspread.0007 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_waldensians" value = 180 }
				NOT = { has_global_flag = waldensian_china_four }
			}
			set_global_flag = waldensian_china_four
			set_global_flag = kcc_waxwane_waldensians
			any_playable_ruler = { narrative_event = { id = kccspread.0006 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_waldensians" value = 100 } }
				has_global_flag = waldensian_china_three
			}
			clr_global_flag = waldensian_china_three
			set_global_flag = kcc_waxwane_waldensians
			any_playable_ruler = { narrative_event = { id = kccspread.0008 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_waldensians" value = 40 } }
				has_global_flag = waldensian_china_two
			}
			clr_global_flag = waldensian_china_two
			set_global_flag = kcc_waxwane_waldensians
			any_playable_ruler = { narrative_event = { id = kccspread.0009 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_waldensians" value = 20 } }
				has_global_flag = waldensian_china_one
			}
			clr_global_flag = waldensian_china_one
			set_global_flag = kcc_waxwane_waldensians
			any_playable_ruler = { narrative_event = { id = kccspread.0010 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_waldensians" value = 0 } }
				has_global_flag = waldensians_in_china
			}
			clr_global_flag = waldensians_in_china
			set_variable = { which = "global_chinese_waldensians" value = 0 }
			set_global_flag = kcc_waxwane_waldensians
			any_playable_ruler = { narrative_event = { id = kccspread.0011 days = 1 } }
		}
	}
	
	weight_multiplier = {
		days = 17
		modifier = {
			factor = 0
			NOR = { has_global_flag = waldensians_in_china }
		}
		modifier = {
			factor = 0
			1513 = {
				OR = {
					has_province_modifier = kcc_china_persecuted_christians
					has_province_modifier = kcc_china_persecuted_waldensians
					has_province_modifier = kcc_china_persecuted_latins
				}
			}
		}
		modifier = {
			factor = 2
			offmap_china = { offmap_has_like = likes_christians }
		}
		modifier = {
			factor = 5
			offmap_china = { offmap_ruler = { religion = waldensian } }
			NOR = {
				has_global_flag = waldensian_china_two
				has_global_flag = waldensian_china_three
				has_global_flag = waldensian_china_four
			}
		}
		modifier = {
			factor = 4
			offmap_china = { offmap_ruler = { religion = waldensian } }
			NOR = {
				has_global_flag = waldensian_china_three
				has_global_flag = waldensian_china_four
			}
		}
		modifier = {
			factor = 1.5
			offmap_china = { offmap_ruler = { religion = waldensian } }
			NOT = { has_global_flag = waldensian_china_four }
		}
		modifier = {
			factor = 0
			offmap_china = { offmap_ruler = { religion = waldensian } }
			has_global_flag = waldensian_china_four
		}
	}
	
	option = { #No change
	
		ai_chance = {
			factor = 30
		}
	}
	
	option = { #Wax
		if = {
			limit = {
				offmap_china = {
					OR = {
						offmap_ruler = { religion = waldensian }
						offmap_china = { offmap_has_like = likes_christians }
					}
				}
			}
			change_variable = { which = "global_chinese_waldensians" value = 2 }
		}
		else = {
			change_variable = { which = "global_chinese_waldensians" value = 1 }
		}
		
		ai_chance = {
			factor = 60
			modifier = {
				factor = 1.1
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = waldensian
						culture = mongol
					}
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = waldensian
						OR = {
							culture = khitan
							culture = tangut
							culture = jurchen
							culture_group = chinese_group
						}
					}
				}
			}
			modifier = {
				factor = 1.2
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = waldensian
						OR = {
							culture = khitan
							culture = tangut
							culture = jurchen
						}
					}
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = waldensian
						culture_group = chinese_group
					}
				}
			}
			modifier = {
				factor = 1.3
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = waldensian
						culture_group = chinese_group
					}
				}
			}
			modifier = {
				factor = 5
				OR = {
					offmap_china = { offmap_has_like = likes_christians }
					offmap_china = { offmap_ruler = { religion = waldensian } }
				}
			}
			modifier = {
				factor = 1.5
				AND = {
					offmap_china = { offmap_ruler = { religion = waldensian } }
					offmap_china = { offmap_ruler = { culture_group = chinese_group } }
				}
			}
			modifier = {
				factor = 1.5
				AND = {
					offmap_china = { offmap_ruler = { religion = waldensian } }
					offmap_china = { has_status = china_golden_age }
				}
			}
			modifier = {
				factor = 0.2
				AND = {
					offmap_china = { offmap_ruler = { religion = waldensian } }
					offmap_china = {
						OR = {
							has_status = china_unrest
							has_status = china_famine
							has_status = china_plague
						}
					}
				}
			}
			modifier = {
				factor = 0.01
				AND = {
					offmap_china = { offmap_ruler = { religion = waldensian } }
					offmap_china = {
						OR = {
							has_status = china_civil_war
							has_status = china_mongol_invasion
							has_status = china_jurchen_invasion
						}
					}
				}
			}
			modifier = {
				factor = 3
				AND = {
					offmap_china = { offmap_ruler = { NOT = { religion = waldensian } } }
					offmap_china = {
						OR = {
							has_status = china_unrest
							has_status = china_civil_war
						}
					}
				}
			}
			modifier = {
				factor = 1.5
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = waldensian
					any_realm_province = {
						region = custom_eastern_access
					}
					NOR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
					OR = {
						has_character_modifier = peace_deal_with_china
						has_character_modifier = chinese_imperial_trade_contract
						has_character_modifier = chinese_favored_in_trade
						has_offmap_currency = { offmap = offmap_china value = 1000 }
					}
				}
			}
			modifier = {
				factor = 0.33
				OR = {
					offmap_china = { offmap_ruler = { religion_group = muslim } }
					AND = {
						offmap_china = { offmap_ruler = { religion_group = christian } }
						offmap_china = { offmap_ruler = { NOT = { religion = waldensian } } }
					}
					offmap_china = {
						offmap_ruler = {
							religion_group = pagan_group
							has_religion_feature = religion_dogmatic
						}
					}
				}
			}
		}
	}
	
	option = { #Wane
		if = {
			limit = {
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = waldensian
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
			change_variable = { which = "global_chinese_waldensians" value = -2 }
		}
		else = {
			change_variable = { which = "global_chinese_waldensians" value = -1 }
		}
	
		ai_chance = {
			factor = 30
			modifier = {
				factor = 0
				offmap_china = { offmap_ruler = { religion = waldensian } }
			}
			modifier = {
				factor = 0
				offmap_china = { offmap_has_like = likes_christians }
			}
			modifier = {
				factor = 0.1
				1513 = { has_province_modifier = kcc_recent_waldensian_mission }
			}
			modifier = {
				factor = 2
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = waldensian
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
		}
	}
}

# Wax & Wane of Lollardy
character_event = {
	id = kccwaxwane.0005
	hide_window = yes
	
	is_triggered_only = yes
	
	has_dlc = "Jade Dragon"
	only_playable = yes
	
	trigger = {
		has_landed_title = e_china_west_governor
	}
	
	after = {
		if = {
			limit = {
				check_variable = { which = "global_chinese_lollards" value = 20 }
				NOT = { has_global_flag = lollard_china_one }
			}
			set_global_flag = lollard_china_one
			set_global_flag = kcc_waxwane_lollards
			any_playable_ruler = { narrative_event = { id = kccspread.0003 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_lollards" value = 40 }
				NOT = { has_global_flag = lollard_china_two }
			}
			set_global_flag = lollard_china_two
			set_global_flag = kcc_waxwane_lollards
			any_playable_ruler = { narrative_event = { id = kccspread.0004 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_lollards" value = 100 }
				NOT = { has_global_flag = lollard_china_three }
			}
			set_global_flag = lollard_china_three
			set_global_flag = kcc_waxwane_lollards
			any_playable_ruler = { narrative_event = { id = kccspread.0005 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_lollards" value = 180 }
				NOT = { has_global_flag = lollard_china_four }
				kcc_nontaoist_majority_trigger = yes
			}
			kcc_drop_other_religion_effect = yes
			set_global_flag = waldensian_china_four
			set_global_flag = kcc_waxwane_lollards
			any_playable_ruler = { narrative_event = { id = kccspread.0007 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_lollards" value = 180 }
				NOT = { has_global_flag = lollard_china_four }
			}
			set_global_flag = lollard_china_four
			set_global_flag = kcc_waxwane_lollards
			any_playable_ruler = { narrative_event = { id = kccspread.0006 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_lollards" value = 100 } }
				has_global_flag = lollard_china_three
			}
			clr_global_flag = lollard_china_three
			set_global_flag = kcc_waxwane_lollards
			any_playable_ruler = { narrative_event = { id = kccspread.0008 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_lollards" value = 40 } }
				has_global_flag = lollard_china_two
			}
			clr_global_flag = lollard_china_two
			set_global_flag = kcc_waxwane_lollards
			any_playable_ruler = { narrative_event = { id = kccspread.0009 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_lollards" value = 20 } }
				has_global_flag = lollard_china_one
			}
			clr_global_flag = lollard_china_one
			set_global_flag = kcc_waxwane_lollards
			any_playable_ruler = { narrative_event = { id = kccspread.0010 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_lollards" value = 0 } }
				has_global_flag = lollards_in_china
			}
			clr_global_flag = lollards_in_china
			set_variable = { which = "global_chinese_lollards" value = 0 }
			set_global_flag = kcc_waxwane_lollards
			any_playable_ruler = { narrative_event = { id = kccspread.0011 days = 1 } }
		}
	}
	
	weight_multiplier = {
		days = 17
		modifier = {
			factor = 0
			NOR = { has_global_flag = lollards_in_china }
		}
		modifier = {
			factor = 0
			1513 = {
				OR = {
					has_province_modifier = kcc_china_persecuted_christians
					has_province_modifier = kcc_china_persecuted_lollards
					has_province_modifier = kcc_china_persecuted_latins
				}
			}
		}
		modifier = {
			factor = 2
			offmap_china = { offmap_has_like = likes_christians }
		}
		modifier = {
			factor = 5
			offmap_china = { offmap_ruler = { religion = lollard } }
			NOR = {
				has_global_flag = lollard_china_two
				has_global_flag = lollard_china_three
				has_global_flag = lollard_china_four
			}
		}
		modifier = {
			factor = 4
			offmap_china = { offmap_ruler = { religion = lollard } }
			NOR = {
				has_global_flag = lollard_china_three
				has_global_flag = lollard_china_four
			}
		}
		modifier = {
			factor = 1.5
			offmap_china = { offmap_ruler = { religion = lollard } }
			NOT = { has_global_flag = lollard_china_four }
		}
		modifier = {
			factor = 0
			offmap_china = { offmap_ruler = { religion = lollard } }
			has_global_flag = lollard_china_four
		}
	}
	
	option = { #No change
	
		ai_chance = {
			factor = 30
		}
	}
	
	option = { #Wax
		if = {
			limit = {
				offmap_china = {
					OR = {
						offmap_ruler = { religion = lollard }
						offmap_china = { offmap_has_like = likes_christians }
					}
				}
			}
			change_variable = { which = "global_chinese_lollards" value = 2 }
		}
		else = {
			change_variable = { which = "global_chinese_lollards" value = 1 }
		}
		
		ai_chance = {
			factor = 60
			modifier = {
				factor = 1.1
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = lollard
						culture = mongol
					}
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = lollard
						OR = {
							culture = khitan
							culture = tangut
							culture = jurchen
							culture_group = chinese_group
						}
					}
				}
			}
			modifier = {
				factor = 1.2
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = lollard
						OR = {
							culture = khitan
							culture = tangut
							culture = jurchen
						}
					}
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = lollard
						culture_group = chinese_group
					}
				}
			}
			modifier = {
				factor = 1.3
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = lollard
						culture_group = chinese_group
					}
				}
			}
			modifier = {
				factor = 5
				OR = {
					offmap_china = { offmap_has_like = likes_christians }
					offmap_china = { offmap_ruler = { religion = lollard } }
				}
			}
			modifier = {
				factor = 1.5
				AND = {
					offmap_china = { offmap_ruler = { religion = lollard } }
					offmap_china = { offmap_ruler = { culture_group = chinese_group } }
				}
			}
			modifier = {
				factor = 1.5
				AND = {
					offmap_china = { offmap_ruler = { religion = lollard } }
					offmap_china = { has_status = china_golden_age }
				}
			}
			modifier = {
				factor = 0.2
				AND = {
					offmap_china = { offmap_ruler = { religion = lollard } }
					offmap_china = {
						OR = {
							has_status = china_unrest
							has_status = china_famine
							has_status = china_plague
						}
					}
				}
			}
			modifier = {
				factor = 0.01
				AND = {
					offmap_china = { offmap_ruler = { religion = lollard } }
					offmap_china = {
						OR = {
							has_status = china_civil_war
							has_status = china_mongol_invasion
							has_status = china_jurchen_invasion
						}
					}
				}
			}
			modifier = {
				factor = 3
				AND = {
					offmap_china = { offmap_ruler = { NOT = { religion = lollard } } }
					offmap_china = {
						OR = {
							has_status = china_unrest
							has_status = china_civil_war
						}
					}
				}
			}
			modifier = {
				factor = 1.5
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = lollard
					any_realm_province = {
						region = custom_eastern_access
					}
					NOR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
					OR = {
						has_character_modifier = peace_deal_with_china
						has_character_modifier = chinese_imperial_trade_contract
						has_character_modifier = chinese_favored_in_trade
						has_offmap_currency = { offmap = offmap_china value = 1000 }
					}
				}
			}
			modifier = {
				factor = 0.33
				OR = {
					offmap_china = { offmap_ruler = { religion_group = muslim } }
					AND = {
						offmap_china = { offmap_ruler = { religion_group = christian } }
						offmap_china = { offmap_ruler = { NOT = { religion = lollard } } }
					}
					offmap_china = {
						offmap_ruler = {
							religion_group = pagan_group
							has_religion_feature = religion_dogmatic
						}
					}
				}
			}
		}
	}
	
	option = { #Wane
		if = {
			limit = {
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = lollard
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
			change_variable = { which = "global_chinese_lollards" value = -2 }
		}
		else = {
			change_variable = { which = "global_chinese_lollards" value = -1 }
		}
	
		ai_chance = {
			factor = 30
			modifier = {
				factor = 0
				offmap_china = { offmap_ruler = { religion = lollard } }
			}
			modifier = {
				factor = 0
				offmap_china = { offmap_has_like = likes_christians }
			}
			modifier = {
				factor = 0.1
				1513 = { has_province_modifier = kcc_recent_lollard_mission }
			}
			modifier = {
				factor = 2
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = lollard
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
		}
	}
}

# Wax & Wane of Orthodoxy
character_event = {
	id = kccwaxwane.0006
	hide_window = yes
	
	is_triggered_only = yes
	
	has_dlc = "Jade Dragon"
	only_playable = yes
	
	trigger = {
		has_landed_title = e_china_west_governor
	}
	
	after = {
		if = {
			limit = {
				check_variable = { which = "global_chinese_orthodoxs" value = 20 }
				NOT = { has_global_flag = orthodox_china_one }
			}
			set_global_flag = orthodox_china_one
			set_global_flag = kcc_waxwane_orthodoxy
			any_playable_ruler = { narrative_event = { id = kccspread.0003 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_orthodoxs" value = 40 }
				NOT = { has_global_flag = orthodox_china_two }
			}
			set_global_flag = orthodox_china_two
			set_global_flag = kcc_waxwane_orthodoxy
			any_playable_ruler = { narrative_event = { id = kccspread.0004 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_orthodoxs" value = 100 }
				NOT = { has_global_flag = orthodox_china_three }
			}
			set_global_flag = orthodox_china_three
			set_global_flag = kcc_waxwane_orthodoxy
			any_playable_ruler = { narrative_event = { id = kccspread.0005 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_orthodoxs" value = 180 }
				NOT = { has_global_flag = orthodox_china_four }
				kcc_nontaoist_majority_trigger = yes
			}
			kcc_drop_other_religion_effect = yes
			set_global_flag = orthodox_china_four
			set_global_flag = kcc_waxwane_orthodoxy
			any_playable_ruler = { narrative_event = { id = kccspread.0007 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_orthodoxs" value = 180 }
				NOT = { has_global_flag = orthodox_china_four }
			}
			set_global_flag = orthodox_china_four
			set_global_flag = kcc_waxwane_orthodoxy
			any_playable_ruler = { narrative_event = { id = kccspread.0006 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_orthodoxs" value = 100 } }
				has_global_flag = orthodox_china_three
			}
			clr_global_flag = orthodox_china_three
			set_global_flag = kcc_waxwane_orthodoxy
			any_playable_ruler = { narrative_event = { id = kccspread.0008 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_orthodoxs" value = 40 } }
				has_global_flag = orthodox_china_two
			}
			clr_global_flag = orthodox_china_two
			set_global_flag = kcc_waxwane_orthodoxy
			any_playable_ruler = { narrative_event = { id = kccspread.0009 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_orthodoxs" value = 20 } }
				has_global_flag = orthodox_china_one
			}
			clr_global_flag = orthodox_china_one
			set_global_flag = kcc_waxwane_orthodoxy
			any_playable_ruler = { narrative_event = { id = kccspread.0010 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_orthodoxs" value = 0 } }
				has_global_flag = orthodoxy_in_china
			}
			clr_global_flag = orthodoxy_in_china
			set_variable = { which = "global_chinese_orthodoxs" value = 0 }
			set_global_flag = kcc_waxwane_orthodoxy
			any_playable_ruler = { narrative_event = { id = kccspread.0011 days = 1 } }
		}
	}
	
	weight_multiplier = {
		days = 17
		modifier = {
			factor = 0
			NOR = { has_global_flag = orthodoxy_in_china }
		}
		modifier = {
			factor = 0
			1513 = {
				OR = {
					has_province_modifier = kcc_china_persecuted_christians
					has_province_modifier = kcc_china_persecuted_orthodoxy
					has_province_modifier = kcc_china_persecuted_byzantines
				}
			}
		}
		modifier = {
			factor = 2
			offmap_china = { offmap_has_like = likes_christians }
		}
		modifier = {
			factor = 5
			offmap_china = { offmap_ruler = { religion = orthodox } }
			NOR = {
				has_global_flag = orthodox_china_two
				has_global_flag = orthodox_china_three
				has_global_flag = orthodox_china_four
			}
		}
		modifier = {
			factor = 4
			offmap_china = { offmap_ruler = { religion = orthodox } }
			NOR = {
				has_global_flag = orthodox_china_three
				has_global_flag = orthodox_china_four
			}
		}
		modifier = {
			factor = 1.5
			offmap_china = { offmap_ruler = { religion = orthodox } }
			NOT = { has_global_flag = orthodox_china_four }
		}
		modifier = {
			factor = 0
			offmap_china = { offmap_ruler = { religion = orthodox } }
			has_global_flag = orthodox_china_four
		}
	}
	
	option = { #No change
	
		ai_chance = {
			factor = 30
		}
	}
	
	option = { #Wax
		if = {
			limit = {
				offmap_china = {
					OR = {
						offmap_ruler = { religion = orthodox }
						offmap_china = { offmap_has_like = likes_christians }
					}
				}
			}
			change_variable = { which = "global_chinese_orthodoxs" value = 2 }
		}
		else = {
			change_variable = { which = "global_chinese_orthodoxs" value = 1 }
		}
		
		ai_chance = {
			factor = 60
			modifier = {
				factor = 1.1
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = orthodox
						culture = mongol
					}
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = orthodox
						OR = {
							culture = khitan
							culture = tangut
							culture = jurchen
							culture_group = chinese_group
						}
					}
				}
			}
			modifier = {
				factor = 1.2
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = orthodox
						OR = {
							culture = khitan
							culture = tangut
							culture = jurchen
						}
					}
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = orthodox
						culture_group = chinese_group
					}
				}
			}
			modifier = {
				factor = 1.3
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = orthodox
						culture_group = chinese_group
					}
				}
			}
			modifier = {
				factor = 5
				OR = {
					offmap_china = { offmap_has_like = likes_christians }
					offmap_china = { offmap_ruler = { religion = orthodox } }
				}
			}
			modifier = {
				factor = 1.5
				AND = {
					offmap_china = { offmap_ruler = { religion = orthodox } }
					offmap_china = { offmap_ruler = { culture_group = chinese_group } }
				}
			}
			modifier = {
				factor = 1.5
				AND = {
					offmap_china = { offmap_ruler = { religion = orthodox } }
					offmap_china = { has_status = china_golden_age }
				}
			}
			modifier = {
				factor = 0.2
				AND = {
					offmap_china = { offmap_ruler = { religion = orthodox } }
					offmap_china = {
						OR = {
							has_status = china_unrest
							has_status = china_famine
							has_status = china_plague
						}
					}
				}
			}
			modifier = {
				factor = 0.01
				AND = {
					offmap_china = { offmap_ruler = { religion = orthodox } }
					offmap_china = {
						OR = {
							has_status = china_civil_war
							has_status = china_mongol_invasion
							has_status = china_jurchen_invasion
						}
					}
				}
			}
			modifier = {
				factor = 3
				AND = {
					offmap_china = { offmap_ruler = { NOT = { religion = orthodox } } }
					offmap_china = {
						OR = {
							has_status = china_unrest
							has_status = china_civil_war
						}
					}
				}
			}
			modifier = {
				factor = 2
				OR = {
					AND = {
						offmap_china = { offmap_has_like = likes_indians }
						k_orthodox = { holder_scope = { culture_group = indo_aryan_group } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_dravidians }
						k_orthodox = { holder_scope = { culture_group = dravidian_group } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_tibetans }
						k_orthodox = { holder_scope = { culture_group = tibetan_group } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_germanics }
						k_orthodox = { holder_scope = {
							OR = {
								culture_group = north_germanic
								culture_group = central_germanic
								culture_group = west_germanic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_latino_iberians }
						k_orthodox = { holder_scope = {
							OR = {
								culture_group = latin
								culture_group = iberian
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_byzantines }
						k_orthodox = { holder_scope = { culture_group = byzantine } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_celts }
						k_orthodox = { holder_scope = { culture_group = celtic } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_finno_ugrics }
						k_orthodox = { holder_scope = {
							OR = {
								culture_group = finno_ugric
								culture_group = magyar
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_altaics }
						k_orthodox = { holder_scope = { culture_group = altaic } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_balto_slavics }
						k_orthodox = { holder_scope = {
							OR = {
								culture_group = baltic
								culture_group = east_slavic
								culture_group = west_slavic
								culture_group = south_slavic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_arabs }
						k_orthodox = { holder_scope = { culture_group = arabic } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_iranians }
						k_orthodox = { holder_scope = { culture_group = iranian } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_africans }
						k_orthodox = { holder_scope = {
							OR = {
								culture_group = west_african
								culture_group = east_african
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_mesoamericans }
						k_orthodox = { holder_scope = { culture_group = mesoamerican } }
					}
				}
			}
			modifier = {
				factor = 1.5
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = orthodox
					any_realm_province = {
						region = custom_eastern_access
					}
					NOR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
					OR = {
						has_character_modifier = peace_deal_with_china
						has_character_modifier = chinese_imperial_trade_contract
						has_character_modifier = chinese_favored_in_trade
						has_offmap_currency = { offmap = offmap_china value = 1000 }
					}
				}
			}
			modifier = {
				factor = 0.33
				OR = {
					offmap_china = { offmap_ruler = { religion_group = muslim } }
					AND = {
						offmap_china = { offmap_ruler = { religion_group = christian } }
						offmap_china = { offmap_ruler = { NOT = { religion = orthodox } } }
					}
					offmap_china = {
						offmap_ruler = {
							religion_group = pagan_group
							has_religion_feature = religion_dogmatic
						}
					}
				}
			}
			modifier = {
				factor = 1.33
				AND = {
					offmap_china = { offmap_ruler = { NOT = { religion = orthodox } } }
					has_global_flag = orthodox_patriach_moved_to_china
				}
			}
			modifier = {
				factor = 4
				AND = {
					offmap_china = { offmap_ruler = { religion = orthodox } }
					has_global_flag = orthodox_patriach_moved_to_china
				}
			}
		}
	}
	
	option = { #Wane
		if = {
			limit = {
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = orthodox
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
			change_variable = { which = "global_chinese_orthodoxs" value = -2 }
		}
		else = {
			change_variable = { which = "global_chinese_orthodoxs" value = -1 }
		}
	
		ai_chance = {
			factor = 30
			modifier = {
				factor = 0
				offmap_china = { offmap_ruler = { religion = orthodox } }
			}
			modifier = {
				factor = 0
				offmap_china = { offmap_has_like = likes_christians }
			}
			modifier = {
				factor = 0.1
				1513 = { has_province_modifier = kcc_recent_orthodox_mission }
			}
			modifier = {
				factor = 2
				OR = {
					AND = {
						offmap_china = { offmap_has_dislike = likes_indians }
						k_orthodox = { holder_scope = { culture_group = indo_aryan_group } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_dravidians }
						k_orthodox = { holder_scope = { culture_group = dravidian_group } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_tibetans }
						k_orthodox = { holder_scope = { culture_group = tibetan_group } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_germanics }
						k_orthodox = { holder_scope = {
							OR = {
								culture_group = north_germanic
								culture_group = central_germanic
								culture_group = west_germanic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_latino_iberians }
						k_orthodox = { holder_scope = {
							OR = {
								culture_group = latin
								culture_group = iberian
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_byzantines }
						k_orthodox = { holder_scope = { culture_group = byzantine } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_celts }
						k_orthodox = { holder_scope = { culture_group = celtic } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_finno_ugrics }
						k_orthodox = { holder_scope = {
							OR = {
								culture_group = finno_ugric
								culture_group = magyar
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_altaics }
						k_orthodox = { holder_scope = { culture_group = altaic } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_balto_slavics }
						k_orthodox = { holder_scope = {
							OR = {
								culture_group = baltic
								culture_group = east_slavic
								culture_group = west_slavic
								culture_group = south_slavic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_arabs }
						k_orthodox = { holder_scope = { culture_group = arabic } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_iranians }
						k_orthodox = { holder_scope = { culture_group = iranian } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_africans }
						k_orthodox = { holder_scope = {
							OR = {
								culture_group = west_african
								culture_group = east_african
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_mesoamericans }
						k_orthodox = { holder_scope = { culture_group = mesoamerican } }
					}
				}
			}
			modifier = {
				factor = 2
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = orthodox
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
		}
	}
}

# Wax & Wane of Miaphysitism
character_event = {
	id = kccwaxwane.0007
	hide_window = yes
	
	is_triggered_only = yes
	
	has_dlc = "Jade Dragon"
	only_playable = yes
	
	trigger = {
		has_landed_title = e_china_west_governor
	}
	
	after = {
		if = {
			limit = {
				check_variable = { which = "global_chinese_miaphysites" value = 20 }
				NOT = { has_global_flag = miaphysite_china_one }
			}
			set_global_flag = miaphysite_china_one
			set_global_flag = kcc_waxwane_miaphysites
			any_playable_ruler = { narrative_event = { id = kccspread.0003 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_miaphysites" value = 40 }
				NOT = { has_global_flag = miaphysite_china_two }
			}
			set_global_flag = miaphysite_china_two
			set_global_flag = kcc_waxwane_miaphysites
			any_playable_ruler = { narrative_event = { id = kccspread.0004 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_miaphysites" value = 100 }
				NOT = { has_global_flag = miaphysite_china_three }
			}
			set_global_flag = miaphysite_china_three
			set_global_flag = kcc_waxwane_miaphysites
			any_playable_ruler = { narrative_event = { id = kccspread.0005 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_miaphysites" value = 180 }
				NOT = { has_global_flag = miaphysite_china_four }
				kcc_nontaoist_majority_trigger = yes
			}
			kcc_drop_other_religion_effect = yes
			set_global_flag = miaphysite_china_four
			set_global_flag = kcc_waxwane_miaphysites
			any_playable_ruler = { narrative_event = { id = kccspread.0007 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_miaphysites" value = 180 }
				NOT = { has_global_flag = miaphysite_china_four }
			}
			set_global_flag = miaphysite_china_four
			set_global_flag = kcc_waxwane_miaphysites
			any_playable_ruler = { narrative_event = { id = kccspread.0006 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_miaphysites" value = 100 } }
				has_global_flag = miaphysite_china_three
			}
			clr_global_flag = miaphysite_china_three
			set_global_flag = kcc_waxwane_miaphysites
			any_playable_ruler = { narrative_event = { id = kccspread.0008 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_miaphysites" value = 40 } }
				has_global_flag = miaphysite_china_two
			}
			clr_global_flag = miaphysite_china_two
			set_global_flag = kcc_waxwane_miaphysites
			any_playable_ruler = { narrative_event = { id = kccspread.0009 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_miaphysites" value = 20 } }
				has_global_flag = miaphysite_china_one
			}
			clr_global_flag = miaphysite_china_one
			set_global_flag = kcc_waxwane_miaphysites
			any_playable_ruler = { narrative_event = { id = kccspread.0010 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_miaphysites" value = 0 } }
				has_global_flag = miaphysites_in_china
			}
			clr_global_flag = miaphysites_in_china
			set_variable = { which = "global_chinese_miaphysites" value = 0 }
			set_global_flag = kcc_waxwane_miaphysites
			any_playable_ruler = { narrative_event = { id = kccspread.0011 days = 1 } }
		}
	}
	
	weight_multiplier = {
		days = 17
		modifier = {
			factor = 0
			NOR = { has_global_flag = miaphysites_in_china }
		}
		modifier = {
			factor = 0
			1513 = {
				OR = {
					has_province_modifier = kcc_china_persecuted_christians
					has_province_modifier = kcc_china_persecuted_miaphysites
					has_province_modifier = kcc_china_persecuted_nonchalcedonians
				}
			}
		}
		modifier = {
			factor = 2
			offmap_china = { offmap_has_like = likes_christians }
		}
		modifier = {
			factor = 5
			offmap_china = { offmap_ruler = { religion = miaphysite } }
			NOR = {
				has_global_flag = miaphysite_china_two
				has_global_flag = miaphysite_china_three
				has_global_flag = miaphysite_china_four
			}
		}
		modifier = {
			factor = 4
			offmap_china = { offmap_ruler = { religion = miaphysite } }
			NOR = {
				has_global_flag = miaphysite_china_three
				has_global_flag = miaphysite_china_four
			}
		}
		modifier = {
			factor = 1.5
			offmap_china = { offmap_ruler = { religion = miaphysite } }
			NOT = { has_global_flag = miaphysite_china_four }
		}
		modifier = {
			factor = 0
			offmap_china = { offmap_ruler = { religion = miaphysite } }
			has_global_flag = miaphysite_china_four
		}
	}
	
	option = { #No change
	
		ai_chance = {
			factor = 30
		}
	}
	
	option = { #Wax
		if = {
			limit = {
				offmap_china = {
					OR = {
						offmap_ruler = { religion = miaphysite }
						offmap_china = { offmap_has_like = likes_christians }
					}
				}
			}
			change_variable = { which = "global_chinese_miaphysites" value = 2 }
		}
		else = {
			change_variable = { which = "global_chinese_miaphysites" value = 1 }
		}
		
		ai_chance = {
			factor = 60
			modifier = {
				factor = 1.1
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = miaphysite
						culture = mongol
					}
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = miaphysite
						OR = {
							culture = khitan
							culture = tangut
							culture = jurchen
							culture_group = chinese_group
						}
					}
				}
			}
			modifier = {
				factor = 1.2
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = miaphysite
						OR = {
							culture = khitan
							culture = tangut
							culture = jurchen
						}
					}
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = miaphysite
						culture_group = chinese_group
					}
				}
			}
			modifier = {
				factor = 1.3
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = miaphysite
						culture_group = chinese_group
					}
				}
			}
			modifier = {
				factor = 5
				OR = {
					offmap_china = { offmap_has_like = likes_christians }
					offmap_china = { offmap_ruler = { religion = miaphysite } }
				}
			}
			modifier = {
				factor = 1.5
				AND = {
					offmap_china = { offmap_ruler = { religion = miaphysite } }
					offmap_china = { offmap_ruler = { culture_group = chinese_group } }
				}
			}
			modifier = {
				factor = 1.5
				AND = {
					offmap_china = { offmap_ruler = { religion = miaphysite } }
					offmap_china = { has_status = china_golden_age }
				}
			}
			modifier = {
				factor = 0.2
				AND = {
					offmap_china = { offmap_ruler = { religion = miaphysite } }
					offmap_china = {
						OR = {
							has_status = china_unrest
							has_status = china_famine
							has_status = china_plague
						}
					}
				}
			}
			modifier = {
				factor = 0.01
				AND = {
					offmap_china = { offmap_ruler = { religion = miaphysite } }
					offmap_china = {
						OR = {
							has_status = china_civil_war
							has_status = china_mongol_invasion
							has_status = china_jurchen_invasion
						}
					}
				}
			}
			modifier = {
				factor = 3
				AND = {
					offmap_china = { offmap_ruler = { NOT = { religion = miaphysite } } }
					offmap_china = {
						OR = {
							has_status = china_unrest
							has_status = china_civil_war
						}
					}
				}
			}
			modifier = {
				factor = 2
				OR = {
					AND = {
						offmap_china = { offmap_has_like = likes_indians }
						d_miaphysite = { holder_scope = { culture_group = indo_aryan_group } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_dravidians }
						d_miaphysite = { holder_scope = { culture_group = dravidian_group } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_tibetans }
						d_miaphysite = { holder_scope = { culture_group = tibetan_group } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_germanics }
						d_miaphysite = { holder_scope = {
							OR = {
								culture_group = north_germanic
								culture_group = central_germanic
								culture_group = west_germanic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_latino_iberians }
						d_miaphysite = { holder_scope = {
							OR = {
								culture_group = latin
								culture_group = iberian
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_byzantines }
						d_miaphysite = { holder_scope = { culture_group = byzantine } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_celts }
						d_miaphysite = { holder_scope = { culture_group = celtic } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_finno_ugrics }
						d_miaphysite = { holder_scope = {
							OR = {
								culture_group = finno_ugric
								culture_group = magyar
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_altaics }
						d_miaphysite = { holder_scope = { culture_group = altaic } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_balto_slavics }
						d_miaphysite = { holder_scope = {
							OR = {
								culture_group = baltic
								culture_group = east_slavic
								culture_group = west_slavic
								culture_group = south_slavic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_arabs }
						d_miaphysite = { holder_scope = { culture_group = arabic } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_iranians }
						d_miaphysite = { holder_scope = { culture_group = iranian } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_africans }
						d_miaphysite = { holder_scope = {
							OR = {
								culture_group = west_african
								culture_group = east_african
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_mesoamericans }
						d_miaphysite = { holder_scope = { culture_group = mesoamerican } }
					}
				}
			}
			modifier = {
				factor = 1.5
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = miaphysite
					any_realm_province = {
						region = custom_eastern_access
					}
					NOR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
					OR = {
						has_character_modifier = peace_deal_with_china
						has_character_modifier = chinese_imperial_trade_contract
						has_character_modifier = chinese_favored_in_trade
						has_offmap_currency = { offmap = offmap_china value = 1000 }
					}
				}
			}
			modifier = {
				factor = 0.33
				OR = {
					offmap_china = { offmap_ruler = { religion_group = muslim } }
					AND = {
						offmap_china = { offmap_ruler = { religion_group = christian } }
						offmap_china = { offmap_ruler = { NOT = { religion = miaphysite } } }
					}
					offmap_china = {
						offmap_ruler = {
							religion_group = pagan_group
							has_religion_feature = religion_dogmatic
						}
					}
				}
			}
			modifier = {
				factor = 1.33
				AND = {
					offmap_china = { offmap_ruler = { NOT = { religion = miaphysite } } }
					has_global_flag = coptic_pope_moved_to_china
				}
			}
			modifier = {
				factor = 4
				AND = {
					offmap_china = { offmap_ruler = { religion = miaphysite } }
					has_global_flag = coptic_pope_moved_to_china
				}
			}
		}
	}
	
	option = { #Wane
		if = {
			limit = {
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = miaphysite
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
			change_variable = { which = "global_chinese_miaphysites" value = -2 }
		}
		else = {
			change_variable = { which = "global_chinese_miaphysites" value = -1 }
		}
	
		ai_chance = {
			factor = 30
			modifier = {
				factor = 0
				offmap_china = { offmap_ruler = { religion = miaphysite } }
			}
			modifier = {
				factor = 0
				offmap_china = { offmap_has_like = likes_christians }
			}
			modifier = {
				factor = 0.1
				1513 = { has_province_modifier = kcc_recent_miaphysite_mission }
			}
			modifier = {
				factor = 2
				OR = {
					AND = {
						offmap_china = { offmap_has_dislike = likes_indians }
						d_miaphysite = { holder_scope = { culture_group = indo_aryan_group } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_dravidians }
						d_miaphysite = { holder_scope = { culture_group = dravidian_group } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_tibetans }
						d_miaphysite = { holder_scope = { culture_group = tibetan_group } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_germanics }
						d_miaphysite = { holder_scope = {
							OR = {
								culture_group = north_germanic
								culture_group = central_germanic
								culture_group = west_germanic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_latino_iberians }
						d_miaphysite = { holder_scope = {
							OR = {
								culture_group = latin
								culture_group = iberian
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_byzantines }
						d_miaphysite = { holder_scope = { culture_group = byzantine } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_celts }
						d_miaphysite = { holder_scope = { culture_group = celtic } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_finno_ugrics }
						d_miaphysite = { holder_scope = {
							OR = {
								culture_group = finno_ugric
								culture_group = magyar
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_altaics }
						d_miaphysite = { holder_scope = { culture_group = altaic } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_balto_slavics }
						d_miaphysite = { holder_scope = {
							OR = {
								culture_group = baltic
								culture_group = east_slavic
								culture_group = west_slavic
								culture_group = south_slavic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_arabs }
						d_miaphysite = { holder_scope = { culture_group = arabic } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_iranians }
						d_miaphysite = { holder_scope = { culture_group = iranian } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_africans }
						d_miaphysite = { holder_scope = {
							OR = {
								culture_group = west_african
								culture_group = east_african
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_mesoamericans }
						d_miaphysite = { holder_scope = { culture_group = mesoamerican } }
					}
				}
			}
			modifier = {
				factor = 2
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = miaphysite
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
		}
	}
}

# Wax & Wane of Monophysitism
character_event = {
	id = kccwaxwane.0008
	hide_window = yes
	
	is_triggered_only = yes
	
	has_dlc = "Jade Dragon"
	only_playable = yes
	
	trigger = {
		has_landed_title = e_china_west_governor
	}
	
	after = {
		if = {
			limit = {
				check_variable = { which = "global_chinese_monophysites" value = 20 }
				NOT = { has_global_flag = monophysite_china_one }
			}
			set_global_flag = monophysite_china_one
			set_global_flag = kcc_waxwane_monophysites
			any_playable_ruler = { narrative_event = { id = kccspread.0003 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_monophysites" value = 40 }
				NOT = { has_global_flag = monophysite_china_two }
			}
			set_global_flag = monophysite_china_two
			set_global_flag = kcc_waxwane_monophysites
			any_playable_ruler = { narrative_event = { id = kccspread.0004 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_monophysites" value = 100 }
				NOT = { has_global_flag = monophysite_china_three }
			}
			set_global_flag = monophysite_china_three
			set_global_flag = kcc_waxwane_monophysites
			any_playable_ruler = { narrative_event = { id = kccspread.0005 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_monophysites" value = 180 }
				NOT = { has_global_flag = monophysite_china_four }
				kcc_nontaoist_majority_trigger = yes
			}
			kcc_drop_other_religion_effect = yes
			set_global_flag = monophysite_china_four
			set_global_flag = kcc_waxwane_monophysites
			any_playable_ruler = { narrative_event = { id = kccspread.0007 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_monophysites" value = 180 }
				NOT = { has_global_flag = monophysite_china_four }
			}
			set_global_flag = monophysite_china_four
			set_global_flag = kcc_waxwane_monophysites
			any_playable_ruler = { narrative_event = { id = kccspread.0006 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_monophysites" value = 100 } }
				has_global_flag = monophysite_china_three
			}
			clr_global_flag = monophysite_china_three
			set_global_flag = kcc_waxwane_monophysites
			any_playable_ruler = { narrative_event = { id = kccspread.0008 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_monophysites" value = 40 } }
				has_global_flag = monophysite_china_two
			}
			clr_global_flag = monophysite_china_two
			set_global_flag = kcc_waxwane_monophysites
			any_playable_ruler = { narrative_event = { id = kccspread.0009 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_monophysites" value = 20 } }
				has_global_flag = monophysite_china_one
			}
			clr_global_flag = monophysite_china_one
			set_global_flag = kcc_waxwane_monophysites
			any_playable_ruler = { narrative_event = { id = kccspread.0010 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_monophysites" value = 0 } }
				has_global_flag = monophysites_in_china
			}
			clr_global_flag = monophysites_in_china
			set_variable = { which = "global_chinese_monophysites" value = 0 }
			set_global_flag = kcc_waxwane_monophysites
			any_playable_ruler = { narrative_event = { id = kccspread.0011 days = 1 } }
		}
	}
	
	weight_multiplier = {
		days = 17
		modifier = {
			factor = 0
			NOR = { has_global_flag = monophysites_in_china }
		}
		modifier = {
			factor = 0
			1513 = {
				OR = {
					has_province_modifier = kcc_china_persecuted_christians
					has_province_modifier = kcc_china_persecuted_monophysites
					has_province_modifier = kcc_china_persecuted_nonchalcedonians
				}
			}
		}
		modifier = {
			factor = 2
			offmap_china = { offmap_has_like = likes_christians }
		}
		modifier = {
			factor = 5
			offmap_china = { offmap_ruler = { religion = monophysite } }
			NOR = {
				has_global_flag = monophysite_china_two
				has_global_flag = monophysite_china_three
				has_global_flag = monophysite_china_four
			}
		}
		modifier = {
			factor = 4
			offmap_china = { offmap_ruler = { religion = monophysite } }
			NOR = {
				has_global_flag = monophysite_china_three
				has_global_flag = monophysite_china_four
			}
		}
		modifier = {
			factor = 1.5
			offmap_china = { offmap_ruler = { religion = monophysite } }
			NOT = { has_global_flag = monophysite_china_four }
		}
		modifier = {
			factor = 0
			offmap_china = { offmap_ruler = { religion = monophysite } }
			has_global_flag = monophysite_china_four
		}
	}
	
	option = { #No change
	
		ai_chance = {
			factor = 30
		}
	}
	
	option = { #Wax
		if = {
			limit = {
				offmap_china = {
					OR = {
						offmap_ruler = { religion = monophysite }
						offmap_china = { offmap_has_like = likes_christians }
					}
				}
			}
			change_variable = { which = "global_chinese_monophysites" value = 2 }
		}
		else = {
			change_variable = { which = "global_chinese_monophysites" value = 1 }
		}
		
		ai_chance = {
			factor = 60
			modifier = {
				factor = 1.1
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = monophysite
						culture = mongol
					}
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = monophysite
						OR = {
							culture = khitan
							culture = tangut
							culture = jurchen
							culture_group = chinese_group
						}
					}
				}
			}
			modifier = {
				factor = 1.2
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = monophysite
						OR = {
							culture = khitan
							culture = tangut
							culture = jurchen
						}
					}
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = monophysite
						culture_group = chinese_group
					}
				}
			}
			modifier = {
				factor = 1.3
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = monophysite
						culture_group = chinese_group
					}
				}
			}
			modifier = {
				factor = 5
				OR = {
					offmap_china = { offmap_has_like = likes_christians }
					offmap_china = { offmap_ruler = { religion = monophysite } }
				}
			}
			modifier = {
				factor = 1.5
				AND = {
					offmap_china = { offmap_ruler = { religion = monophysite } }
					offmap_china = { offmap_ruler = { culture_group = chinese_group } }
				}
			}
			modifier = {
				factor = 1.5
				AND = {
					offmap_china = { offmap_ruler = { religion = monophysite } }
					offmap_china = { has_status = china_golden_age }
				}
			}
			modifier = {
				factor = 0.2
				AND = {
					offmap_china = { offmap_ruler = { religion = monophysite } }
					offmap_china = {
						OR = {
							has_status = china_unrest
							has_status = china_famine
							has_status = china_plague
						}
					}
				}
			}
			modifier = {
				factor = 0.01
				AND = {
					offmap_china = { offmap_ruler = { religion = monophysite } }
					offmap_china = {
						OR = {
							has_status = china_civil_war
							has_status = china_mongol_invasion
							has_status = china_jurchen_invasion
						}
					}
				}
			}
			modifier = {
				factor = 3
				AND = {
					offmap_china = { offmap_ruler = { NOT = { religion = monophysite } } }
					offmap_china = {
						OR = {
							has_status = china_unrest
							has_status = china_civil_war
						}
					}
				}
			}
			modifier = {
				factor = 2
				OR = {
					AND = {
						offmap_china = { offmap_has_like = likes_indians }
						d_monophysite = { holder_scope = { culture_group = indo_aryan_group } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_dravidians }
						d_monophysite = { holder_scope = { culture_group = dravidian_group } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_tibetans }
						d_monophysite = { holder_scope = { culture_group = tibetan_group } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_germanics }
						d_monophysite = { holder_scope = {
							OR = {
								culture_group = north_germanic
								culture_group = central_germanic
								culture_group = west_germanic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_latino_iberians }
						d_monophysite = { holder_scope = {
							OR = {
								culture_group = latin
								culture_group = iberian
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_byzantines }
						d_monophysite = { holder_scope = { culture_group = byzantine } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_celts }
						d_monophysite = { holder_scope = { culture_group = celtic } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_finno_ugrics }
						d_monophysite = { holder_scope = {
							OR = {
								culture_group = finno_ugric
								culture_group = magyar
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_altaics }
						d_monophysite = { holder_scope = { culture_group = altaic } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_balto_slavics }
						d_monophysite = { holder_scope = {
							OR = {
								culture_group = baltic
								culture_group = east_slavic
								culture_group = west_slavic
								culture_group = south_slavic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_arabs }
						d_monophysite = { holder_scope = { culture_group = arabic } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_iranians }
						d_monophysite = { holder_scope = { culture_group = iranian } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_africans }
						d_monophysite = { holder_scope = {
							OR = {
								culture_group = west_african
								culture_group = east_african
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_mesoamericans }
						d_monophysite = { holder_scope = { culture_group = mesoamerican } }
					}
				}
			}
			modifier = {
				factor = 1.5
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = monophysite
					any_realm_province = {
						region = custom_eastern_access
					}
					NOR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
					OR = {
						has_character_modifier = peace_deal_with_china
						has_character_modifier = chinese_imperial_trade_contract
						has_character_modifier = chinese_favored_in_trade
						has_offmap_currency = { offmap = offmap_china value = 1000 }
					}
				}
			}
			modifier = {
				factor = 0.33
				OR = {
					offmap_china = { offmap_ruler = { religion_group = muslim } }
					AND = {
						offmap_china = { offmap_ruler = { religion_group = christian } }
						offmap_china = { offmap_ruler = { NOT = { religion = monophysite } } }
					}
					offmap_china = {
						offmap_ruler = {
							religion_group = pagan_group
							has_religion_feature = religion_dogmatic
						}
					}
				}
			}
			modifier = {
				factor = 1.33
				AND = {
					offmap_china = { offmap_ruler = { NOT = { religion = monophysite } } }
					has_global_flag = monophysite_patriach_moved_to_china
				}
			}
			modifier = {
				factor = 4
				AND = {
					offmap_china = { offmap_ruler = { religion = monophysite } }
					has_global_flag = monophysite_patriach_moved_to_china
				}
			}
		}
	}
	
	option = { #Wane
		if = {
			limit = {
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = monophysite
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
			change_variable = { which = "global_chinese_monophysites" value = -2 }
		}
		else = {
			change_variable = { which = "global_chinese_monophysites" value = -1 }
		}
	
		ai_chance = {
			factor = 30
			modifier = {
				factor = 0
				offmap_china = { offmap_ruler = { religion = monophysite } }
			}
			modifier = {
				factor = 0
				offmap_china = { offmap_has_like = likes_christians }
			}
			modifier = {
				factor = 0.1
				1513 = { has_province_modifier = kcc_recent_monophysite_mission }
			}
			modifier = {
				factor = 2
				OR = {
					AND = {
						offmap_china = { offmap_has_dislike = likes_indians }
						d_monophysite = { holder_scope = { culture_group = indo_aryan_group } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_dravidians }
						d_monophysite = { holder_scope = { culture_group = dravidian_group } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_tibetans }
						d_monophysite = { holder_scope = { culture_group = tibetan_group } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_germanics }
						d_monophysite = { holder_scope = {
							OR = {
								culture_group = north_germanic
								culture_group = central_germanic
								culture_group = west_germanic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_latino_iberians }
						d_monophysite = { holder_scope = {
							OR = {
								culture_group = latin
								culture_group = iberian
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_byzantines }
						d_monophysite = { holder_scope = { culture_group = byzantine } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_celts }
						d_monophysite = { holder_scope = { culture_group = celtic } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_finno_ugrics }
						d_monophysite = { holder_scope = {
							OR = {
								culture_group = finno_ugric
								culture_group = magyar
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_altaics }
						d_monophysite = { holder_scope = { culture_group = altaic } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_balto_slavics }
						d_monophysite = { holder_scope = {
							OR = {
								culture_group = baltic
								culture_group = east_slavic
								culture_group = west_slavic
								culture_group = south_slavic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_arabs }
						d_monophysite = { holder_scope = { culture_group = arabic } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_iranians }
						d_monophysite = { holder_scope = { culture_group = iranian } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_africans }
						d_monophysite = { holder_scope = {
							OR = {
								culture_group = west_african
								culture_group = east_african
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_mesoamericans }
						d_monophysite = { holder_scope = { culture_group = mesoamerican } }
					}
				}
			}
			modifier = {
				factor = 2
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = monophysite
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
		}
	}
}

# Wax & Wane of Bogomilism
character_event = {
	id = kccwaxwane.0009
	hide_window = yes
	
	is_triggered_only = yes
	
	has_dlc = "Jade Dragon"
	only_playable = yes
	
	trigger = {
		has_landed_title = e_china_west_governor
	}
	
	after = {
		if = {
			limit = {
				check_variable = { which = "global_chinese_bogomilists" value = 20 }
				NOT = { has_global_flag = bogomilist_china_one }
			}
			set_global_flag = bogomilist_china_one
			set_global_flag = kcc_waxwane_bogomilists
			any_playable_ruler = { narrative_event = { id = kccspread.0003 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_bogomilists" value = 40 }
				NOT = { has_global_flag = bogomilist_china_two }
			}
			set_global_flag = bogomilist_china_two
			set_global_flag = kcc_waxwane_bogomilists
			any_playable_ruler = { narrative_event = { id = kccspread.0004 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_bogomilists" value = 100 }
				NOT = { has_global_flag = bogomilist_china_three }
			}
			set_global_flag = bogomilist_china_three
			set_global_flag = kcc_waxwane_bogomilists
			any_playable_ruler = { narrative_event = { id = kccspread.0005 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_bogomilists" value = 180 }
				NOT = { has_global_flag = bogomilist_china_four }
				kcc_nontaoist_majority_trigger = yes
			}
			kcc_drop_other_religion_effect = yes
			set_global_flag = bogomilist_china_four
			set_global_flag = kcc_waxwane_bogomilists
			any_playable_ruler = { narrative_event = { id = kccspread.0007 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_bogomilists" value = 180 }
				NOT = { has_global_flag = bogomilist_china_four }
			}
			set_global_flag = bogomilist_china_four
			set_global_flag = kcc_waxwane_bogomilists
			any_playable_ruler = { narrative_event = { id = kccspread.0006 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_bogomilists" value = 100 } }
				has_global_flag = bogomilist_china_three
			}
			clr_global_flag = bogomilist_china_three
			set_global_flag = kcc_waxwane_bogomilists
			any_playable_ruler = { narrative_event = { id = kccspread.0008 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_bogomilists" value = 40 } }
				has_global_flag = bogomilist_china_two
			}
			clr_global_flag = bogomilist_china_two
			set_global_flag = kcc_waxwane_bogomilists
			any_playable_ruler = { narrative_event = { id = kccspread.0009 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_bogomilists" value = 20 } }
				has_global_flag = bogomilist_china_one
			}
			clr_global_flag = bogomilist_china_one
			set_global_flag = kcc_waxwane_bogomilists
			any_playable_ruler = { narrative_event = { id = kccspread.0010 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_bogomilists" value = 0 } }
				has_global_flag = bogomilists_in_china
			}
			clr_global_flag = bogomilists_in_china
			set_variable = { which = "global_chinese_bogomilists" value = 0 }
			set_global_flag = kcc_waxwane_bogomilists
			any_playable_ruler = { narrative_event = { id = kccspread.0011 days = 1 } }
		}
	}
	
	weight_multiplier = {
		days = 17
		modifier = {
			factor = 0
			NOR = { has_global_flag = bogomilists_in_china }
		}
		modifier = {
			factor = 0
			1513 = {
				OR = {
					has_province_modifier = kcc_china_persecuted_christians
					has_province_modifier = kcc_china_persecuted_bogomilists
					has_province_modifier = kcc_china_persecuted_byzantines
				}
			}
		}
		modifier = {
			factor = 2
			offmap_china = { offmap_has_like = likes_christians }
		}
		modifier = {
			factor = 5
			offmap_china = { offmap_ruler = { religion = bogomilist } }
			NOR = {
				has_global_flag = bogomilist_china_two
				has_global_flag = bogomilist_china_three
				has_global_flag = bogomilist_china_four
			}
		}
		modifier = {
			factor = 4
			offmap_china = { offmap_ruler = { religion = bogomilist } }
			NOR = {
				has_global_flag = bogomilist_china_three
				has_global_flag = bogomilist_china_four
			}
		}
		modifier = {
			factor = 1.5
			offmap_china = { offmap_ruler = { religion = bogomilist } }
			NOT = { has_global_flag = bogomilist_china_four }
		}
		modifier = {
			factor = 0
			offmap_china = { offmap_ruler = { religion = bogomilist } }
			has_global_flag = bogomilist_china_four
		}
		modifier = {
			factor = 1.33
			offmap_china = { offmap_ruler = { is_female = yes } }
		}
	}
	
	option = { #No change
	
		ai_chance = {
			factor = 30
		}
	}
	
	option = { #Wax
		if = {
			limit = {
				offmap_china = {
					OR = {
						offmap_ruler = { religion = bogomilist }
						offmap_china = { offmap_has_like = likes_christians }
					}
				}
			}
			change_variable = { which = "global_chinese_bogomilists" value = 2 }
		}
		else = {
			change_variable = { which = "global_chinese_bogomilists" value = 1 }
		}
		
		ai_chance = {
			factor = 60
			modifier = {
				factor = 1.1
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = bogomilist
						culture = mongol
					}
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = bogomilist
						OR = {
							culture = khitan
							culture = tangut
							culture = jurchen
							culture_group = chinese_group
						}
					}
				}
			}
			modifier = {
				factor = 1.2
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = bogomilist
						OR = {
							culture = khitan
							culture = tangut
							culture = jurchen
						}
					}
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = bogomilist
						culture_group = chinese_group
					}
				}
			}
			modifier = {
				factor = 1.3
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = bogomilist
						culture_group = chinese_group
					}
				}
			}
			modifier = {
				factor = 5
				OR = {
					offmap_china = { offmap_has_like = likes_christians }
					offmap_china = { offmap_ruler = { religion = bogomilist } }
				}
			}
			modifier = {
				factor = 1.5
				AND = {
					offmap_china = { offmap_ruler = { religion = bogomilist } }
					offmap_china = { offmap_ruler = { culture_group = chinese_group } }
				}
			}
			modifier = {
				factor = 1.5
				AND = {
					offmap_china = { offmap_ruler = { religion = bogomilist } }
					offmap_china = { has_status = china_golden_age }
				}
			}
			modifier = {
				factor = 0.2
				AND = {
					offmap_china = { offmap_ruler = { religion = bogomilist } }
					offmap_china = {
						OR = {
							has_status = china_unrest
							has_status = china_famine
							has_status = china_plague
						}
					}
				}
			}
			modifier = {
				factor = 0.01
				AND = {
					offmap_china = { offmap_ruler = { religion = bogomilist } }
					offmap_china = {
						OR = {
							has_status = china_civil_war
							has_status = china_mongol_invasion
							has_status = china_jurchen_invasion
						}
					}
				}
			}
			modifier = {
				factor = 3
				AND = {
					offmap_china = { offmap_ruler = { NOT = { religion = bogomilist } } }
					offmap_china = {
						OR = {
							has_status = china_unrest
							has_status = china_civil_war
						}
					}
				}
			}
			modifier = {
				factor = 1.5
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = bogomilist
					any_realm_province = {
						region = custom_eastern_access
					}
					NOR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
					OR = {
						has_character_modifier = peace_deal_with_china
						has_character_modifier = chinese_imperial_trade_contract
						has_character_modifier = chinese_favored_in_trade
						has_offmap_currency = { offmap = offmap_china value = 1000 }
					}
				}
			}
			modifier = {
				factor = 0.33
				OR = {
					offmap_china = { offmap_ruler = { religion_group = muslim } }
					AND = {
						offmap_china = { offmap_ruler = { religion_group = christian } }
						offmap_china = { offmap_ruler = { NOT = { religion = bogomilist } } }
					}
					offmap_china = {
						offmap_ruler = {
							religion_group = pagan_group
							has_religion_feature = religion_dogmatic
						}
					}
				}
			}
			modifier = {
				factor = 1.33
				offmap_china = { offmap_ruler = { is_female = yes } }
			}
		}
	}
	
	option = { #Wane
		if = {
			limit = {
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = bogomilist
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
			change_variable = { which = "global_chinese_bogomilists" value = -2 }
		}
		else = {
			change_variable = { which = "global_chinese_bogomilists" value = -1 }
		}
	
		ai_chance = {
			factor = 30
			modifier = {
				factor = 0
				offmap_china = { offmap_ruler = { religion = bogomilist } }
			}
			modifier = {
				factor = 0
				offmap_china = { offmap_has_like = likes_christians }
			}
			modifier = {
				factor = 0.1
				1513 = { has_province_modifier = kcc_recent_bogomilist_mission }
			}
			modifier = {
				factor = 2
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = bogomilist
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
		}
	}
}

# Wax & Wane of Monothelite
character_event = {
	id = kccwaxwane.0010
	hide_window = yes
	
	is_triggered_only = yes
	
	has_dlc = "Jade Dragon"
	only_playable = yes
	
	trigger = {
		has_landed_title = e_china_west_governor
	}
	
	after = {
		if = {
			limit = {
				check_variable = { which = "global_chinese_monothelites" value = 20 }
				NOT = { has_global_flag = monothelite_china_one }
			}
			set_global_flag = monothelite_china_one
			set_global_flag = kcc_waxwane_monothelites
			any_playable_ruler = { narrative_event = { id = kccspread.0003 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_monothelites" value = 40 }
				NOT = { has_global_flag = monothelite_china_two }
			}
			set_global_flag = monothelite_china_two
			set_global_flag = kcc_waxwane_monothelites
			any_playable_ruler = { narrative_event = { id = kccspread.0004 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_monothelites" value = 100 }
				NOT = { has_global_flag = monothelite_china_three }
			}
			set_global_flag = monothelite_china_three
			set_global_flag = kcc_waxwane_monothelites
			any_playable_ruler = { narrative_event = { id = kccspread.0005 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_monothelites" value = 180 }
				NOT = { has_global_flag = monothelite_china_four }
				kcc_nontaoist_majority_trigger = yes
			}
			kcc_drop_other_religion_effect = yes
			set_global_flag = monothelite_china_four
			set_global_flag = kcc_waxwane_monothelites
			any_playable_ruler = { narrative_event = { id = kccspread.0007 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_monothelites" value = 180 }
				NOT = { has_global_flag = monothelite_china_four }
			}
			set_global_flag = monothelite_china_four
			set_global_flag = kcc_waxwane_monothelites
			any_playable_ruler = { narrative_event = { id = kccspread.0006 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_monothelites" value = 100 } }
				has_global_flag = monothelite_china_three
			}
			clr_global_flag = monothelite_china_three
			set_global_flag = kcc_waxwane_monothelites
			any_playable_ruler = { narrative_event = { id = kccspread.0008 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_monothelites" value = 40 } }
				has_global_flag = monothelite_china_two
			}
			clr_global_flag = monothelite_china_two
			set_global_flag = kcc_waxwane_monothelites
			any_playable_ruler = { narrative_event = { id = kccspread.0009 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_monothelites" value = 20 } }
				has_global_flag = monothelite_china_one
			}
			clr_global_flag = monothelite_china_one
			set_global_flag = kcc_waxwane_monothelites
			any_playable_ruler = { narrative_event = { id = kccspread.0010 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_monothelites" value = 0 } }
				has_global_flag = monothelites_in_china
			}
			clr_global_flag = monothelites_in_china
			set_variable = { which = "global_chinese_monothelites" value = 0 }
			set_global_flag = kcc_waxwane_monothelites
			any_playable_ruler = { narrative_event = { id = kccspread.0011 days = 1 } }
		}
	}
	
	weight_multiplier = {
		days = 17
		modifier = {
			factor = 0
			NOR = { has_global_flag = monothelites_in_china }
		}
		modifier = {
			factor = 0
			1513 = {
				OR = {
					has_province_modifier = kcc_china_persecuted_christians
					has_province_modifier = kcc_china_persecuted_monothelites
					has_province_modifier = kcc_china_persecuted_byzantines
				}
			}
		}
		modifier = {
			factor = 2
			offmap_china = { offmap_has_like = likes_christians }
		}
		modifier = {
			factor = 5
			offmap_china = { offmap_ruler = { religion = monothelite } }
			NOR = {
				has_global_flag = monothelite_china_two
				has_global_flag = monothelite_china_three
				has_global_flag = monothelite_china_four
			}
		}
		modifier = {
			factor = 4
			offmap_china = { offmap_ruler = { religion = monothelite } }
			NOR = {
				has_global_flag = monothelite_china_three
				has_global_flag = monothelite_china_four
			}
		}
		modifier = {
			factor = 1.5
			offmap_china = { offmap_ruler = { religion = monothelite } }
			NOT = { has_global_flag = monothelite_china_four }
		}
		modifier = {
			factor = 0
			offmap_china = { offmap_ruler = { religion = monothelite } }
			has_global_flag = monothelite_china_four
		}
	}
	
	option = { #No change
	
		ai_chance = {
			factor = 30
		}
	}
	
	option = { #Wax
		if = {
			limit = {
				offmap_china = {
					OR = {
						offmap_ruler = { religion = monothelite }
						offmap_china = { offmap_has_like = likes_christians }
					}
				}
			}
			change_variable = { which = "global_chinese_monothelites" value = 2 }
		}
		else = {
			change_variable = { which = "global_chinese_monothelites" value = 1 }
		}
		
		ai_chance = {
			factor = 60
			modifier = {
				factor = 1.1
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = monothelite
						culture = mongol
					}
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = monothelite
						OR = {
							culture = khitan
							culture = tangut
							culture = jurchen
							culture_group = chinese_group
						}
					}
				}
			}
			modifier = {
				factor = 1.2
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = monothelite
						OR = {
							culture = khitan
							culture = tangut
							culture = jurchen
						}
					}
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = monothelite
						culture_group = chinese_group
					}
				}
			}
			modifier = {
				factor = 1.3
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = monothelite
						culture_group = chinese_group
					}
				}
			}
			modifier = {
				factor = 5
				OR = {
					offmap_china = { offmap_has_like = likes_christians }
					offmap_china = { offmap_ruler = { religion = monothelite } }
				}
			}
			modifier = {
				factor = 1.5
				AND = {
					offmap_china = { offmap_ruler = { religion = monothelite } }
					offmap_china = { offmap_ruler = { culture_group = chinese_group } }
				}
			}
			modifier = {
				factor = 1.5
				AND = {
					offmap_china = { offmap_ruler = { religion = monothelite } }
					offmap_china = { has_status = china_golden_age }
				}
			}
			modifier = {
				factor = 0.2
				AND = {
					offmap_china = { offmap_ruler = { religion = monothelite } }
					offmap_china = {
						OR = {
							has_status = china_unrest
							has_status = china_famine
							has_status = china_plague
						}
					}
				}
			}
			modifier = {
				factor = 0.01
				AND = {
					offmap_china = { offmap_ruler = { religion = monothelite } }
					offmap_china = {
						OR = {
							has_status = china_civil_war
							has_status = china_mongol_invasion
							has_status = china_jurchen_invasion
						}
					}
				}
			}
			modifier = {
				factor = 3
				AND = {
					offmap_china = { offmap_ruler = { NOT = { religion = monothelite } } }
					offmap_china = {
						OR = {
							has_status = china_unrest
							has_status = china_civil_war
						}
					}
				}
			}
			modifier = {
				factor = 2
				OR = {
					AND = {
						offmap_china = { offmap_has_like = likes_indians }
						d_monothelite = { holder_scope = { culture_group = indo_aryan_group } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_dravidians }
						d_monothelite = { holder_scope = { culture_group = dravidian_group } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_tibetans }
						d_monothelite = { holder_scope = { culture_group = tibetan_group } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_germanics }
						d_monothelite = { holder_scope = {
							OR = {
								culture_group = north_germanic
								culture_group = central_germanic
								culture_group = west_germanic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_latino_iberians }
						d_monothelite = { holder_scope = {
							OR = {
								culture_group = latin
								culture_group = iberian
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_byzantines }
						d_monothelite = { holder_scope = { culture_group = byzantine } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_celts }
						d_monothelite = { holder_scope = { culture_group = celtic } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_finno_ugrics }
						d_monothelite = { holder_scope = {
							OR = {
								culture_group = finno_ugric
								culture_group = magyar
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_altaics }
						d_monothelite = { holder_scope = { culture_group = altaic } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_balto_slavics }
						d_monothelite = { holder_scope = {
							OR = {
								culture_group = baltic
								culture_group = east_slavic
								culture_group = west_slavic
								culture_group = south_slavic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_arabs }
						d_monothelite = { holder_scope = { culture_group = arabic } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_iranians }
						d_monothelite = { holder_scope = { culture_group = iranian } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_africans }
						d_monothelite = { holder_scope = {
							OR = {
								culture_group = west_african
								culture_group = east_african
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_mesoamericans }
						d_monothelite = { holder_scope = { culture_group = mesoamerican } }
					}
				}
			}
			modifier = {
				factor = 1.5
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = monothelite
					any_realm_province = {
						region = custom_eastern_access
					}
					NOR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
					OR = {
						has_character_modifier = peace_deal_with_china
						has_character_modifier = chinese_imperial_trade_contract
						has_character_modifier = chinese_favored_in_trade
						has_offmap_currency = { offmap = offmap_china value = 1000 }
					}
				}
			}
			modifier = {
				factor = 0.33
				OR = {
					offmap_china = { offmap_ruler = { religion_group = muslim } }
					AND = {
						offmap_china = { offmap_ruler = { religion_group = christian } }
						offmap_china = { offmap_ruler = { NOT = { religion = monothelite } } }
					}
					offmap_china = {
						offmap_ruler = {
							religion_group = pagan_group
							has_religion_feature = religion_dogmatic
						}
					}
				}
			}
			modifier = {
				factor = 1.33
				AND = {
					offmap_china = { offmap_ruler = { NOT = { religion = monothelite } } }
					has_global_flag = monothelite_patriach_moved_to_china
				}
			}
			modifier = {
				factor = 4
				AND = {
					offmap_china = { offmap_ruler = { religion = monothelite } }
					has_global_flag = monothelite_patriach_moved_to_china
				}
			}
		}
	}
	
	option = { #Wane
		if = {
			limit = {
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = monothelite
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
			change_variable = { which = "global_chinese_monothelites" value = -2 }
		}
		else = {
			change_variable = { which = "global_chinese_monothelites" value = -1 }
		}
	
		ai_chance = {
			factor = 30
			modifier = {
				factor = 0
				offmap_china = { offmap_ruler = { religion = monothelite } }
			}
			modifier = {
				factor = 0
				offmap_china = { offmap_has_like = likes_christians }
			}
			modifier = {
				factor = 0.1
				1513 = { has_province_modifier = kcc_recent_monothelite_mission }
			}
			modifier = {
				factor = 2
				OR = {
					AND = {
						offmap_china = { offmap_has_dislike = likes_indians }
						d_monothelite = { holder_scope = { culture_group = indo_aryan_group } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_dravidians }
						d_monothelite = { holder_scope = { culture_group = dravidian_group } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_tibetans }
						d_monothelite = { holder_scope = { culture_group = tibetan_group } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_germanics }
						d_monothelite = { holder_scope = {
							OR = {
								culture_group = north_germanic
								culture_group = central_germanic
								culture_group = west_germanic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_latino_iberians }
						d_monothelite = { holder_scope = {
							OR = {
								culture_group = latin
								culture_group = iberian
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_byzantines }
						d_monothelite = { holder_scope = { culture_group = byzantine } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_celts }
						d_monothelite = { holder_scope = { culture_group = celtic } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_finno_ugrics }
						d_monothelite = { holder_scope = {
							OR = {
								culture_group = finno_ugric
								culture_group = magyar
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_altaics }
						d_monothelite = { holder_scope = { culture_group = altaic } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_balto_slavics }
						d_monothelite = { holder_scope = {
							OR = {
								culture_group = baltic
								culture_group = east_slavic
								culture_group = west_slavic
								culture_group = south_slavic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_arabs }
						d_monothelite = { holder_scope = { culture_group = arabic } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_iranians }
						d_monothelite = { holder_scope = { culture_group = iranian } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_africans }
						d_monothelite = { holder_scope = {
							OR = {
								culture_group = west_african
								culture_group = east_african
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_mesoamericans }
						d_monothelite = { holder_scope = { culture_group = mesoamerican } }
					}
				}
			}
			modifier = {
				factor = 2
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = monothelite
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
		}
	}
}

# Wax & Wane of Iconoclasm
character_event = {
	id = kccwaxwane.0011
	hide_window = yes
	
	is_triggered_only = yes
	
	has_dlc = "Jade Dragon"
	only_playable = yes
	
	trigger = {
		has_landed_title = e_china_west_governor
	}
	
	after = {
		if = {
			limit = {
				check_variable = { which = "global_chinese_iconoclasts" value = 20 }
				NOT = { has_global_flag = iconoclast_china_one }
			}
			set_global_flag = iconoclast_china_one
			set_global_flag = kcc_waxwane_iconoclasts
			any_playable_ruler = { narrative_event = { id = kccspread.0003 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_iconoclasts" value = 40 }
				NOT = { has_global_flag = iconoclast_china_two }
			}
			set_global_flag = iconoclast_china_two
			set_global_flag = kcc_waxwane_iconoclasts
			any_playable_ruler = { narrative_event = { id = kccspread.0004 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_iconoclasts" value = 100 }
				NOT = { has_global_flag = iconoclast_china_three }
			}
			set_global_flag = iconoclast_china_three
			set_global_flag = kcc_waxwane_iconoclasts
			any_playable_ruler = { narrative_event = { id = kccspread.0005 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_iconoclasts" value = 180 }
				NOT = { has_global_flag = iconoclast_china_four }
				kcc_nontaoist_majority_trigger = yes
			}
			kcc_drop_other_religion_effect = yes
			set_global_flag = iconoclast_china_four
			set_global_flag = kcc_waxwane_iconoclasts
			any_playable_ruler = { narrative_event = { id = kccspread.0007 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_iconoclasts" value = 180 }
				NOT = { has_global_flag = iconoclast_china_four }
			}
			set_global_flag = iconoclast_china_four
			set_global_flag = kcc_waxwane_iconoclasts
			any_playable_ruler = { narrative_event = { id = kccspread.0006 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_iconoclasts" value = 100 } }
				has_global_flag = iconoclast_china_three
			}
			clr_global_flag = iconoclast_china_three
			set_global_flag = kcc_waxwane_iconoclasts
			any_playable_ruler = { narrative_event = { id = kccspread.0008 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_iconoclasts" value = 40 } }
				has_global_flag = iconoclast_china_two
			}
			clr_global_flag = iconoclast_china_two
			set_global_flag = kcc_waxwane_iconoclasts
			any_playable_ruler = { narrative_event = { id = kccspread.0009 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_iconoclasts" value = 20 } }
				has_global_flag = iconoclast_china_one
			}
			clr_global_flag = iconoclast_china_one
			set_global_flag = kcc_waxwane_iconoclasts
			any_playable_ruler = { narrative_event = { id = kccspread.0010 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_iconoclasts" value = 0 } }
				has_global_flag = iconoclasts_in_china
			}
			clr_global_flag = iconoclasts_in_china
			set_variable = { which = "global_chinese_iconoclasts" value = 0 }
			set_global_flag = kcc_waxwane_iconoclasts
			any_playable_ruler = { narrative_event = { id = kccspread.0011 days = 1 } }
		}
	}
	
	weight_multiplier = {
		days = 17
		modifier = {
			factor = 0
			NOR = { has_global_flag = iconoclasts_in_china }
		}
		modifier = {
			factor = 0
			1513 = {
				OR = {
					has_province_modifier = kcc_china_persecuted_christians
					has_province_modifier = kcc_china_persecuted_iconoclasts
					has_province_modifier = kcc_china_persecuted_byzantines
				}
			}
		}
		modifier = {
			factor = 2
			offmap_china = { offmap_has_like = likes_christians }
		}
		modifier = {
			factor = 5
			offmap_china = { offmap_ruler = { religion = iconoclast } }
			NOR = {
				has_global_flag = iconoclast_china_two
				has_global_flag = iconoclast_china_three
				has_global_flag = iconoclast_china_four
			}
		}
		modifier = {
			factor = 4
			offmap_china = { offmap_ruler = { religion = iconoclast } }
			NOR = {
				has_global_flag = iconoclast_china_three
				has_global_flag = iconoclast_china_four
			}
		}
		modifier = {
			factor = 1.5
			offmap_china = { offmap_ruler = { religion = iconoclast } }
			NOT = { has_global_flag = iconoclast_china_four }
		}
		modifier = {
			factor = 0
			offmap_china = { offmap_ruler = { religion = iconoclast } }
			has_global_flag = iconoclast_china_four
		}
	}
	
	option = { #No change
	
		ai_chance = {
			factor = 30
		}
	}
	
	option = { #Wax
		if = {
			limit = {
				offmap_china = {
					OR = {
						offmap_ruler = { religion = iconoclast }
						offmap_china = { offmap_has_like = likes_christians }
					}
				}
			}
			change_variable = { which = "global_chinese_iconoclasts" value = 2 }
		}
		else = {
			change_variable = { which = "global_chinese_iconoclasts" value = 1 }
		}
		
		ai_chance = {
			factor = 60
			modifier = {
				factor = 1.1
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = iconoclast
						culture = mongol
					}
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = iconoclast
						OR = {
							culture = khitan
							culture = tangut
							culture = jurchen
							culture_group = chinese_group
						}
					}
				}
			}
			modifier = {
				factor = 1.2
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = iconoclast
						OR = {
							culture = khitan
							culture = tangut
							culture = jurchen
						}
					}
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = iconoclast
						culture_group = chinese_group
					}
				}
			}
			modifier = {
				factor = 1.3
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = iconoclast
						culture_group = chinese_group
					}
				}
			}
			modifier = {
				factor = 5
				OR = {
					offmap_china = { offmap_has_like = likes_christians }
					offmap_china = { offmap_ruler = { religion = iconoclast } }
				}
			}
			modifier = {
				factor = 1.5
				AND = {
					offmap_china = { offmap_ruler = { religion = iconoclast } }
					offmap_china = { offmap_ruler = { culture_group = chinese_group } }
				}
			}
			modifier = {
				factor = 1.5
				AND = {
					offmap_china = { offmap_ruler = { religion = iconoclast } }
					offmap_china = { has_status = china_golden_age }
				}
			}
			modifier = {
				factor = 0.2
				AND = {
					offmap_china = { offmap_ruler = { religion = iconoclast } }
					offmap_china = {
						OR = {
							has_status = china_unrest
							has_status = china_famine
							has_status = china_plague
						}
					}
				}
			}
			modifier = {
				factor = 0.01
				AND = {
					offmap_china = { offmap_ruler = { religion = iconoclast } }
					offmap_china = {
						OR = {
							has_status = china_civil_war
							has_status = china_mongol_invasion
							has_status = china_jurchen_invasion
						}
					}
				}
			}
			modifier = {
				factor = 3
				AND = {
					offmap_china = { offmap_ruler = { NOT = { religion = iconoclast } } }
					offmap_china = {
						OR = {
							has_status = china_unrest
							has_status = china_civil_war
						}
					}
				}
			}
			modifier = {
				factor = 2
				OR = {
					AND = {
						offmap_china = { offmap_has_like = likes_indians }
						d_iconoclast = { holder_scope = { culture_group = indo_aryan_group } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_dravidians }
						d_iconoclast = { holder_scope = { culture_group = dravidian_group } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_tibetans }
						d_iconoclast = { holder_scope = { culture_group = tibetan_group } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_germanics }
						d_iconoclast = { holder_scope = {
							OR = {
								culture_group = north_germanic
								culture_group = central_germanic
								culture_group = west_germanic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_latino_iberians }
						d_iconoclast = { holder_scope = {
							OR = {
								culture_group = latin
								culture_group = iberian
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_byzantines }
						d_iconoclast = { holder_scope = { culture_group = byzantine } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_celts }
						d_iconoclast = { holder_scope = { culture_group = celtic } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_finno_ugrics }
						d_iconoclast = { holder_scope = {
							OR = {
								culture_group = finno_ugric
								culture_group = magyar
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_altaics }
						d_iconoclast = { holder_scope = { culture_group = altaic } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_balto_slavics }
						d_iconoclast = { holder_scope = {
							OR = {
								culture_group = baltic
								culture_group = east_slavic
								culture_group = west_slavic
								culture_group = south_slavic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_arabs }
						d_iconoclast = { holder_scope = { culture_group = arabic } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_iranians }
						d_iconoclast = { holder_scope = { culture_group = iranian } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_africans }
						d_iconoclast = { holder_scope = {
							OR = {
								culture_group = west_african
								culture_group = east_african
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_mesoamericans }
						d_iconoclast = { holder_scope = { culture_group = mesoamerican } }
					}
				}
			}
			modifier = {
				factor = 1.5
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = iconoclast
					any_realm_province = {
						region = custom_eastern_access
					}
					NOR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
					OR = {
						has_character_modifier = peace_deal_with_china
						has_character_modifier = chinese_imperial_trade_contract
						has_character_modifier = chinese_favored_in_trade
						has_offmap_currency = { offmap = offmap_china value = 1000 }
					}
				}
			}
			modifier = {
				factor = 0.33
				OR = {
					AND = {
						offmap_china = { offmap_ruler = { religion_group = christian } }
						offmap_china = { offmap_ruler = { NOT = { religion = iconoclast } } }
					}
					offmap_china = {
						offmap_ruler = {
							religion_group = pagan_group
							has_religion_feature = religion_dogmatic
						}
					}
				}
			}
			modifier = {
				factor = 1.33
				AND = {
					offmap_china = { offmap_ruler = { NOT = { religion = iconoclast } } }
					has_global_flag = iconoclast_patriach_moved_to_china
				}
			}
			modifier = {
				factor = 4
				AND = {
					offmap_china = { offmap_ruler = { religion = iconoclast } }
					has_global_flag = iconoclast_patriach_moved_to_china
				}
			}
		}
	}
	
	option = { #Wane
		if = {
			limit = {
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = iconoclast
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
			change_variable = { which = "global_chinese_iconoclasts" value = -2 }
		}
		else = {
			change_variable = { which = "global_chinese_iconoclasts" value = -1 }
		}
	
		ai_chance = {
			factor = 30
			modifier = {
				factor = 0
				offmap_china = { offmap_ruler = { religion = iconoclast } }
			}
			modifier = {
				factor = 0
				offmap_china = { offmap_has_like = likes_christians }
			}
			modifier = {
				factor = 0.1
				1513 = { has_province_modifier = kcc_recent_iconoclast_mission }
			}
			modifier = {
				factor = 2
				OR = {
					AND = {
						offmap_china = { offmap_has_dislike = likes_indians }
						d_iconoclast = { holder_scope = { culture_group = indo_aryan_group } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_dravidians }
						d_iconoclast = { holder_scope = { culture_group = dravidian_group } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_tibetans }
						d_iconoclast = { holder_scope = { culture_group = tibetan_group } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_germanics }
						d_iconoclast = { holder_scope = {
							OR = {
								culture_group = north_germanic
								culture_group = central_germanic
								culture_group = west_germanic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_latino_iberians }
						d_iconoclast = { holder_scope = {
							OR = {
								culture_group = latin
								culture_group = iberian
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_byzantines }
						d_iconoclast = { holder_scope = { culture_group = byzantine } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_celts }
						d_iconoclast = { holder_scope = { culture_group = celtic } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_finno_ugrics }
						d_iconoclast = { holder_scope = {
							OR = {
								culture_group = finno_ugric
								culture_group = magyar
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_altaics }
						d_iconoclast = { holder_scope = { culture_group = altaic } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_balto_slavics }
						d_iconoclast = { holder_scope = {
							OR = {
								culture_group = baltic
								culture_group = east_slavic
								culture_group = west_slavic
								culture_group = south_slavic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_arabs }
						d_iconoclast = { holder_scope = { culture_group = arabic } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_iranians }
						d_iconoclast = { holder_scope = { culture_group = iranian } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_africans }
						d_iconoclast = { holder_scope = {
							OR = {
								culture_group = west_african
								culture_group = east_african
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_mesoamericans }
						d_iconoclast = { holder_scope = { culture_group = mesoamerican } }
					}
				}
			}
			modifier = {
				factor = 2
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = iconoclast
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
		}
	}
}

# Wax & Wane of Paulicianism
character_event = {
	id = kccwaxwane.0012
	hide_window = yes
	
	is_triggered_only = yes
	
	has_dlc = "Jade Dragon"
	only_playable = yes
	
	trigger = {
		has_landed_title = e_china_west_governor
	}
	
	after = {
		if = {
			limit = {
				check_variable = { which = "global_chinese_paulicians" value = 20 }
				NOT = { has_global_flag = paulician_china_one }
			}
			set_global_flag = paulician_china_one
			set_global_flag = kcc_waxwane_paulicians
			any_playable_ruler = { narrative_event = { id = kccspread.0003 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_paulicians" value = 40 }
				NOT = { has_global_flag = paulician_china_two }
			}
			set_global_flag = paulician_china_two
			set_global_flag = kcc_waxwane_paulicians
			any_playable_ruler = { narrative_event = { id = kccspread.0004 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_paulicians" value = 100 }
				NOT = { has_global_flag = paulician_china_three }
			}
			set_global_flag = paulician_china_three
			set_global_flag = kcc_waxwane_paulicians
			any_playable_ruler = { narrative_event = { id = kccspread.0005 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_paulicians" value = 180 }
				NOT = { has_global_flag = paulician_china_four }
				kcc_nontaoist_majority_trigger = yes
			}
			kcc_drop_other_religion_effect = yes
			set_global_flag = paulician_china_four
			set_global_flag = kcc_waxwane_paulicians
			any_playable_ruler = { narrative_event = { id = kccspread.0007 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_paulicians" value = 180 }
				NOT = { has_global_flag = paulician_china_four }
			}
			set_global_flag = paulician_china_four
			set_global_flag = kcc_waxwane_paulicians
			any_playable_ruler = { narrative_event = { id = kccspread.0006 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_paulicians" value = 100 } }
				has_global_flag = paulician_china_three
			}
			clr_global_flag = paulician_china_three
			set_global_flag = kcc_waxwane_paulicians
			any_playable_ruler = { narrative_event = { id = kccspread.0008 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_paulicians" value = 40 } }
				has_global_flag = paulician_china_two
			}
			clr_global_flag = paulician_china_two
			set_global_flag = kcc_waxwane_paulicians
			any_playable_ruler = { narrative_event = { id = kccspread.0009 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_paulicians" value = 20 } }
				has_global_flag = paulician_china_one
			}
			clr_global_flag = paulician_china_one
			set_global_flag = kcc_waxwane_paulicians
			any_playable_ruler = { narrative_event = { id = kccspread.0010 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_paulicians" value = 0 } }
				has_global_flag = paulicians_in_china
			}
			clr_global_flag = paulicians_in_china
			set_variable = { which = "global_chinese_paulicians" value = 0 }
			set_global_flag = kcc_waxwane_paulicians
			any_playable_ruler = { narrative_event = { id = kccspread.0011 days = 1 } }
		}
	}
	
	weight_multiplier = {
		days = 17
		modifier = {
			factor = 0
			NOR = { has_global_flag = paulicians_in_china }
		}
		modifier = {
			factor = 0
			1513 = {
				OR = {
					has_province_modifier = kcc_china_persecuted_christians
					has_province_modifier = kcc_china_persecuted_paulicians
					has_province_modifier = kcc_china_persecuted_byzantines
				}
			}
		}
		modifier = {
			factor = 2
			offmap_china = { offmap_has_like = likes_christians }
		}
		modifier = {
			factor = 5
			offmap_china = { offmap_ruler = { religion = paulician } }
			NOR = {
				has_global_flag = paulician_china_two
				has_global_flag = paulician_china_three
				has_global_flag = paulician_china_four
			}
		}
		modifier = {
			factor = 4
			offmap_china = { offmap_ruler = { religion = paulician } }
			NOR = {
				has_global_flag = paulician_china_three
				has_global_flag = paulician_china_four
			}
		}
		modifier = {
			factor = 1.5
			offmap_china = { offmap_ruler = { religion = paulician } }
			NOT = { has_global_flag = paulician_china_four }
		}
		modifier = {
			factor = 0
			offmap_china = { offmap_ruler = { religion = paulician } }
			has_global_flag = paulician_china_four
		}
	}
	
	option = { #No change
	
		ai_chance = {
			factor = 30
		}
	}
	
	option = { #Wax
		if = {
			limit = {
				offmap_china = {
					OR = {
						offmap_ruler = { religion = paulician }
						offmap_china = { offmap_has_like = likes_christians }
					}
				}
			}
			change_variable = { which = "global_chinese_paulicians" value = 2 }
		}
		else = {
			change_variable = { which = "global_chinese_paulicians" value = 1 }
		}
		
		ai_chance = {
			factor = 60
			modifier = {
				factor = 1.1
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = paulician
						culture = mongol
					}
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = paulician
						OR = {
							culture = khitan
							culture = tangut
							culture = jurchen
							culture_group = chinese_group
						}
					}
				}
			}
			modifier = {
				factor = 1.2
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = paulician
						OR = {
							culture = khitan
							culture = tangut
							culture = jurchen
						}
					}
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = paulician
						culture_group = chinese_group
					}
				}
			}
			modifier = {
				factor = 1.3
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = paulician
						culture_group = chinese_group
					}
				}
			}
			modifier = {
				factor = 5
				OR = {
					offmap_china = { offmap_has_like = likes_christians }
					offmap_china = { offmap_ruler = { religion = paulician } }
				}
			}
			modifier = {
				factor = 1.5
				AND = {
					offmap_china = { offmap_ruler = { religion = paulician } }
					offmap_china = { offmap_ruler = { culture_group = chinese_group } }
				}
			}
			modifier = {
				factor = 1.5
				AND = {
					offmap_china = { offmap_ruler = { religion = paulician } }
					offmap_china = { has_status = china_golden_age }
				}
			}
			modifier = {
				factor = 0.2
				AND = {
					offmap_china = { offmap_ruler = { religion = paulician } }
					offmap_china = {
						OR = {
							has_status = china_unrest
							has_status = china_famine
							has_status = china_plague
						}
					}
				}
			}
			modifier = {
				factor = 0.01
				AND = {
					offmap_china = { offmap_ruler = { religion = paulician } }
					offmap_china = {
						OR = {
							has_status = china_civil_war
							has_status = china_mongol_invasion
							has_status = china_jurchen_invasion
						}
					}
				}
			}
			modifier = {
				factor = 3
				AND = {
					offmap_china = { offmap_ruler = { NOT = { religion = paulician } } }
					offmap_china = {
						OR = {
							has_status = china_unrest
							has_status = china_civil_war
						}
					}
				}
			}
			modifier = {
				factor = 2
				OR = {
					AND = {
						offmap_china = { offmap_has_like = likes_indians }
						d_paulician = { holder_scope = { culture_group = indo_aryan_group } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_dravidians }
						d_paulician = { holder_scope = { culture_group = dravidian_group } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_tibetans }
						d_paulician = { holder_scope = { culture_group = tibetan_group } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_germanics }
						d_paulician = { holder_scope = {
							OR = {
								culture_group = north_germanic
								culture_group = central_germanic
								culture_group = west_germanic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_latino_iberians }
						d_paulician = { holder_scope = {
							OR = {
								culture_group = latin
								culture_group = iberian
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_byzantines }
						d_paulician = { holder_scope = { culture_group = byzantine } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_celts }
						d_paulician = { holder_scope = { culture_group = celtic } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_finno_ugrics }
						d_paulician = { holder_scope = {
							OR = {
								culture_group = finno_ugric
								culture_group = magyar
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_altaics }
						d_paulician = { holder_scope = { culture_group = altaic } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_balto_slavics }
						d_paulician = { holder_scope = {
							OR = {
								culture_group = baltic
								culture_group = east_slavic
								culture_group = west_slavic
								culture_group = south_slavic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_arabs }
						d_paulician = { holder_scope = { culture_group = arabic } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_iranians }
						d_paulician = { holder_scope = { culture_group = iranian } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_africans }
						d_paulician = { holder_scope = {
							OR = {
								culture_group = west_african
								culture_group = east_african
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_mesoamericans }
						d_paulician = { holder_scope = { culture_group = mesoamerican } }
					}
				}
			}
			modifier = {
				factor = 1.5
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = paulician
					any_realm_province = {
						region = custom_eastern_access
					}
					NOR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
					OR = {
						has_character_modifier = peace_deal_with_china
						has_character_modifier = chinese_imperial_trade_contract
						has_character_modifier = chinese_favored_in_trade
						has_offmap_currency = { offmap = offmap_china value = 1000 }
					}
				}
			}
			modifier = {
				factor = 0.33
				OR = {
					offmap_china = { offmap_ruler = { religion_group = muslim } }
					AND = {
						offmap_china = { offmap_ruler = { religion_group = christian } }
						offmap_china = { offmap_ruler = { NOT = { religion = paulician } } }
					}
					offmap_china = {
						offmap_ruler = {
							religion_group = pagan_group
							has_religion_feature = religion_dogmatic
						}
					}
				}
			}
			modifier = {
				factor = 1.33
				AND = {
					offmap_china = { offmap_ruler = { NOT = { religion = paulician } } }
					has_global_flag = paulician_patriach_moved_to_china
				}
			}
			modifier = {
				factor = 4
				AND = {
					offmap_china = { offmap_ruler = { religion = paulician } }
					has_global_flag = paulician_patriach_moved_to_china
				}
			}
		}
	}
	
	option = { #Wane
		if = {
			limit = {
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = paulician
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
			change_variable = { which = "global_chinese_paulicians" value = -2 }
		}
		else = {
			change_variable = { which = "global_chinese_paulicians" value = -1 }
		}
	
		ai_chance = {
			factor = 30
			modifier = {
				factor = 0
				offmap_china = { offmap_ruler = { religion = paulician } }
			}
			modifier = {
				factor = 0
				offmap_china = { offmap_has_like = likes_christians }
			}
			modifier = {
				factor = 0.1
				1513 = { has_province_modifier = kcc_recent_paulician_mission }
			}
			modifier = {
				factor = 2
				OR = {
					AND = {
						offmap_china = { offmap_has_dislike = likes_indians }
						d_paulician = { holder_scope = { culture_group = indo_aryan_group } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_dravidians }
						d_paulician = { holder_scope = { culture_group = dravidian_group } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_tibetans }
						d_paulician = { holder_scope = { culture_group = tibetan_group } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_germanics }
						d_paulician = { holder_scope = {
							OR = {
								culture_group = north_germanic
								culture_group = central_germanic
								culture_group = west_germanic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_latino_iberians }
						d_paulician = { holder_scope = {
							OR = {
								culture_group = latin
								culture_group = iberian
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_byzantines }
						d_paulician = { holder_scope = { culture_group = byzantine } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_celts }
						d_paulician = { holder_scope = { culture_group = celtic } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_finno_ugrics }
						d_paulician = { holder_scope = {
							OR = {
								culture_group = finno_ugric
								culture_group = magyar
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_altaics }
						d_paulician = { holder_scope = { culture_group = altaic } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_balto_slavics }
						d_paulician = { holder_scope = {
							OR = {
								culture_group = baltic
								culture_group = east_slavic
								culture_group = west_slavic
								culture_group = south_slavic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_arabs }
						d_paulician = { holder_scope = { culture_group = arabic } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_iranians }
						d_paulician = { holder_scope = { culture_group = iranian } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_africans }
						d_paulician = { holder_scope = {
							OR = {
								culture_group = west_african
								culture_group = east_african
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_mesoamericans }
						d_paulician = { holder_scope = { culture_group = mesoamerican } }
					}
				}
			}
			modifier = {
				factor = 2
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = paulician
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
		}
	}
}

# Wax & Wane of Nestorianism
character_event = {
	id = kccwaxwane.0013
	hide_window = yes
	
	is_triggered_only = yes
	
	has_dlc = "Jade Dragon"
	only_playable = yes
	
	trigger = {
		has_landed_title = e_china_west_governor
	}
	
	after = {
		if = {
			limit = {
				check_variable = { which = "global_chinese_nestorians" value = 20 }
				NOT = { has_global_flag = nestorian_china_one }
			}
			set_global_flag = nestorian_china_one
			set_global_flag = kcc_waxwane_nestorians
			any_playable_ruler = { narrative_event = { id = kccspread.0003 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_nestorians" value = 40 }
				NOT = { has_global_flag = nestorian_china_two }
			}
			set_global_flag = nestorian_china_two
			set_global_flag = kcc_waxwane_nestorians
			any_playable_ruler = { narrative_event = { id = kccspread.0004 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_nestorians" value = 100 }
				NOT = { has_global_flag = nestorian_china_three }
			}
			set_global_flag = nestorian_china_three
			set_global_flag = kcc_waxwane_nestorians
			any_playable_ruler = { narrative_event = { id = kccspread.0005 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_nestorians" value = 180 }
				NOT = { has_global_flag = nestorian_china_four }
				kcc_nontaoist_majority_trigger = yes
			}
			kcc_drop_other_religion_effect = yes
			set_global_flag = nestorian_china_four
			set_global_flag = kcc_waxwane_nestorians
			any_playable_ruler = { narrative_event = { id = kccspread.0007 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_nestorians" value = 180 }
				NOT = { has_global_flag = nestorian_china_four }
			}
			set_global_flag = nestorian_china_four
			set_global_flag = kcc_waxwane_nestorians
			any_playable_ruler = { narrative_event = { id = kccspread.0006 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_nestorians" value = 100 } }
				has_global_flag = nestorian_china_three
			}
			clr_global_flag = nestorian_china_three
			set_global_flag = kcc_waxwane_nestorians
			any_playable_ruler = { narrative_event = { id = kccspread.0008 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_nestorians" value = 40 } }
				has_global_flag = nestorian_china_two
			}
			clr_global_flag = nestorian_china_two
			set_global_flag = kcc_waxwane_nestorians
			any_playable_ruler = { narrative_event = { id = kccspread.0009 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_nestorians" value = 20 } }
				has_global_flag = nestorian_china_one
			}
			clr_global_flag = nestorian_china_one
			set_global_flag = kcc_waxwane_nestorians
			any_playable_ruler = { narrative_event = { id = kccspread.0010 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_nestorians" value = 0 } }
				has_global_flag = nestorians_in_china
			}
			clr_global_flag = nestorians_in_china
			set_variable = { which = "global_chinese_nestorians" value = 0 }
			set_global_flag = kcc_waxwane_nestorians
			any_playable_ruler = { narrative_event = { id = kccspread.0011 days = 1 } }
		}
	}
	
	weight_multiplier = {
		days = 17
		modifier = {
			factor = 0
			NOR = { has_global_flag = nestorians_in_china }
		}
		modifier = {
			factor = 0
			1513 = {
				OR = {
					has_province_modifier = kcc_china_persecuted_christians
					has_province_modifier = kcc_china_persecuted_nestorians
					has_province_modifier = kcc_china_persecuted_nonchalcedonians
				}
			}
		}
		modifier = {
			factor = 2
			offmap_china = { offmap_has_like = likes_christians }
		}
		modifier = {
			factor = 5
			offmap_china = { offmap_ruler = { religion = nestorian } }
			NOR = {
				has_global_flag = nestorian_china_two
				has_global_flag = nestorian_china_three
				has_global_flag = nestorian_china_four
			}
		}
		modifier = {
			factor = 4
			offmap_china = { offmap_ruler = { religion = nestorian } }
			NOR = {
				has_global_flag = nestorian_china_three
				has_global_flag = nestorian_china_four
			}
		}
		modifier = {
			factor = 1.5
			offmap_china = { offmap_ruler = { religion = nestorian } }
			NOT = { has_global_flag = nestorian_china_four }
		}
		modifier = {
			factor = 0
			offmap_china = { offmap_ruler = { religion = nestorian } }
			has_global_flag = nestorian_china_four
		}
	}
	
	option = { #No change
	
		ai_chance = {
			factor = 30
		}
	}
	
	option = { #Wax
		if = {
			limit = {
				offmap_china = {
					OR = {
						offmap_ruler = { religion = nestorian }
						offmap_china = { offmap_has_like = likes_christians }
					}
				}
			}
			change_variable = { which = "global_chinese_nestorians" value = 2 }
		}
		else = {
			change_variable = { which = "global_chinese_nestorians" value = 1 }
		}
		
		ai_chance = {
			factor = 60
			modifier = {
				factor = 1.1
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = nestorian
						culture = mongol
					}
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = nestorian
						OR = {
							culture = khitan
							culture = tangut
							culture = jurchen
							culture_group = chinese_group
						}
					}
				}
			}
			modifier = {
				factor = 1.2
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = nestorian
						OR = {
							culture = khitan
							culture = tangut
							culture = jurchen
						}
					}
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = nestorian
						culture_group = chinese_group
					}
				}
			}
			modifier = {
				factor = 1.3
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = nestorian
						culture_group = chinese_group
					}
				}
			}
			modifier = {
				factor = 5
				OR = {
					offmap_china = { offmap_has_like = likes_christians }
					offmap_china = { offmap_ruler = { religion = nestorian } }
				}
			}
			modifier = {
				factor = 1.5
				AND = {
					offmap_china = { offmap_ruler = { religion = nestorian } }
					offmap_china = { offmap_ruler = { culture_group = chinese_group } }
				}
			}
			modifier = {
				factor = 1.5
				AND = {
					offmap_china = { offmap_ruler = { religion = nestorian } }
					offmap_china = { has_status = china_golden_age }
				}
			}
			modifier = {
				factor = 0.2
				AND = {
					offmap_china = { offmap_ruler = { religion = nestorian } }
					offmap_china = {
						OR = {
							has_status = china_unrest
							has_status = china_famine
							has_status = china_plague
						}
					}
				}
			}
			modifier = {
				factor = 0.01
				AND = {
					offmap_china = { offmap_ruler = { religion = nestorian } }
					offmap_china = {
						OR = {
							has_status = china_civil_war
							has_status = china_mongol_invasion
							has_status = china_jurchen_invasion
						}
					}
				}
			}
			modifier = {
				factor = 3
				AND = {
					offmap_china = { offmap_ruler = { NOT = { religion = nestorian } } }
					offmap_china = {
						OR = {
							has_status = china_unrest
							has_status = china_civil_war
						}
					}
				}
			}
			modifier = {
				factor = 2
				OR = {
					AND = {
						offmap_china = { offmap_has_like = likes_indians }
						d_nestorian = { holder_scope = { culture_group = indo_aryan_group } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_dravidians }
						d_nestorian = { holder_scope = { culture_group = dravidian_group } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_tibetans }
						d_nestorian = { holder_scope = { culture_group = tibetan_group } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_germanics }
						d_nestorian = { holder_scope = {
							OR = {
								culture_group = north_germanic
								culture_group = central_germanic
								culture_group = west_germanic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_latino_iberians }
						d_nestorian = { holder_scope = {
							OR = {
								culture_group = latin
								culture_group = iberian
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_byzantines }
						d_nestorian = { holder_scope = { culture_group = byzantine } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_celts }
						d_nestorian = { holder_scope = { culture_group = celtic } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_finno_ugrics }
						d_nestorian = { holder_scope = {
							OR = {
								culture_group = finno_ugric
								culture_group = magyar
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_altaics }
						d_nestorian = { holder_scope = { culture_group = altaic } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_balto_slavics }
						d_nestorian = { holder_scope = {
							OR = {
								culture_group = baltic
								culture_group = east_slavic
								culture_group = west_slavic
								culture_group = south_slavic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_arabs }
						d_nestorian = { holder_scope = { culture_group = arabic } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_iranians }
						d_nestorian = { holder_scope = { culture_group = iranian } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_africans }
						d_nestorian = { holder_scope = {
							OR = {
								culture_group = west_african
								culture_group = east_african
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_mesoamericans }
						d_nestorian = { holder_scope = { culture_group = mesoamerican } }
					}
				}
			}
			modifier = {
				factor = 1.5
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = nestorian
					any_realm_province = {
						region = custom_eastern_access
					}
					NOR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
					OR = {
						has_character_modifier = peace_deal_with_china
						has_character_modifier = chinese_imperial_trade_contract
						has_character_modifier = chinese_favored_in_trade
						has_offmap_currency = { offmap = offmap_china value = 1000 }
					}
				}
			}
			modifier = {
				factor = 0.33
				OR = {
					offmap_china = { offmap_ruler = { religion_group = muslim } }
					AND = {
						offmap_china = { offmap_ruler = { religion_group = christian } }
						offmap_china = { offmap_ruler = { NOT = { religion = nestorian } } }
					}
					offmap_china = {
						offmap_ruler = {
							religion_group = pagan_group
							has_religion_feature = religion_dogmatic
						}
					}
				}
			}
			modifier = {
				factor = 1.33
				AND = {
					offmap_china = { offmap_ruler = { NOT = { religion = nestorian } } }
					has_global_flag = nestorian_patriach_moved_to_china
				}
			}
			modifier = {
				factor = 4
				AND = {
					offmap_china = { offmap_ruler = { religion = nestorian } }
					has_global_flag = nestorian_patriach_moved_to_china
				}
			}
		}
	}
	
	option = { #Wane
		if = {
			limit = {
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = nestorian
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
			change_variable = { which = "global_chinese_nestorians" value = -2 }
		}
		else = {
			change_variable = { which = "global_chinese_nestorians" value = -1 }
		}
	
		ai_chance = {
			factor = 30
			modifier = {
				factor = 0
				offmap_china = { offmap_ruler = { religion = nestorian } }
			}
			modifier = {
				factor = 0
				offmap_china = { offmap_has_like = likes_christians }
			}
			modifier = {
				factor = 0.1
				1513 = { has_province_modifier = kcc_recent_nestorian_mission }
			}
			modifier = {
				factor = 2
				OR = {
					AND = {
						offmap_china = { offmap_has_dislike = likes_indians }
						d_nestorian = { holder_scope = { culture_group = indo_aryan_group } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_dravidians }
						d_nestorian = { holder_scope = { culture_group = dravidian_group } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_tibetans }
						d_nestorian = { holder_scope = { culture_group = tibetan_group } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_germanics }
						d_nestorian = { holder_scope = {
							OR = {
								culture_group = north_germanic
								culture_group = central_germanic
								culture_group = west_germanic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_latino_iberians }
						d_nestorian = { holder_scope = {
							OR = {
								culture_group = latin
								culture_group = iberian
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_byzantines }
						d_nestorian = { holder_scope = { culture_group = byzantine } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_celts }
						d_nestorian = { holder_scope = { culture_group = celtic } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_finno_ugrics }
						d_nestorian = { holder_scope = {
							OR = {
								culture_group = finno_ugric
								culture_group = magyar
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_altaics }
						d_nestorian = { holder_scope = { culture_group = altaic } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_balto_slavics }
						d_nestorian = { holder_scope = {
							OR = {
								culture_group = baltic
								culture_group = east_slavic
								culture_group = west_slavic
								culture_group = south_slavic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_arabs }
						d_nestorian = { holder_scope = { culture_group = arabic } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_iranians }
						d_nestorian = { holder_scope = { culture_group = iranian } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_africans }
						d_nestorian = { holder_scope = {
							OR = {
								culture_group = west_african
								culture_group = east_african
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_mesoamericans }
						d_nestorian = { holder_scope = { culture_group = mesoamerican } }
					}
				}
			}
			modifier = {
				factor = 2
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = nestorian
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
		}
	}
}

# Wax & Wane of Messalianism
character_event = {
	id = kccwaxwane.0014
	hide_window = yes
	
	is_triggered_only = yes
	
	has_dlc = "Jade Dragon"
	only_playable = yes
	
	trigger = {
		has_landed_title = e_china_west_governor
	}
	
	after = {
		if = {
			limit = {
				check_variable = { which = "global_chinese_messalians" value = 20 }
				NOT = { has_global_flag = messalian_china_one }
			}
			set_global_flag = messalian_china_one
			set_global_flag = kcc_waxwane_messalians
			any_playable_ruler = { narrative_event = { id = kccspread.0003 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_messalians" value = 40 }
				NOT = { has_global_flag = messalian_china_two }
			}
			set_global_flag = messalian_china_two
			set_global_flag = kcc_waxwane_messalians
			any_playable_ruler = { narrative_event = { id = kccspread.0004 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_messalians" value = 100 }
				NOT = { has_global_flag = messalian_china_three }
			}
			set_global_flag = messalian_china_three
			set_global_flag = kcc_waxwane_messalians
			any_playable_ruler = { narrative_event = { id = kccspread.0005 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_messalians" value = 180 }
				NOT = { has_global_flag = messalian_china_four }
				kcc_nontaoist_majority_trigger = yes
			}
			kcc_drop_other_religion_effect = yes
			set_global_flag = messalian_china_four
			set_global_flag = kcc_waxwane_messalians
			any_playable_ruler = { narrative_event = { id = kccspread.0007 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_messalians" value = 180 }
				NOT = { has_global_flag = messalian_china_four }
			}
			set_global_flag = messalian_china_four
			set_global_flag = kcc_waxwane_messalians
			any_playable_ruler = { narrative_event = { id = kccspread.0006 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_messalians" value = 100 } }
				has_global_flag = messalian_china_three
			}
			clr_global_flag = messalian_china_three
			set_global_flag = kcc_waxwane_messalians
			any_playable_ruler = { narrative_event = { id = kccspread.0008 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_messalians" value = 40 } }
				has_global_flag = messalian_china_two
			}
			clr_global_flag = messalian_china_two
			set_global_flag = kcc_waxwane_messalians
			any_playable_ruler = { narrative_event = { id = kccspread.0009 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_messalians" value = 20 } }
				has_global_flag = messalian_china_one
			}
			clr_global_flag = messalian_china_one
			set_global_flag = kcc_waxwane_messalians
			any_playable_ruler = { narrative_event = { id = kccspread.0010 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_messalians" value = 0 } }
				has_global_flag = messalians_in_china
			}
			clr_global_flag = messalians_in_china
			set_variable = { which = "global_chinese_messalians" value = 0 }
			set_global_flag = kcc_waxwane_messalians
			any_playable_ruler = { narrative_event = { id = kccspread.0011 days = 1 } }
		}
	}
	
	weight_multiplier = {
		days = 17
		modifier = {
			factor = 0
			NOR = { has_global_flag = messalians_in_china }
		}
		modifier = {
			factor = 0
			1513 = {
				OR = {
					has_province_modifier = kcc_china_persecuted_christians
					has_province_modifier = kcc_china_persecuted_messalians
					has_province_modifier = kcc_china_persecuted_nonchalcedonians
				}
			}
		}
		modifier = {
			factor = 2
			offmap_china = { offmap_has_like = likes_christians }
		}
		modifier = {
			factor = 5
			offmap_china = { offmap_ruler = { religion = messalian } }
			NOR = {
				has_global_flag = messalian_china_two
				has_global_flag = messalian_china_three
				has_global_flag = messalian_china_four
			}
		}
		modifier = {
			factor = 4
			offmap_china = { offmap_ruler = { religion = messalian } }
			NOR = {
				has_global_flag = messalian_china_three
				has_global_flag = messalian_china_four
			}
		}
		modifier = {
			factor = 1.5
			offmap_china = { offmap_ruler = { religion = messalian } }
			NOT = { has_global_flag = messalian_china_four }
		}
		modifier = {
			factor = 0
			offmap_china = { offmap_ruler = { religion = messalian } }
			has_global_flag = messalian_china_four
		}
		modifier = {
			factor = 1.33
			offmap_china = { offmap_ruler = { is_female = yes } }
		}
	}
	
	option = { #No change
	
		ai_chance = {
			factor = 30
		}
	}
	
	option = { #Wax
		if = {
			limit = {
				offmap_china = {
					OR = {
						offmap_ruler = { religion = messalian }
						offmap_china = { offmap_has_like = likes_christians }
					}
				}
			}
			change_variable = { which = "global_chinese_messalians" value = 2 }
		}
		else = {
			change_variable = { which = "global_chinese_messalians" value = 1 }
		}
		
		ai_chance = {
			factor = 60
			modifier = {
				factor = 1.1
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = messalian
						culture = mongol
					}
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = messalian
						OR = {
							culture = khitan
							culture = tangut
							culture = jurchen
							culture_group = chinese_group
						}
					}
				}
			}
			modifier = {
				factor = 1.2
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = messalian
						OR = {
							culture = khitan
							culture = tangut
							culture = jurchen
						}
					}
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = messalian
						culture_group = chinese_group
					}
				}
			}
			modifier = {
				factor = 1.3
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = messalian
						culture_group = chinese_group
					}
				}
			}
			modifier = {
				factor = 5
				OR = {
					offmap_china = { offmap_has_like = likes_christians }
					offmap_china = { offmap_ruler = { religion = messalian } }
				}
			}
			modifier = {
				factor = 1.5
				AND = {
					offmap_china = { offmap_ruler = { religion = messalian } }
					offmap_china = { offmap_ruler = { culture_group = chinese_group } }
				}
			}
			modifier = {
				factor = 1.5
				AND = {
					offmap_china = { offmap_ruler = { religion = messalian } }
					offmap_china = { has_status = china_golden_age }
				}
			}
			modifier = {
				factor = 0.2
				AND = {
					offmap_china = { offmap_ruler = { religion = messalian } }
					offmap_china = {
						OR = {
							has_status = china_unrest
							has_status = china_famine
							has_status = china_plague
						}
					}
				}
			}
			modifier = {
				factor = 0.01
				AND = {
					offmap_china = { offmap_ruler = { religion = messalian } }
					offmap_china = {
						OR = {
							has_status = china_civil_war
							has_status = china_mongol_invasion
							has_status = china_jurchen_invasion
						}
					}
				}
			}
			modifier = {
				factor = 3
				AND = {
					offmap_china = { offmap_ruler = { NOT = { religion = messalian } } }
					offmap_china = {
						OR = {
							has_status = china_unrest
							has_status = china_civil_war
						}
					}
				}
			}
			modifier = {
				factor = 1.5
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = messalian
					any_realm_province = {
						region = custom_eastern_access
					}
					NOR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
					OR = {
						has_character_modifier = peace_deal_with_china
						has_character_modifier = chinese_imperial_trade_contract
						has_character_modifier = chinese_favored_in_trade
						has_offmap_currency = { offmap = offmap_china value = 1000 }
					}
				}
			}
			modifier = {
				factor = 0.33
				OR = {
					offmap_china = { offmap_ruler = { religion_group = muslim } }
					AND = {
						offmap_china = { offmap_ruler = { religion_group = christian } }
						offmap_china = { offmap_ruler = { NOT = { religion = messalian } } }
					}
					offmap_china = {
						offmap_ruler = {
							religion_group = pagan_group
							has_religion_feature = religion_dogmatic
						}
					}
				}
			}
			modifier = {
				factor = 1.33
				offmap_china = { offmap_ruler = { is_female = yes } }
			}
		}
	}
	
	option = { #Wane
		if = {
			limit = {
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = messalian
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
			change_variable = { which = "global_chinese_messalians" value = -2 }
		}
		else = {
			change_variable = { which = "global_chinese_messalians" value = -1 }
		}
	
		ai_chance = {
			factor = 30
			modifier = {
				factor = 0
				offmap_china = { offmap_ruler = { religion = messalian } }
			}
			modifier = {
				factor = 0
				offmap_china = { offmap_has_like = likes_christians }
			}
			modifier = {
				factor = 0.1
				1513 = { has_province_modifier = kcc_recent_messalian_mission }
			}
			modifier = {
				factor = 2
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = messalian
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
		}
	}
}

# Wax & Wane of Sunni Islam
character_event = {
	id = kccwaxwane.0015
	hide_window = yes
	
	is_triggered_only = yes
	
	has_dlc = "Jade Dragon"
	only_playable = yes
	
	trigger = {
		has_landed_title = e_china_west_governor
	}
	
	after = {
		if = {
			limit = {
				check_variable = { which = "global_chinese_sunnis" value = 20 }
				NOT = { has_global_flag = sunni_china_one }
			}
			set_global_flag = sunni_china_one
			set_global_flag = kcc_waxwane_sunnis
			any_playable_ruler = { narrative_event = { id = kccspread.0003 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_sunnis" value = 40 }
				NOT = { has_global_flag = sunni_china_two }
			}
			set_global_flag = sunni_china_two
			set_global_flag = kcc_waxwane_sunnis
			any_playable_ruler = { narrative_event = { id = kccspread.0004 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_sunnis" value = 100 }
				NOT = { has_global_flag = sunni_china_three }
			}
			set_global_flag = sunni_china_three
			set_global_flag = kcc_waxwane_sunnis
			any_playable_ruler = { narrative_event = { id = kccspread.0005 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_sunnis" value = 180 }
				NOT = { has_global_flag = sunni_china_four }
				kcc_nontaoist_majority_trigger = yes
			}
			kcc_drop_other_religion_effect = yes
			set_global_flag = sunni_china_four
			set_global_flag = kcc_waxwane_sunnis
			any_playable_ruler = { narrative_event = { id = kccspread.0007 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_sunnis" value = 180 }
				NOT = { has_global_flag = sunni_china_four }
			}
			set_global_flag = sunni_china_four
			set_global_flag = kcc_waxwane_sunnis
			any_playable_ruler = { narrative_event = { id = kccspread.0006 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_sunnis" value = 100 } }
				has_global_flag = sunni_china_three
			}
			clr_global_flag = sunni_china_three
			set_global_flag = kcc_waxwane_sunnis
			any_playable_ruler = { narrative_event = { id = kccspread.0008 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_sunnis" value = 40 } }
				has_global_flag = sunni_china_two
			}
			clr_global_flag = sunni_china_two
			set_global_flag = kcc_waxwane_sunnis
			any_playable_ruler = { narrative_event = { id = kccspread.0009 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_sunnis" value = 20 } }
				has_global_flag = sunni_china_one
			}
			clr_global_flag = sunni_china_one
			set_global_flag = kcc_waxwane_sunnis
			any_playable_ruler = { narrative_event = { id = kccspread.0010 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_sunnis" value = 0 } }
				has_global_flag = sunnis_in_china
			}
			clr_global_flag = sunnis_in_china
			set_variable = { which = "global_chinese_sunnis" value = 0 }
			set_global_flag = kcc_waxwane_sunnis
			any_playable_ruler = { narrative_event = { id = kccspread.0011 days = 1 } }
		}
	}
	
	weight_multiplier = {
		days = 17
		modifier = {
			factor = 0
			NOT = { has_global_flag = sunnis_in_china }
		}
		modifier = {
			factor = 0
			1513 = {
				OR = {
					has_province_modifier = kcc_china_persecuted_muslims
					has_province_modifier = kcc_china_persecuted_sunnis
				}
			}
		}
		modifier = {
			factor = 2
			offmap_china = { offmap_has_like = likes_muslims }
		}
		modifier = {
			factor = 5
			offmap_china = { offmap_ruler = { religion = sunni } }
			NOR = {
				has_global_flag = sunni_china_two
				has_global_flag = sunni_china_three
				has_global_flag = sunni_china_four
			}
		}
		modifier = {
			factor = 4
			offmap_china = { offmap_ruler = { religion = sunni } }
			NOR = {
				has_global_flag = sunni_china_three
				has_global_flag = sunni_china_four
			}
		}
		modifier = {
			factor = 1.5
			offmap_china = { offmap_ruler = { religion = sunni } }
			NOT = { has_global_flag = sunni_china_four }
		}
		modifier = {
			factor = 0
			offmap_china = { offmap_ruler = { religion = sunni } }
			has_global_flag = sunni_china_four
		}
	}
	
	option = { #No change
	
		ai_chance = {
			factor = 30
		}
	}
	
	option = { #Wax
		if = {
			limit = {
				offmap_china = {
					OR = {
						offmap_ruler = { religion = sunni }
						offmap_china = { offmap_has_like = likes_muslims }
					}
				}
			}
			change_variable = { which = "global_chinese_sunnis" value = 2 }
		}
		else = {
			change_variable = { which = "global_chinese_sunnis" value = 1 }
		}
		
		ai_chance = {
			factor = 60
			modifier = {
				factor = 1.1
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = sunni
						culture = mongol
					}
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = sunni
						OR = {
							culture = khitan
							culture = tangut
							culture = jurchen
							culture_group = chinese_group
						}
					}
				}
			}
			modifier = {
				factor = 1.2
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = sunni
						OR = {
							culture = khitan
							culture = tangut
							culture = jurchen
						}
					}
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = sunni
						culture_group = chinese_group
					}
				}
			}
			modifier = {
				factor = 1.3
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = sunni
						culture_group = chinese_group
					}
				}
			}
			modifier = {
				factor = 5
				OR = {
					offmap_china = { offmap_has_like = likes_muslims }
					offmap_china = { offmap_ruler = { religion = sunni } }
				}
			}
			modifier = {
				factor = 1.2
				offmap_china = { offmap_ruler = { religion_group = muslim } }
			}
			modifier = {
				factor = 1.5
				AND = {
					offmap_china = { offmap_ruler = { religion = sunni } }
					offmap_china = { offmap_ruler = { culture_group = chinese_group } }
				}
			}
			modifier = {
				factor = 1.5
				AND = {
					offmap_china = { offmap_ruler = { religion = sunni } }
					offmap_china = { has_status = china_golden_age }
				}
			}
			modifier = {
				factor = 0.2
				AND = {
					offmap_china = { offmap_ruler = { religion = sunni } }
					offmap_china = {
						OR = {
							has_status = china_unrest
							has_status = china_famine
							has_status = china_plague
						}
					}
				}
			}
			modifier = {
				factor = 0.01
				AND = {
					offmap_china = { offmap_ruler = { religion = sunni } }
					offmap_china = {
						OR = {
							has_status = china_civil_war
							has_status = china_mongol_invasion
							has_status = china_jurchen_invasion
						}
					}
				}
			}
			modifier = {
				factor = 3
				AND = {
					offmap_china = { offmap_ruler = { NOT = { religion = sunni } } }
					offmap_china = {
						OR = {
							has_status = china_unrest
							has_status = china_civil_war
						}
					}
				}
			}
			modifier = {
				factor = 2
				OR = {
					AND = {
						offmap_china = { offmap_has_like = likes_indians }
						d_sunni = { holder_scope = { culture_group = indo_aryan_group } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_dravidians }
						d_sunni = { holder_scope = { culture_group = dravidian_group } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_tibetans }
						d_sunni = { holder_scope = { culture_group = tibetan_group } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_germanics }
						d_sunni = { holder_scope = {
							OR = {
								culture_group = north_germanic
								culture_group = central_germanic
								culture_group = west_germanic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_latino_iberians }
						d_sunni = { holder_scope = {
							OR = {
								culture_group = latin
								culture_group = iberian
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_byzantines }
						d_sunni = { holder_scope = { culture_group = byzantine } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_celts }
						d_sunni = { holder_scope = { culture_group = celtic } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_finno_ugrics }
						d_sunni = { holder_scope = {
							OR = {
								culture_group = finno_ugric
								culture_group = magyar
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_altaics }
						d_sunni = { holder_scope = { culture_group = altaic } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_balto_slavics }
						d_sunni = { holder_scope = {
							OR = {
								culture_group = baltic
								culture_group = east_slavic
								culture_group = west_slavic
								culture_group = south_slavic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_arabs }
						d_sunni = { holder_scope = { culture_group = arabic } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_iranians }
						d_sunni = { holder_scope = { culture_group = iranian } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_africans }
						d_sunni = { holder_scope = {
							OR = {
								culture_group = west_african
								culture_group = east_african
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_mesoamericans }
						d_sunni = { holder_scope = { culture_group = mesoamerican } }
					}
				}
			}
			modifier = {
				factor = 1.5
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = sunni
					any_realm_province = {
						region = custom_eastern_access
					}
					NOR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
					OR = {
						has_character_modifier = peace_deal_with_china
						has_character_modifier = chinese_imperial_trade_contract
						has_character_modifier = chinese_favored_in_trade
						has_offmap_currency = { offmap = offmap_china value = 1000 }
					}
				}
			}
			modifier = {
				factor = 0.33
				OR = {
					offmap_china = { offmap_ruler = { religion_group = christian } }
					offmap_china = {
						offmap_ruler = {
							religion_group = pagan_group
							has_religion_feature = religion_dogmatic
						}
					}
				}
			}
			modifier = {
				factor = 0.05
				OR = {
					offmap_china = { offmap_ruler = { religion = shiite } }
					offmap_china = { offmap_ruler = { religion = qarmatian } }
					offmap_china = { offmap_ruler = { religion = hurufi } }
				}
			}
			modifier = {
				factor = 1.33
				AND = {
					offmap_china = { offmap_ruler = { NOT = { religion = sunni } } }
					has_global_flag = sunni_chinese_caliphate
				}
			}
			modifier = {
				factor = 4
				AND = {
					offmap_china = { offmap_ruler = { religion = sunni } }
					has_global_flag = sunni_chinese_caliphate
				}
			}
		}
	}
	
	option = { #Wane
		if = {
			limit = {
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = sunni
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
			change_variable = { which = "global_chinese_sunnis" value = -2 }
		}
		else = {
			change_variable = { which = "global_chinese_sunnis" value = -1 }
		}
	
		ai_chance = {
			factor = 30
			modifier = {
				factor = 0
				offmap_china = { offmap_ruler = { religion = sunni } }
			}
			modifier = {
				factor = 0
				offmap_china = { offmap_has_like = likes_muslims }
			}
			modifier = {
				factor = 0.1
				1513 = { has_province_modifier = kcc_recent_sunni_mission }
			}
			modifier = {
				factor = 2
				OR = {
					AND = {
						offmap_china = { offmap_has_dislike = likes_indians }
						d_sunni = { holder_scope = { culture_group = indo_aryan_group } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_dravidians }
						d_sunni = { holder_scope = { culture_group = dravidian_group } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_tibetans }
						d_sunni = { holder_scope = { culture_group = tibetan_group } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_germanics }
						d_sunni = { holder_scope = {
							OR = {
								culture_group = north_germanic
								culture_group = central_germanic
								culture_group = west_germanic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_latino_iberians }
						d_sunni = { holder_scope = {
							OR = {
								culture_group = latin
								culture_group = iberian
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_byzantines }
						d_sunni = { holder_scope = { culture_group = byzantine } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_celts }
						d_sunni = { holder_scope = { culture_group = celtic } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_finno_ugrics }
						d_sunni = { holder_scope = {
							OR = {
								culture_group = finno_ugric
								culture_group = magyar
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_altaics }
						d_sunni = { holder_scope = { culture_group = altaic } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_balto_slavics }
						d_sunni = { holder_scope = {
							OR = {
								culture_group = baltic
								culture_group = east_slavic
								culture_group = west_slavic
								culture_group = south_slavic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_arabs }
						d_sunni = { holder_scope = { culture_group = arabic } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_iranians }
						d_sunni = { holder_scope = { culture_group = iranian } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_africans }
						d_sunni = { holder_scope = {
							OR = {
								culture_group = west_african
								culture_group = east_african
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_mesoamericans }
						d_sunni = { holder_scope = { culture_group = mesoamerican } }
					}
				}
			}
			modifier = {
				factor = 2
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = sunni
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
		}
	}
}

# Wax & Wane of Zikri Islam
character_event = {
	id = kccwaxwane.0016
	hide_window = yes
	
	is_triggered_only = yes
	
	has_dlc = "Jade Dragon"
	only_playable = yes
	
	trigger = {
		has_landed_title = e_china_west_governor
	}
	
	after = {
		if = {
			limit = {
				check_variable = { which = "global_chinese_zikris" value = 20 }
				NOT = { has_global_flag = zikri_china_one }
			}
			set_global_flag = zikri_china_one
			set_global_flag = kcc_waxwane_zikris
			any_playable_ruler = { narrative_event = { id = kccspread.0003 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_zikris" value = 40 }
				NOT = { has_global_flag = zikri_china_two }
			}
			set_global_flag = zikri_china_two
			set_global_flag = kcc_waxwane_zikris
			any_playable_ruler = { narrative_event = { id = kccspread.0004 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_zikris" value = 100 }
				NOT = { has_global_flag = zikri_china_three }
			}
			set_global_flag = zikri_china_three
			set_global_flag = kcc_waxwane_zikris
			any_playable_ruler = { narrative_event = { id = kccspread.0005 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_zikris" value = 180 }
				NOT = { has_global_flag = zikri_china_four }
				kcc_nontaoist_majority_trigger = yes
			}
			kcc_drop_other_religion_effect = yes
			set_global_flag = zikri_china_four
			set_global_flag = kcc_waxwane_zikris
			any_playable_ruler = { narrative_event = { id = kccspread.0007 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_zikris" value = 180 }
				NOT = { has_global_flag = zikri_china_four }
			}
			set_global_flag = zikri_china_four
			set_global_flag = kcc_waxwane_zikris
			any_playable_ruler = { narrative_event = { id = kccspread.0006 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_zikris" value = 100 } }
				has_global_flag = zikri_china_three
			}
			clr_global_flag = zikri_china_three
			set_global_flag = kcc_waxwane_zikris
			any_playable_ruler = { narrative_event = { id = kccspread.0008 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_zikris" value = 40 } }
				has_global_flag = zikri_china_two
			}
			clr_global_flag = zikri_china_two
			set_global_flag = kcc_waxwane_zikris
			any_playable_ruler = { narrative_event = { id = kccspread.0009 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_zikris" value = 20 } }
				has_global_flag = zikri_china_one
			}
			clr_global_flag = zikri_china_one
			set_global_flag = kcc_waxwane_zikris
			any_playable_ruler = { narrative_event = { id = kccspread.0010 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_zikris" value = 0 } }
				has_global_flag = zikris_in_china
			}
			clr_global_flag = zikris_in_china
			set_variable = { which = "global_chinese_zikris" value = 0 }
			set_global_flag = kcc_waxwane_zikris
			any_playable_ruler = { narrative_event = { id = kccspread.0011 days = 1 } }
		}
	}
	
	weight_multiplier = {
		days = 17
		modifier = {
			factor = 0
			NOT = { has_global_flag = zikris_in_china }
		}
		modifier = {
			factor = 0
			1513 = {
				OR = {
					has_province_modifier = kcc_china_persecuted_muslims
					has_province_modifier = kcc_china_persecuted_sunnis
				}
			}
		}
		modifier = {
			factor = 2
			offmap_china = { offmap_has_like = likes_muslims }
		}
		modifier = {
			factor = 5
			offmap_china = { offmap_ruler = { religion = zikri } }
			NOR = {
				has_global_flag = zikri_china_two
				has_global_flag = zikri_china_three
				has_global_flag = zikri_china_four
			}
		}
		modifier = {
			factor = 4
			offmap_china = { offmap_ruler = { religion = zikri } }
			NOR = {
				has_global_flag = zikri_china_three
				has_global_flag = zikri_china_four
			}
		}
		modifier = {
			factor = 1.5
			offmap_china = { offmap_ruler = { religion = zikri } }
			NOT = { has_global_flag = zikri_china_four }
		}
		modifier = {
			factor = 0
			offmap_china = { offmap_ruler = { religion = zikri } }
			has_global_flag = zikri_china_four
		}
	}
	
	option = { #No change
	
		ai_chance = {
			factor = 30
		}
	}
	
	option = { #Wax
		if = {
			limit = {
				offmap_china = {
					OR = {
						offmap_ruler = { religion = zikri }
						offmap_china = { offmap_has_like = likes_muslims }
					}
				}
			}
			change_variable = { which = "global_chinese_zikris" value = 2 }
		}
		else = {
			change_variable = { which = "global_chinese_zikris" value = 1 }
		}
		
		ai_chance = {
			factor = 60
			modifier = {
				factor = 1.1
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = zikri
						culture = mongol
					}
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = zikri
						OR = {
							culture = khitan
							culture = tangut
							culture = jurchen
							culture_group = chinese_group
						}
					}
				}
			}
			modifier = {
				factor = 1.2
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = zikri
						OR = {
							culture = khitan
							culture = tangut
							culture = jurchen
						}
					}
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = zikri
						culture_group = chinese_group
					}
				}
			}
			modifier = {
				factor = 1.3
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = zikri
						culture_group = chinese_group
					}
				}
			}
			modifier = {
				factor = 5
				OR = {
					offmap_china = { offmap_has_like = likes_muslims }
					offmap_china = { offmap_ruler = { religion = zikri } }
				}
			}
			modifier = {
				factor = 1.2
				offmap_china = { offmap_ruler = { religion_group = muslim } }
			}
			modifier = {
				factor = 1.5
				AND = {
					offmap_china = { offmap_ruler = { religion = zikri } }
					offmap_china = { offmap_ruler = { culture_group = chinese_group } }
				}
			}
			modifier = {
				factor = 1.5
				AND = {
					offmap_china = { offmap_ruler = { religion = zikri } }
					offmap_china = { has_status = china_golden_age }
				}
			}
			modifier = {
				factor = 0.2
				AND = {
					offmap_china = { offmap_ruler = { religion = zikri } }
					offmap_china = {
						OR = {
							has_status = china_unrest
							has_status = china_famine
							has_status = china_plague
						}
					}
				}
			}
			modifier = {
				factor = 0.01
				AND = {
					offmap_china = { offmap_ruler = { religion = zikri } }
					offmap_china = {
						OR = {
							has_status = china_civil_war
							has_status = china_mongol_invasion
							has_status = china_jurchen_invasion
						}
					}
				}
			}
			modifier = {
				factor = 3
				AND = {
					offmap_china = { offmap_ruler = { NOT = { religion = zikri } } }
					offmap_china = {
						OR = {
							has_status = china_unrest
							has_status = china_civil_war
						}
					}
				}
			}
			modifier = {
				factor = 1.5
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = zikri
					any_realm_province = {
						region = custom_eastern_access
					}
					NOR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
					OR = {
						has_character_modifier = peace_deal_with_china
						has_character_modifier = chinese_imperial_trade_contract
						has_character_modifier = chinese_favored_in_trade
						has_offmap_currency = { offmap = offmap_china value = 1000 }
					}
				}
			}
			modifier = {
				factor = 0.33
				OR = {
					offmap_china = { offmap_ruler = { religion_group = christian } }
					offmap_china = {
						offmap_ruler = {
							religion_group = pagan_group
							has_religion_feature = religion_dogmatic
						}
					}
				}
			}
			modifier = {
				factor = 0.05
				OR = {
					offmap_china = { offmap_ruler = { religion = shiite } }
					offmap_china = { offmap_ruler = { religion = qarmatian } }
					offmap_china = { offmap_ruler = { religion = hurufi } }
				}
			}
		}
	}
	
	option = { #Wane
		if = {
			limit = {
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = zikri
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
			change_variable = { which = "global_chinese_zikris" value = -2 }
		}
		else = {
			change_variable = { which = "global_chinese_zikris" value = -1 }
		}
	
		ai_chance = {
			factor = 30
			modifier = {
				factor = 0
				offmap_china = { offmap_ruler = { religion = zikri } }
			}
			modifier = {
				factor = 0
				offmap_china = { offmap_has_like = likes_muslims }
			}
			modifier = {
				factor = 0.1
				1513 = { has_province_modifier = kcc_recent_zikri_mission }
			}
			modifier = {
				factor = 2
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = zikri
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
		}
	}
}

# Wax & Wane of Shia Islam
character_event = {
	id = kccwaxwane.0017
	hide_window = yes
	
	is_triggered_only = yes
	
	has_dlc = "Jade Dragon"
	only_playable = yes
	
	trigger = {
		has_landed_title = e_china_west_governor
	}
	
	after = {
		if = {
			limit = {
				check_variable = { which = "global_chinese_shiites" value = 20 }
				NOT = { has_global_flag = shiite_china_one }
			}
			set_global_flag = shiite_china_one
			set_global_flag = kcc_waxwane_shiites
			any_playable_ruler = { narrative_event = { id = kccspread.0003 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_shiites" value = 40 }
				NOT = { has_global_flag = shiite_china_two }
			}
			set_global_flag = shiite_china_two
			set_global_flag = kcc_waxwane_shiites
			any_playable_ruler = { narrative_event = { id = kccspread.0004 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_shiites" value = 100 }
				NOT = { has_global_flag = shiite_china_three }
			}
			set_global_flag = shiite_china_three
			set_global_flag = kcc_waxwane_shiites
			any_playable_ruler = { narrative_event = { id = kccspread.0005 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_shiites" value = 180 }
				NOT = { has_global_flag = shiite_china_four }
				kcc_nontaoist_majority_trigger = yes
			}
			kcc_drop_other_religion_effect = yes
			set_global_flag = shiite_china_four
			set_global_flag = kcc_waxwane_shiites
			any_playable_ruler = { narrative_event = { id = kccspread.0007 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_shiites" value = 180 }
				NOT = { has_global_flag = shiite_china_four }
			}
			set_global_flag = shiite_china_four
			set_global_flag = kcc_waxwane_shiites
			any_playable_ruler = { narrative_event = { id = kccspread.0006 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_shiites" value = 100 } }
				has_global_flag = shiite_china_three
			}
			clr_global_flag = shiite_china_three
			set_global_flag = kcc_waxwane_shiites
			any_playable_ruler = { narrative_event = { id = kccspread.0008 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_shiites" value = 40 } }
				has_global_flag = shiite_china_two
			}
			clr_global_flag = shiite_china_two
			set_global_flag = kcc_waxwane_shiites
			any_playable_ruler = { narrative_event = { id = kccspread.0009 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_shiites" value = 20 } }
				has_global_flag = shiite_china_one
			}
			clr_global_flag = shiite_china_one
			set_global_flag = kcc_waxwane_shiites
			any_playable_ruler = { narrative_event = { id = kccspread.0010 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_shiites" value = 0 } }
				has_global_flag = shiites_in_china
			}
			clr_global_flag = shiites_in_china
			set_variable = { which = "global_chinese_shiites" value = 0 }
			set_global_flag = kcc_waxwane_shiites
			any_playable_ruler = { narrative_event = { id = kccspread.0011 days = 1 } }
		}
	}
	
	weight_multiplier = {
		days = 17
		modifier = {
			factor = 0
			NOT = { has_global_flag = shiites_in_china }
		}
		modifier = {
			factor = 0
			1513 = {
				OR = {
					has_province_modifier = kcc_china_persecuted_muslims
					has_province_modifier = kcc_china_persecuted_shiites
				}
			}
		}
		modifier = {
			factor = 2
			offmap_china = { offmap_has_like = likes_muslims }
		}
		modifier = {
			factor = 5
			offmap_china = { offmap_ruler = { religion = shiite } }
			NOR = {
				has_global_flag = shiite_china_two
				has_global_flag = shiite_china_three
				has_global_flag = shiite_china_four
			}
		}
		modifier = {
			factor = 4
			offmap_china = { offmap_ruler = { religion = shiite } }
			NOR = {
				has_global_flag = shiite_china_three
				has_global_flag = shiite_china_four
			}
		}
		modifier = {
			factor = 1.5
			offmap_china = { offmap_ruler = { religion = shiite } }
			NOT = { has_global_flag = shiite_china_four }
		}
		modifier = {
			factor = 0
			offmap_china = { offmap_ruler = { religion = shiite } }
			has_global_flag = shiite_china_four
		}
	}
	
	option = { #No change
	
		ai_chance = {
			factor = 30
		}
	}
	
	option = { #Wax
		if = {
			limit = {
				offmap_china = {
					OR = {
						offmap_ruler = { religion = shiite }
						offmap_china = { offmap_has_like = likes_muslims }
					}
				}
			}
			change_variable = { which = "global_chinese_shiites" value = 2 }
		}
		else = {
			change_variable = { which = "global_chinese_shiites" value = 1 }
		}
		
		ai_chance = {
			factor = 60
			modifier = {
				factor = 1.1
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = shiite
						culture = mongol
					}
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = shiite
						OR = {
							culture = khitan
							culture = tangut
							culture = jurchen
							culture_group = chinese_group
						}
					}
				}
			}
			modifier = {
				factor = 1.2
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = shiite
						OR = {
							culture = khitan
							culture = tangut
							culture = jurchen
						}
					}
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = shiite
						culture_group = chinese_group
					}
				}
			}
			modifier = {
				factor = 1.3
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = shiite
						culture_group = chinese_group
					}
				}
			}
			modifier = {
				factor = 5
				OR = {
					offmap_china = { offmap_has_like = likes_muslims }
					offmap_china = { offmap_ruler = { religion = shiite } }
				}
			}
			modifier = {
				factor = 1.2
				offmap_china = { offmap_ruler = { religion_group = muslim } }
			}
			modifier = {
				factor = 1.5
				AND = {
					offmap_china = { offmap_ruler = { religion = shiite } }
					offmap_china = { offmap_ruler = { culture_group = chinese_group } }
				}
			}
			modifier = {
				factor = 1.5
				AND = {
					offmap_china = { offmap_ruler = { religion = shiite } }
					offmap_china = { has_status = china_golden_age }
				}
			}
			modifier = {
				factor = 0.2
				AND = {
					offmap_china = { offmap_ruler = { religion = shiite } }
					offmap_china = {
						OR = {
							has_status = china_unrest
							has_status = china_famine
							has_status = china_plague
						}
					}
				}
			}
			modifier = {
				factor = 0.01
				AND = {
					offmap_china = { offmap_ruler = { religion = shiite } }
					offmap_china = {
						OR = {
							has_status = china_civil_war
							has_status = china_mongol_invasion
							has_status = china_jurchen_invasion
						}
					}
				}
			}
			modifier = {
				factor = 3
				AND = {
					offmap_china = { offmap_ruler = { NOT = { religion = shiite } } }
					offmap_china = {
						OR = {
							has_status = china_unrest
							has_status = china_civil_war
						}
					}
				}
			}
			modifier = {
				factor = 2
				OR = {
					AND = {
						offmap_china = { offmap_has_like = likes_indians }
						d_shiite = { holder_scope = { culture_group = indo_aryan_group } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_dravidians }
						d_shiite = { holder_scope = { culture_group = dravidian_group } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_tibetans }
						d_shiite = { holder_scope = { culture_group = tibetan_group } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_germanics }
						d_shiite = { holder_scope = {
							OR = {
								culture_group = north_germanic
								culture_group = central_germanic
								culture_group = west_germanic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_latino_iberians }
						d_shiite = { holder_scope = {
							OR = {
								culture_group = latin
								culture_group = iberian
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_byzantines }
						d_shiite = { holder_scope = { culture_group = byzantine } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_celts }
						d_shiite = { holder_scope = { culture_group = celtic } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_finno_ugrics }
						d_shiite = { holder_scope = {
							OR = {
								culture_group = finno_ugric
								culture_group = magyar
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_altaics }
						d_shiite = { holder_scope = { culture_group = altaic } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_balto_slavics }
						d_shiite = { holder_scope = {
							OR = {
								culture_group = baltic
								culture_group = east_slavic
								culture_group = west_slavic
								culture_group = south_slavic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_arabs }
						d_shiite = { holder_scope = { culture_group = arabic } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_iranians }
						d_shiite = { holder_scope = { culture_group = iranian } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_africans }
						d_shiite = { holder_scope = {
							OR = {
								culture_group = west_african
								culture_group = east_african
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_mesoamericans }
						d_shiite = { holder_scope = { culture_group = mesoamerican } }
					}
				}
			}
			modifier = {
				factor = 1.5
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = shiite
					any_realm_province = {
						region = custom_eastern_access
					}
					NOR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
					OR = {
						has_character_modifier = peace_deal_with_china
						has_character_modifier = chinese_imperial_trade_contract
						has_character_modifier = chinese_favored_in_trade
						has_offmap_currency = { offmap = offmap_china value = 1000 }
					}
				}
			}
			modifier = {
				factor = 0.33
				OR = {
					offmap_china = { offmap_ruler = { religion_group = christian } }
					offmap_china = {
						offmap_ruler = {
							religion_group = pagan_group
							has_religion_feature = religion_dogmatic
						}
					}
				}
			}
			modifier = {
				factor = 0.05
				OR = {
					offmap_china = { offmap_ruler = { religion = sunni } }
					offmap_china = { offmap_ruler = { religion = zikri } }
				}
			}
			modifier = {
				factor = 1.33
				AND = {
					offmap_china = { offmap_ruler = { NOT = { religion = shiite } } }
					has_global_flag = shiite_chinese_caliphate
				}
			}
			modifier = {
				factor = 4
				AND = {
					offmap_china = { offmap_ruler = { religion = shiite } }
					has_global_flag = shiite_chinese_caliphate
				}
			}
		}
	}
	
	option = { #Wane
		if = {
			limit = {
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = shiite
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
			change_variable = { which = "global_chinese_shiites" value = -2 }
		}
		else = {
			change_variable = { which = "global_chinese_shiites" value = -1 }
		}
	
		ai_chance = {
			factor = 30
			modifier = {
				factor = 0
				offmap_china = { offmap_ruler = { religion = shiite } }
			}
			modifier = {
				factor = 0
				offmap_china = { offmap_has_like = likes_muslims }
			}
			modifier = {
				factor = 0.1
				1513 = { has_province_modifier = kcc_recent_shiite_mission }
			}
			modifier = {
				factor = 2
				OR = {
					AND = {
						offmap_china = { offmap_has_dislike = likes_indians }
						d_shiite = { holder_scope = { culture_group = indo_aryan_group } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_dravidians }
						d_shiite = { holder_scope = { culture_group = dravidian_group } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_tibetans }
						d_shiite = { holder_scope = { culture_group = tibetan_group } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_germanics }
						d_shiite = { holder_scope = {
							OR = {
								culture_group = north_germanic
								culture_group = central_germanic
								culture_group = west_germanic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_latino_iberians }
						d_shiite = { holder_scope = {
							OR = {
								culture_group = latin
								culture_group = iberian
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_byzantines }
						d_shiite = { holder_scope = { culture_group = byzantine } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_celts }
						d_shiite = { holder_scope = { culture_group = celtic } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_finno_ugrics }
						d_shiite = { holder_scope = {
							OR = {
								culture_group = finno_ugric
								culture_group = magyar
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_altaics }
						d_shiite = { holder_scope = { culture_group = altaic } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_balto_slavics }
						d_shiite = { holder_scope = {
							OR = {
								culture_group = baltic
								culture_group = east_slavic
								culture_group = west_slavic
								culture_group = south_slavic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_arabs }
						d_shiite = { holder_scope = { culture_group = arabic } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_iranians }
						d_shiite = { holder_scope = { culture_group = iranian } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_africans }
						d_shiite = { holder_scope = {
							OR = {
								culture_group = west_african
								culture_group = east_african
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_mesoamericans }
						d_shiite = { holder_scope = { culture_group = mesoamerican } }
					}
				}
			}
			modifier = {
				factor = 2
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = shiite
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
		}
	}
}

# Wax & Wane of qarmatian Islam
character_event = {
	id = kccwaxwane.0018
	hide_window = yes
	
	is_triggered_only = yes
	
	has_dlc = "Jade Dragon"
	only_playable = yes
	
	trigger = {
		has_landed_title = e_china_west_governor
	}
	
	after = {
		if = {
			limit = {
				check_variable = { which = "global_chinese_qarmatians" value = 20 }
				NOT = { has_global_flag = qarmatian_china_one }
			}
			set_global_flag = qarmatian_china_one
			set_global_flag = kcc_waxwane_qarmatian
			any_playable_ruler = { narrative_event = { id = kccspread.0003 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_qarmatians" value = 40 }
				NOT = { has_global_flag = qarmatian_china_two }
			}
			set_global_flag = qarmatian_china_two
			set_global_flag = kcc_waxwane_qarmatian
			any_playable_ruler = { narrative_event = { id = kccspread.0004 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_qarmatians" value = 100 }
				NOT = { has_global_flag = qarmatian_china_three }
			}
			set_global_flag = qarmatian_china_three
			set_global_flag = kcc_waxwane_qarmatian
			any_playable_ruler = { narrative_event = { id = kccspread.0005 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_qarmatians" value = 180 }
				NOT = { has_global_flag = qarmatian_china_four }
				kcc_nontaoist_majority_trigger = yes
			}
			kcc_drop_other_religion_effect = yes
			set_global_flag = qarmatian_china_four
			set_global_flag = kcc_waxwane_qarmatian
			any_playable_ruler = { narrative_event = { id = kccspread.0007 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_qarmatians" value = 180 }
				NOT = { has_global_flag = qarmatian_china_four }
			}
			set_global_flag = qarmatian_china_four
			set_global_flag = kcc_waxwane_qarmatian
			any_playable_ruler = { narrative_event = { id = kccspread.0006 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_qarmatians" value = 100 } }
				has_global_flag = qarmatian_china_three
			}
			clr_global_flag = qarmatian_china_three
			set_global_flag = kcc_waxwane_qarmatian
			any_playable_ruler = { narrative_event = { id = kccspread.0008 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_qarmatians" value = 40 } }
				has_global_flag = qarmatian_china_two
			}
			clr_global_flag = qarmatian_china_two
			set_global_flag = kcc_waxwane_qarmatian
			any_playable_ruler = { narrative_event = { id = kccspread.0009 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_qarmatians" value = 20 } }
				has_global_flag = qarmatian_china_one
			}
			clr_global_flag = qarmatian_china_one
			set_global_flag = kcc_waxwane_qarmatian
			any_playable_ruler = { narrative_event = { id = kccspread.0010 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_qarmatians" value = 0 } }
				has_global_flag = qarmatian_in_china
			}
			clr_global_flag = qarmatian_in_china
			set_variable = { which = "global_chinese_qarmatians" value = 0 }
			set_global_flag = kcc_waxwane_qarmatian
			any_playable_ruler = { narrative_event = { id = kccspread.0011 days = 1 } }
		}
	}
	
	weight_multiplier = {
		days = 17
		modifier = {
			factor = 0
			NOT = { has_global_flag = qarmatian_in_china }
		}
		modifier = {
			factor = 0
			1513 = {
				OR = {
					has_province_modifier = kcc_china_persecuted_muslims
					has_province_modifier = kcc_china_persecuted_shiites
				}
			}
		}
		modifier = {
			factor = 2
			offmap_china = { offmap_has_like = likes_muslims }
		}
		modifier = {
			factor = 5
			offmap_china = { offmap_ruler = { religion = qarmatian } }
			NOR = {
				has_global_flag = qarmatian_china_two
				has_global_flag = qarmatian_china_three
				has_global_flag = qarmatian_china_four
			}
		}
		modifier = {
			factor = 4
			offmap_china = { offmap_ruler = { religion = qarmatian } }
			NOR = {
				has_global_flag = qarmatian_china_three
				has_global_flag = qarmatian_china_four
			}
		}
		modifier = {
			factor = 1.5
			offmap_china = { offmap_ruler = { religion = qarmatian } }
			NOT = { has_global_flag = qarmatian_china_four }
		}
		modifier = {
			factor = 0
			offmap_china = { offmap_ruler = { religion = qarmatian } }
			has_global_flag = qarmatian_china_four
		}
	}
	
	option = { #No change
	
		ai_chance = {
			factor = 30
		}
	}
	
	option = { #Wax
		if = {
			limit = {
				offmap_china = {
					OR = {
						offmap_ruler = { religion = qarmatian }
						offmap_china = { offmap_has_like = likes_muslims }
					}
				}
			}
			change_variable = { which = "global_chinese_qarmatians" value = 2 }
		}
		else = {
			change_variable = { which = "global_chinese_qarmatians" value = 1 }
		}
		
		ai_chance = {
			factor = 60
			modifier = {
				factor = 1.1
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = qarmatian
						culture = mongol
					}
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = qarmatian
						OR = {
							culture = khitan
							culture = tangut
							culture = jurchen
							culture_group = chinese_group
						}
					}
				}
			}
			modifier = {
				factor = 1.2
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = qarmatian
						OR = {
							culture = khitan
							culture = tangut
							culture = jurchen
						}
					}
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = qarmatian
						culture_group = chinese_group
					}
				}
			}
			modifier = {
				factor = 1.3
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = qarmatian
						culture_group = chinese_group
					}
				}
			}
			modifier = {
				factor = 5
				OR = {
					offmap_china = { offmap_has_like = likes_muslims }
					offmap_china = { offmap_ruler = { religion = qarmatian } }
				}
			}
			modifier = {
				factor = 1.2
				offmap_china = { offmap_ruler = { religion_group = muslim } }
			}
			modifier = {
				factor = 1.5
				AND = {
					offmap_china = { offmap_ruler = { religion = qarmatian } }
					offmap_china = { offmap_ruler = { culture_group = chinese_group } }
				}
			}
			modifier = {
				factor = 1.5
				AND = {
					offmap_china = { offmap_ruler = { religion = qarmatian } }
					offmap_china = { has_status = china_golden_age }
				}
			}
			modifier = {
				factor = 0.2
				AND = {
					offmap_china = { offmap_ruler = { religion = qarmatian } }
					offmap_china = {
						OR = {
							has_status = china_unrest
							has_status = china_famine
							has_status = china_plague
						}
					}
				}
			}
			modifier = {
				factor = 0.01
				AND = {
					offmap_china = { offmap_ruler = { religion = qarmatian } }
					offmap_china = {
						OR = {
							has_status = china_civil_war
							has_status = china_mongol_invasion
							has_status = china_jurchen_invasion
						}
					}
				}
			}
			modifier = {
				factor = 3
				AND = {
					offmap_china = { offmap_ruler = { NOT = { religion = qarmatian } } }
					offmap_china = {
						OR = {
							has_status = china_unrest
							has_status = china_civil_war
						}
					}
				}
			}
			modifier = {
				factor = 1.5
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = qarmatian
					any_realm_province = {
						region = custom_eastern_access
					}
					NOR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
					OR = {
						has_character_modifier = peace_deal_with_china
						has_character_modifier = chinese_imperial_trade_contract
						has_character_modifier = chinese_favored_in_trade
						has_offmap_currency = { offmap = offmap_china value = 1000 }
					}
				}
			}
			modifier = {
				factor = 0.33
				OR = {
					offmap_china = { offmap_ruler = { religion_group = christian } }
					offmap_china = {
						offmap_ruler = {
							religion_group = pagan_group
							has_religion_feature = religion_dogmatic
						}
					}
				}
			}
			modifier = {
				factor = 0.05
				OR = {
					offmap_china = { offmap_ruler = { religion = sunni } }
					offmap_china = { offmap_ruler = { religion = zikri } }
				}
			}
		}
	}
	
	option = { #Wane
		if = {
			limit = {
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = qarmatian
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
			change_variable = { which = "global_chinese_qarmatians" value = -2 }
		}
		else = {
			change_variable = { which = "global_chinese_qarmatians" value = -1 }
		}
	
		ai_chance = {
			factor = 30
			modifier = {
				factor = 0
				offmap_china = { offmap_ruler = { religion = qarmatian } }
			}
			modifier = {
				factor = 0
				offmap_china = { offmap_has_like = likes_muslims }
			}
			modifier = {
				factor = 0.1
				1513 = { has_province_modifier = kcc_recent_qarmatian_mission }
			}
			modifier = {
				factor = 2
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = qarmatian
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
		}
	}
}

# Wax & Wane of Hurufi Islam
character_event = {
	id = kccwaxwane.0019
	hide_window = yes
	
	is_triggered_only = yes
	
	has_dlc = "Jade Dragon"
	only_playable = yes
	
	trigger = {
		has_landed_title = e_china_west_governor
	}
	
	after = {
		if = {
			limit = {
				check_variable = { which = "global_chinese_hurufis" value = 20 }
				NOT = { has_global_flag = hurufi_china_one }
			}
			set_global_flag = hurufi_china_one
			set_global_flag = kcc_waxwane_hurufis
			any_playable_ruler = { narrative_event = { id = kccspread.0003 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_hurufis" value = 40 }
				NOT = { has_global_flag = hurufi_china_two }
			}
			set_global_flag = hurufi_china_two
			set_global_flag = kcc_waxwane_hurufis
			any_playable_ruler = { narrative_event = { id = kccspread.0004 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_hurufis" value = 100 }
				NOT = { has_global_flag = hurufi_china_three }
			}
			set_global_flag = hurufi_china_three
			set_global_flag = kcc_waxwane_hurufis
			any_playable_ruler = { narrative_event = { id = kccspread.0005 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_hurufis" value = 180 }
				NOT = { has_global_flag = hurufi_china_four }
				kcc_nontaoist_majority_trigger = yes
			}
			kcc_drop_other_religion_effect = yes
			set_global_flag = hurufi_china_four
			set_global_flag = kcc_waxwane_hurufis
			any_playable_ruler = { narrative_event = { id = kccspread.0007 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_hurufis" value = 180 }
				NOT = { has_global_flag = hurufi_china_four }
			}
			set_global_flag = hurufi_china_four
			set_global_flag = kcc_waxwane_hurufis
			any_playable_ruler = { narrative_event = { id = kccspread.0006 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_hurufis" value = 100 } }
				has_global_flag = hurufi_china_three
			}
			clr_global_flag = hurufi_china_three
			set_global_flag = kcc_waxwane_hurufis
			any_playable_ruler = { narrative_event = { id = kccspread.0008 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_hurufis" value = 40 } }
				has_global_flag = hurufi_china_two
			}
			clr_global_flag = hurufi_china_two
			set_global_flag = kcc_waxwane_hurufis
			any_playable_ruler = { narrative_event = { id = kccspread.0009 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_hurufis" value = 20 } }
				has_global_flag = hurufi_china_one
			}
			clr_global_flag = hurufi_china_one
			set_global_flag = kcc_waxwane_hurufis
			any_playable_ruler = { narrative_event = { id = kccspread.0010 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_hurufis" value = 0 } }
				has_global_flag = hurufis_in_china
			}
			clr_global_flag = hurufis_in_china
			set_variable = { which = "global_chinese_hurufis" value = 0 }
			set_global_flag = kcc_waxwane_hurufis
			any_playable_ruler = { narrative_event = { id = kccspread.0011 days = 1 } }
		}
	}
	
	weight_multiplier = {
		days = 17
		modifier = {
			factor = 0
			NOT = { has_global_flag = hurufis_in_china }
		}
		modifier = {
			factor = 0
			1513 = {
				OR = {
					has_province_modifier = kcc_china_persecuted_muslims
					has_province_modifier = kcc_china_persecuted_shiites
				}
			}
		}
		modifier = {
			factor = 2
			offmap_china = { offmap_has_like = likes_muslims }
		}
		modifier = {
			factor = 5
			offmap_china = { offmap_ruler = { religion = hurufi } }
			NOR = {
				has_global_flag = hurufi_china_two
				has_global_flag = hurufi_china_three
				has_global_flag = hurufi_china_four
			}
		}
		modifier = {
			factor = 4
			offmap_china = { offmap_ruler = { religion = hurufi } }
			NOR = {
				has_global_flag = hurufi_china_three
				has_global_flag = hurufi_china_four
			}
		}
		modifier = {
			factor = 1.5
			offmap_china = { offmap_ruler = { religion = hurufi } }
			NOT = { has_global_flag = hurufi_china_four }
		}
		modifier = {
			factor = 0
			offmap_china = { offmap_ruler = { religion = hurufi } }
			has_global_flag = hurufi_china_four
		}
	}
	
	option = { #No change
	
		ai_chance = {
			factor = 30
		}
	}
	
	option = { #Wax
		if = {
			limit = {
				offmap_china = {
					OR = {
						offmap_ruler = { religion = hurufi }
						offmap_china = { offmap_has_like = likes_muslims }
					}
				}
			}
			change_variable = { which = "global_chinese_hurufis" value = 2 }
		}
		else = {
			change_variable = { which = "global_chinese_hurufis" value = 1 }
		}
		
		ai_chance = {
			factor = 60
			modifier = {
				factor = 1.1
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = hurufi
						culture = mongol
					}
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = hurufi
						OR = {
							culture = khitan
							culture = tangut
							culture = jurchen
							culture_group = chinese_group
						}
					}
				}
			}
			modifier = {
				factor = 1.2
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = hurufi
						OR = {
							culture = khitan
							culture = tangut
							culture = jurchen
						}
					}
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = hurufi
						culture_group = chinese_group
					}
				}
			}
			modifier = {
				factor = 1.3
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = hurufi
						culture_group = chinese_group
					}
				}
			}
			modifier = {
				factor = 5
				OR = {
					offmap_china = { offmap_has_like = likes_muslims }
					offmap_china = { offmap_ruler = { religion = hurufi } }
				}
			}
			modifier = {
				factor = 1.2
				offmap_china = { offmap_ruler = { religion_group = muslim } }
			}
			modifier = {
				factor = 1.5
				AND = {
					offmap_china = { offmap_ruler = { religion = hurufi } }
					offmap_china = { offmap_ruler = { culture_group = chinese_group } }
				}
			}
			modifier = {
				factor = 1.5
				AND = {
					offmap_china = { offmap_ruler = { religion = hurufi } }
					offmap_china = { has_status = china_golden_age }
				}
			}
			modifier = {
				factor = 0.2
				AND = {
					offmap_china = { offmap_ruler = { religion = hurufi } }
					offmap_china = {
						OR = {
							has_status = china_unrest
							has_status = china_famine
							has_status = china_plague
						}
					}
				}
			}
			modifier = {
				factor = 0.01
				AND = {
					offmap_china = { offmap_ruler = { religion = hurufi } }
					offmap_china = {
						OR = {
							has_status = china_civil_war
							has_status = china_mongol_invasion
							has_status = china_jurchen_invasion
						}
					}
				}
			}
			modifier = {
				factor = 3
				AND = {
					offmap_china = { offmap_ruler = { NOT = { religion = hurufi } } }
					offmap_china = {
						OR = {
							has_status = china_unrest
							has_status = china_civil_war
						}
					}
				}
			}
			modifier = {
				factor = 2
				OR = {
					AND = {
						offmap_china = { offmap_has_like = likes_indians }
						d_hurufi = { holder_scope = { culture_group = indo_aryan_group } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_dravidians }
						d_hurufi = { holder_scope = { culture_group = dravidian_group } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_tibetans }
						d_hurufi = { holder_scope = { culture_group = tibetan_group } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_germanics }
						d_hurufi = { holder_scope = {
							OR = {
								culture_group = north_germanic
								culture_group = central_germanic
								culture_group = west_germanic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_latino_iberians }
						d_hurufi = { holder_scope = {
							OR = {
								culture_group = latin
								culture_group = iberian
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_byzantines }
						d_hurufi = { holder_scope = { culture_group = byzantine } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_celts }
						d_hurufi = { holder_scope = { culture_group = celtic } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_finno_ugrics }
						d_hurufi = { holder_scope = {
							OR = {
								culture_group = finno_ugric
								culture_group = magyar
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_altaics }
						d_hurufi = { holder_scope = { culture_group = altaic } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_balto_slavics }
						d_hurufi = { holder_scope = {
							OR = {
								culture_group = baltic
								culture_group = east_slavic
								culture_group = west_slavic
								culture_group = south_slavic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_arabs }
						d_hurufi = { holder_scope = { culture_group = arabic } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_iranians }
						d_hurufi = { holder_scope = { culture_group = iranian } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_africans }
						d_hurufi = { holder_scope = {
							OR = {
								culture_group = west_african
								culture_group = east_african
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_mesoamericans }
						d_hurufi = { holder_scope = { culture_group = mesoamerican } }
					}
				}
			}
			modifier = {
				factor = 1.5
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = hurufi
					any_realm_province = {
						region = custom_eastern_access
					}
					NOR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
					OR = {
						has_character_modifier = peace_deal_with_china
						has_character_modifier = chinese_imperial_trade_contract
						has_character_modifier = chinese_favored_in_trade
						has_offmap_currency = { offmap = offmap_china value = 1000 }
					}
				}
			}
			modifier = {
				factor = 0.33
				OR = {
					offmap_china = { offmap_ruler = { religion_group = christian } }
					offmap_china = {
						offmap_ruler = {
							religion_group = pagan_group
							has_religion_feature = religion_dogmatic
						}
					}
				}
			}
			modifier = {
				factor = 0.05
				OR = {
					offmap_china = { offmap_ruler = { religion = sunni } }
					offmap_china = { offmap_ruler = { religion = zikri } }
				}
			}
			modifier = {
				factor = 1.33
				AND = {
					offmap_china = { offmap_ruler = { NOT = { religion = hurufi } } }
					has_global_flag = hurufi_chinese_sheikhdom 
				}
			}
			modifier = {
				factor = 4
				AND = {
					offmap_china = { offmap_ruler = { religion = hurufi } }
					has_global_flag = hurufi_chinese_sheikhdom 
				}
			}
		}
	}
	
	option = { #Wane
		if = {
			limit = {
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = hurufi
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
			change_variable = { which = "global_chinese_hurufis" value = -2 }
		}
		else = {
			change_variable = { which = "global_chinese_hurufis" value = -1 }
		}
	
		ai_chance = {
			factor = 30
			modifier = {
				factor = 0
				offmap_china = { offmap_ruler = { religion = hurufi } }
			}
			modifier = {
				factor = 0
				offmap_china = { offmap_has_like = likes_muslims }
			}
			modifier = {
				factor = 0.1
				1513 = { has_province_modifier = kcc_recent_hurufi_mission }
			}
			modifier = {
				factor = 2
				OR = {
					AND = {
						offmap_china = { offmap_has_dislike = likes_indians }
						d_hurufi = { holder_scope = { culture_group = indo_aryan_group } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_dravidians }
						d_hurufi = { holder_scope = { culture_group = dravidian_group } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_tibetans }
						d_hurufi = { holder_scope = { culture_group = tibetan_group } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_germanics }
						d_hurufi = { holder_scope = {
							OR = {
								culture_group = north_germanic
								culture_group = central_germanic
								culture_group = west_germanic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_latino_iberians }
						d_hurufi = { holder_scope = {
							OR = {
								culture_group = latin
								culture_group = iberian
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_byzantines }
						d_hurufi = { holder_scope = { culture_group = byzantine } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_celts }
						d_hurufi = { holder_scope = { culture_group = celtic } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_finno_ugrics }
						d_hurufi = { holder_scope = {
							OR = {
								culture_group = finno_ugric
								culture_group = magyar
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_altaics }
						d_hurufi = { holder_scope = { culture_group = altaic } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_balto_slavics }
						d_hurufi = { holder_scope = {
							OR = {
								culture_group = baltic
								culture_group = east_slavic
								culture_group = west_slavic
								culture_group = south_slavic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_arabs }
						d_hurufi = { holder_scope = { culture_group = arabic } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_iranians }
						d_hurufi = { holder_scope = { culture_group = iranian } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_africans }
						d_hurufi = { holder_scope = {
							OR = {
								culture_group = west_african
								culture_group = east_african
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_mesoamericans }
						d_hurufi = { holder_scope = { culture_group = mesoamerican } }
					}
				}
			}
			modifier = {
				factor = 2
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = hurufi
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
		}
	}
}

# Wax & Wane of Ibadi Islam
character_event = {
	id = kccwaxwane.0020
	hide_window = yes
	
	is_triggered_only = yes
	
	has_dlc = "Jade Dragon"
	only_playable = yes
	
	trigger = {
		has_landed_title = e_china_west_governor
	}
	
	after = {
		if = {
			limit = {
				check_variable = { which = "global_chinese_ibadis" value = 20 }
				NOT = { has_global_flag = ibadi_china_one }
			}
			set_global_flag = ibadi_china_one
			set_global_flag = kcc_waxwane_ibadis
			any_playable_ruler = { narrative_event = { id = kccspread.0003 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_ibadis" value = 40 }
				NOT = { has_global_flag = ibadi_china_two }
			}
			set_global_flag = ibadi_china_two
			set_global_flag = kcc_waxwane_ibadis
			any_playable_ruler = { narrative_event = { id = kccspread.0004 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_ibadis" value = 100 }
				NOT = { has_global_flag = ibadi_china_three }
			}
			set_global_flag = ibadi_china_three
			set_global_flag = kcc_waxwane_ibadis
			any_playable_ruler = { narrative_event = { id = kccspread.0005 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_ibadis" value = 180 }
				NOT = { has_global_flag = ibadi_china_four }
				kcc_nontaoist_majority_trigger = yes
			}
			kcc_drop_other_religion_effect = yes
			set_global_flag = ibadi_china_four
			set_global_flag = kcc_waxwane_ibadis
			any_playable_ruler = { narrative_event = { id = kccspread.0007 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_ibadis" value = 180 }
				NOT = { has_global_flag = ibadi_china_four }
			}
			set_global_flag = ibadi_china_four
			set_global_flag = kcc_waxwane_ibadis
			any_playable_ruler = { narrative_event = { id = kccspread.0006 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_ibadis" value = 100 } }
				has_global_flag = ibadi_china_three
			}
			clr_global_flag = ibadi_china_three
			set_global_flag = kcc_waxwane_ibadis
			any_playable_ruler = { narrative_event = { id = kccspread.0008 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_ibadis" value = 40 } }
				has_global_flag = ibadi_china_two
			}
			clr_global_flag = ibadi_china_two
			set_global_flag = kcc_waxwane_ibadis
			any_playable_ruler = { narrative_event = { id = kccspread.0009 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_ibadis" value = 20 } }
				has_global_flag = ibadi_china_one
			}
			clr_global_flag = ibadi_china_one
			set_global_flag = kcc_waxwane_ibadis
			any_playable_ruler = { narrative_event = { id = kccspread.0010 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_ibadis" value = 0 } }
				has_global_flag = ibadis_in_china
			}
			clr_global_flag = ibadis_in_china
			set_variable = { which = "global_chinese_ibadis" value = 0 }
			set_global_flag = kcc_waxwane_ibadis
			any_playable_ruler = { narrative_event = { id = kccspread.0011 days = 1 } }
		}
	}
	
	weight_multiplier = {
		days = 17
		modifier = {
			factor = 0
			NOT = { has_global_flag = ibadis_in_china }
		}
		modifier = {
			factor = 0
			1513 = {
				OR = {
					has_province_modifier = kcc_china_persecuted_muslims
					has_province_modifier = kcc_china_persecuted_ibadis
				}
			}
		}
		modifier = {
			factor = 2
			offmap_china = { offmap_has_like = likes_muslims }
		}
		modifier = {
			factor = 5
			offmap_china = { offmap_ruler = { religion = ibadi } }
			NOR = {
				has_global_flag = ibadi_china_two
				has_global_flag = ibadi_china_three
				has_global_flag = ibadi_china_four
			}
		}
		modifier = {
			factor = 4
			offmap_china = { offmap_ruler = { religion = ibadi } }
			NOR = {
				has_global_flag = ibadi_china_three
				has_global_flag = ibadi_china_four
			}
		}
		modifier = {
			factor = 1.5
			offmap_china = { offmap_ruler = { religion = ibadi } }
			NOT = { has_global_flag = ibadi_china_four }
		}
		modifier = {
			factor = 0
			offmap_china = { offmap_ruler = { religion = ibadi } }
			has_global_flag = ibadi_china_four
		}
	}
	
	option = { #No change
	
		ai_chance = {
			factor = 30
		}
	}
	
	option = { #Wax
		if = {
			limit = {
				offmap_china = {
					OR = {
						offmap_ruler = { religion = ibadi }
						offmap_china = { offmap_has_like = likes_muslims }
					}
				}
			}
			change_variable = { which = "global_chinese_ibadis" value = 2 }
		}
		else = {
			change_variable = { which = "global_chinese_ibadis" value = 1 }
		}
		
		ai_chance = {
			factor = 60
			modifier = {
				factor = 1.1
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = ibadi
						culture = mongol
					}
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = ibadi
						OR = {
							culture = khitan
							culture = tangut
							culture = jurchen
							culture_group = chinese_group
						}
					}
				}
			}
			modifier = {
				factor = 1.2
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = ibadi
						OR = {
							culture = khitan
							culture = tangut
							culture = jurchen
						}
					}
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = ibadi
						culture_group = chinese_group
					}
				}
			}
			modifier = {
				factor = 1.3
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = ibadi
						culture_group = chinese_group
					}
				}
			}
			modifier = {
				factor = 5
				OR = {
					offmap_china = { offmap_has_like = likes_muslims }
					offmap_china = { offmap_ruler = { religion = ibadi } }
				}
			}
			modifier = {
				factor = 1.2
				offmap_china = { offmap_ruler = { religion_group = muslim } }
			}
			modifier = {
				factor = 1.5
				AND = {
					offmap_china = { offmap_ruler = { religion = ibadi } }
					offmap_china = { offmap_ruler = { culture_group = chinese_group } }
				}
			}
			modifier = {
				factor = 1.5
				AND = {
					offmap_china = { offmap_ruler = { religion = ibadi } }
					offmap_china = { has_status = china_golden_age }
				}
			}
			modifier = {
				factor = 0.2
				AND = {
					offmap_china = { offmap_ruler = { religion = ibadi } }
					offmap_china = {
						OR = {
							has_status = china_unrest
							has_status = china_famine
							has_status = china_plague
						}
					}
				}
			}
			modifier = {
				factor = 0.01
				AND = {
					offmap_china = { offmap_ruler = { religion = ibadi } }
					offmap_china = {
						OR = {
							has_status = china_civil_war
							has_status = china_mongol_invasion
							has_status = china_jurchen_invasion
						}
					}
				}
			}
			modifier = {
				factor = 3
				AND = {
					offmap_china = { offmap_ruler = { NOT = { religion = ibadi } } }
					offmap_china = {
						OR = {
							has_status = china_unrest
							has_status = china_civil_war
						}
					}
				}
			}
			modifier = {
				factor = 2
				OR = {
					AND = {
						offmap_china = { offmap_has_like = likes_indians }
						d_ibadi = { holder_scope = { culture_group = indo_aryan_group } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_dravidians }
						d_ibadi = { holder_scope = { culture_group = dravidian_group } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_tibetans }
						d_ibadi = { holder_scope = { culture_group = tibetan_group } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_germanics }
						d_ibadi = { holder_scope = {
							OR = {
								culture_group = north_germanic
								culture_group = central_germanic
								culture_group = west_germanic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_latino_iberians }
						d_ibadi = { holder_scope = {
							OR = {
								culture_group = latin
								culture_group = iberian
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_byzantines }
						d_ibadi = { holder_scope = { culture_group = byzantine } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_celts }
						d_ibadi = { holder_scope = { culture_group = celtic } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_finno_ugrics }
						d_ibadi = { holder_scope = {
							OR = {
								culture_group = finno_ugric
								culture_group = magyar
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_altaics }
						d_ibadi = { holder_scope = { culture_group = altaic } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_balto_slavics }
						d_ibadi = { holder_scope = {
							OR = {
								culture_group = baltic
								culture_group = east_slavic
								culture_group = west_slavic
								culture_group = south_slavic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_arabs }
						d_ibadi = { holder_scope = { culture_group = arabic } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_iranians }
						d_ibadi = { holder_scope = { culture_group = iranian } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_africans }
						d_ibadi = { holder_scope = {
							OR = {
								culture_group = west_african
								culture_group = east_african
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_mesoamericans }
						d_ibadi = { holder_scope = { culture_group = mesoamerican } }
					}
				}
			}
			modifier = {
				factor = 1.5
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = ibadi
					any_realm_province = {
						region = custom_eastern_access
					}
					NOR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
					OR = {
						has_character_modifier = peace_deal_with_china
						has_character_modifier = chinese_imperial_trade_contract
						has_character_modifier = chinese_favored_in_trade
						has_offmap_currency = { offmap = offmap_china value = 1000 }
					}
				}
			}
			modifier = {
				factor = 0.33
				OR = {
					offmap_china = { offmap_ruler = { religion_group = christian } }
					offmap_china = {
						offmap_ruler = {
							religion_group = pagan_group
							has_religion_feature = religion_dogmatic
						}
					}
				}
			}
			modifier = {
				factor = 1.33
				AND = {
					offmap_china = { offmap_ruler = { NOT = { religion = ibadi } } }
					has_global_flag = ibadi_chinese_caliphate
				}
			}
			modifier = {
				factor = 4
				AND = {
					offmap_china = { offmap_ruler = { religion = ibadi } }
					has_global_flag = ibadi_chinese_caliphate
				}
			}
		}
	}
	
	option = { #Wane
		if = {
			limit = {
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = ibadi
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
			change_variable = { which = "global_chinese_ibadis" value = -2 }
		}
		else = {
			change_variable = { which = "global_chinese_ibadis" value = -1 }
		}
	
		ai_chance = {
			factor = 30
			modifier = {
				factor = 0
				offmap_china = { offmap_ruler = { religion = ibadi } }
			}
			modifier = {
				factor = 0
				offmap_china = { offmap_has_like = likes_muslims }
			}
			modifier = {
				factor = 0.1
				1513 = { has_province_modifier = kcc_recent_ibadi_mission }
			}
			modifier = {
				factor = 2
				OR = {
					AND = {
						offmap_china = { offmap_has_dislike = likes_indians }
						d_ibadi = { holder_scope = { culture_group = indo_aryan_group } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_dravidians }
						d_ibadi = { holder_scope = { culture_group = dravidian_group } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_tibetans }
						d_ibadi = { holder_scope = { culture_group = tibetan_group } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_germanics }
						d_ibadi = { holder_scope = {
							OR = {
								culture_group = north_germanic
								culture_group = central_germanic
								culture_group = west_germanic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_latino_iberians }
						d_ibadi = { holder_scope = {
							OR = {
								culture_group = latin
								culture_group = iberian
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_byzantines }
						d_ibadi = { holder_scope = { culture_group = byzantine } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_celts }
						d_ibadi = { holder_scope = { culture_group = celtic } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_finno_ugrics }
						d_ibadi = { holder_scope = {
							OR = {
								culture_group = finno_ugric
								culture_group = magyar
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_altaics }
						d_ibadi = { holder_scope = { culture_group = altaic } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_balto_slavics }
						d_ibadi = { holder_scope = {
							OR = {
								culture_group = baltic
								culture_group = east_slavic
								culture_group = west_slavic
								culture_group = south_slavic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_arabs }
						d_ibadi = { holder_scope = { culture_group = arabic } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_iranians }
						d_ibadi = { holder_scope = { culture_group = iranian } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_africans }
						d_ibadi = { holder_scope = {
							OR = {
								culture_group = west_african
								culture_group = east_african
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_mesoamericans }
						d_ibadi = { holder_scope = { culture_group = mesoamerican } }
					}
				}
			}
			modifier = {
				factor = 2
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = ibadi
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
		}
	}
}

# Wax & Wane of Kharijite Islam
character_event = {
	id = kccwaxwane.0021
	hide_window = yes
	
	is_triggered_only = yes
	
	has_dlc = "Jade Dragon"
	only_playable = yes
	
	trigger = {
		has_landed_title = e_china_west_governor
	}
	
	after = {
		if = {
			limit = {
				check_variable = { which = "global_chinese_kharijites" value = 20 }
				NOT = { has_global_flag = kharijite_china_one }
			}
			set_global_flag = kharijite_china_one
			set_global_flag = kcc_waxwane_kharijites
			any_playable_ruler = { narrative_event = { id = kccspread.0003 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_kharijites" value = 40 }
				NOT = { has_global_flag = kharijite_china_two }
			}
			set_global_flag = kharijite_china_two
			set_global_flag = kcc_waxwane_kharijites
			any_playable_ruler = { narrative_event = { id = kccspread.0004 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_kharijites" value = 100 }
				NOT = { has_global_flag = kharijite_china_three }
			}
			set_global_flag = kharijite_china_three
			set_global_flag = kcc_waxwane_kharijites
			any_playable_ruler = { narrative_event = { id = kccspread.0005 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_kharijites" value = 180 }
				NOT = { has_global_flag = kharijite_china_four }
				kcc_nontaoist_majority_trigger = yes
			}
			kcc_drop_other_religion_effect = yes
			set_global_flag = kharijite_china_four
			set_global_flag = kcc_waxwane_kharijites
			any_playable_ruler = { narrative_event = { id = kccspread.0007 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_kharijites" value = 180 }
				NOT = { has_global_flag = kharijite_china_four }
			}
			set_global_flag = kharijite_china_four
			set_global_flag = kcc_waxwane_kharijites
			any_playable_ruler = { narrative_event = { id = kccspread.0006 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_kharijites" value = 100 } }
				has_global_flag = kharijite_china_three
			}
			clr_global_flag = kharijite_china_three
			set_global_flag = kcc_waxwane_kharijites
			any_playable_ruler = { narrative_event = { id = kccspread.0008 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_kharijites" value = 40 } }
				has_global_flag = kharijite_china_two
			}
			clr_global_flag = kharijite_china_two
			set_global_flag = kcc_waxwane_kharijites
			any_playable_ruler = { narrative_event = { id = kccspread.0009 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_kharijites" value = 20 } }
				has_global_flag = kharijite_china_one
			}
			clr_global_flag = kharijite_china_one
			set_global_flag = kcc_waxwane_kharijites
			any_playable_ruler = { narrative_event = { id = kccspread.0010 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_kharijites" value = 0 } }
				has_global_flag = kharijites_in_china
			}
			clr_global_flag = kharijites_in_china
			set_variable = { which = "global_chinese_kharijites" value = 0 }
			set_global_flag = kcc_waxwane_kharijites
			any_playable_ruler = { narrative_event = { id = kccspread.0011 days = 1 } }
		}
	}
	
	weight_multiplier = {
		days = 17
		modifier = {
			factor = 0
			NOT = { has_global_flag = kharijites_in_china }
		}
		modifier = {
			factor = 0
			1513 = {
				OR = {
					has_province_modifier = kcc_china_persecuted_muslims
					has_province_modifier = kcc_china_persecuted_ibadis
				}
			}
		}
		modifier = {
			factor = 2
			offmap_china = { offmap_has_like = likes_muslims }
		}
		modifier = {
			factor = 5
			offmap_china = { offmap_ruler = { religion = kharijite } }
			NOR = {
				has_global_flag = kharijite_china_two
				has_global_flag = kharijite_china_three
				has_global_flag = kharijite_china_four
			}
		}
		modifier = {
			factor = 4
			offmap_china = { offmap_ruler = { religion = kharijite } }
			NOR = {
				has_global_flag = kharijite_china_three
				has_global_flag = kharijite_china_four
			}
		}
		modifier = {
			factor = 1.5
			offmap_china = { offmap_ruler = { religion = kharijite } }
			NOT = { has_global_flag = kharijite_china_four }
		}
		modifier = {
			factor = 0
			offmap_china = { offmap_ruler = { religion = kharijite } }
			has_global_flag = kharijite_china_four
		}
	}
	
	option = { #No change
	
		ai_chance = {
			factor = 30
		}
	}
	
	option = { #Wax
		if = {
			limit = {
				offmap_china = {
					OR = {
						offmap_ruler = { religion = kharijite }
						offmap_china = { offmap_has_like = likes_muslims }
					}
				}
			}
			change_variable = { which = "global_chinese_kharijites" value = 2 }
		}
		else = {
			change_variable = { which = "global_chinese_kharijites" value = 1 }
		}
		
		ai_chance = {
			factor = 60
			modifier = {
				factor = 1.1
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = kharijite
						culture = mongol
					}
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = kharijite
						OR = {
							culture = khitan
							culture = tangut
							culture = jurchen
							culture_group = chinese_group
						}
					}
				}
			}
			modifier = {
				factor = 1.2
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = kharijite
						OR = {
							culture = khitan
							culture = tangut
							culture = jurchen
						}
					}
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = kharijite
						culture_group = chinese_group
					}
				}
			}
			modifier = {
				factor = 1.3
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = kharijite
						culture_group = chinese_group
					}
				}
			}
			modifier = {
				factor = 5
				OR = {
					offmap_china = { offmap_has_like = likes_muslims }
					offmap_china = { offmap_ruler = { religion = kharijite } }
				}
			}
			modifier = {
				factor = 1.2
				offmap_china = { offmap_ruler = { religion_group = muslim } }
			}
			modifier = {
				factor = 1.5
				AND = {
					offmap_china = { offmap_ruler = { religion = kharijite } }
					offmap_china = { offmap_ruler = { culture_group = chinese_group } }
				}
			}
			modifier = {
				factor = 1.5
				AND = {
					offmap_china = { offmap_ruler = { religion = kharijite } }
					offmap_china = { has_status = china_golden_age }
				}
			}
			modifier = {
				factor = 0.2
				AND = {
					offmap_china = { offmap_ruler = { religion = kharijite } }
					offmap_china = {
						OR = {
							has_status = china_unrest
							has_status = china_famine
							has_status = china_plague
						}
					}
				}
			}
			modifier = {
				factor = 0.01
				AND = {
					offmap_china = { offmap_ruler = { religion = kharijite } }
					offmap_china = {
						OR = {
							has_status = china_civil_war
							has_status = china_mongol_invasion
							has_status = china_jurchen_invasion
						}
					}
				}
			}
			modifier = {
				factor = 3
				AND = {
					offmap_china = { offmap_ruler = { NOT = { religion = kharijite } } }
					offmap_china = {
						OR = {
							has_status = china_unrest
							has_status = china_civil_war
						}
					}
				}
			}
			modifier = {
				factor = 2
				OR = {
					AND = {
						offmap_china = { offmap_has_like = likes_indians }
						d_kharijite = { holder_scope = { culture_group = indo_aryan_group } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_dravidians }
						d_kharijite = { holder_scope = { culture_group = dravidian_group } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_tibetans }
						d_kharijite = { holder_scope = { culture_group = tibetan_group } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_germanics }
						d_kharijite = { holder_scope = {
							OR = {
								culture_group = north_germanic
								culture_group = central_germanic
								culture_group = west_germanic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_latino_iberians }
						d_kharijite = { holder_scope = {
							OR = {
								culture_group = latin
								culture_group = iberian
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_byzantines }
						d_kharijite = { holder_scope = { culture_group = byzantine } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_celts }
						d_kharijite = { holder_scope = { culture_group = celtic } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_finno_ugrics }
						d_kharijite = { holder_scope = {
							OR = {
								culture_group = finno_ugric
								culture_group = magyar
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_altaics }
						d_kharijite = { holder_scope = { culture_group = altaic } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_balto_slavics }
						d_kharijite = { holder_scope = {
							OR = {
								culture_group = baltic
								culture_group = east_slavic
								culture_group = west_slavic
								culture_group = south_slavic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_arabs }
						d_kharijite = { holder_scope = { culture_group = arabic } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_iranians }
						d_kharijite = { holder_scope = { culture_group = iranian } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_africans }
						d_kharijite = { holder_scope = {
							OR = {
								culture_group = west_african
								culture_group = east_african
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_mesoamericans }
						d_kharijite = { holder_scope = { culture_group = mesoamerican } }
					}
				}
			}
			modifier = {
				factor = 1.5
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = kharijite
					any_realm_province = {
						region = custom_eastern_access
					}
					NOR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
					OR = {
						has_character_modifier = peace_deal_with_china
						has_character_modifier = chinese_imperial_trade_contract
						has_character_modifier = chinese_favored_in_trade
						has_offmap_currency = { offmap = offmap_china value = 1000 }
					}
				}
			}
			modifier = {
				factor = 0.33
				OR = {
					offmap_china = { offmap_ruler = { religion_group = christian } }
					offmap_china = {
						offmap_ruler = {
							religion_group = pagan_group
							has_religion_feature = religion_dogmatic
						}
					}
				}
			}
			modifier = {
				factor = 1.33
				AND = {
					offmap_china = { offmap_ruler = { NOT = { religion = kharijite } } }
					has_global_flag = kharijite_chinese_caliphate
				}
			}
			modifier = {
				factor = 4
				AND = {
					offmap_china = { offmap_ruler = { religion = kharijite } }
					has_global_flag = kharijite_chinese_caliphate
				}
			}
		}
	}
	
	option = { #Wane
		if = {
			limit = {
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = kharijite
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
			change_variable = { which = "global_chinese_kharijites" value = -2 }
		}
		else = {
			change_variable = { which = "global_chinese_kharijites" value = -1 }
		}
	
		ai_chance = {
			factor = 30
			modifier = {
				factor = 0
				offmap_china = { offmap_ruler = { religion = kharijite } }
			}
			modifier = {
				factor = 0
				offmap_china = { offmap_has_like = likes_muslims }
			}
			modifier = {
				factor = 0.1
				1513 = { has_province_modifier = kcc_recent_kharijite_mission }
			}
			modifier = {
				factor = 2
				OR = {
					AND = {
						offmap_china = { offmap_has_dislike = likes_indians }
						d_kharijite = { holder_scope = { culture_group = indo_aryan_group } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_dravidians }
						d_kharijite = { holder_scope = { culture_group = dravidian_group } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_tibetans }
						d_kharijite = { holder_scope = { culture_group = tibetan_group } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_germanics }
						d_kharijite = { holder_scope = {
							OR = {
								culture_group = north_germanic
								culture_group = central_germanic
								culture_group = west_germanic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_latino_iberians }
						d_kharijite = { holder_scope = {
							OR = {
								culture_group = latin
								culture_group = iberian
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_byzantines }
						d_kharijite = { holder_scope = { culture_group = byzantine } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_celts }
						d_kharijite = { holder_scope = { culture_group = celtic } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_finno_ugrics }
						d_kharijite = { holder_scope = {
							OR = {
								culture_group = finno_ugric
								culture_group = magyar
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_altaics }
						d_kharijite = { holder_scope = { culture_group = altaic } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_balto_slavics }
						d_kharijite = { holder_scope = {
							OR = {
								culture_group = baltic
								culture_group = east_slavic
								culture_group = west_slavic
								culture_group = south_slavic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_arabs }
						d_kharijite = { holder_scope = { culture_group = arabic } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_iranians }
						d_kharijite = { holder_scope = { culture_group = iranian } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_africans }
						d_kharijite = { holder_scope = {
							OR = {
								culture_group = west_african
								culture_group = east_african
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_mesoamericans }
						d_kharijite = { holder_scope = { culture_group = mesoamerican } }
					}
				}
			}
			modifier = {
				factor = 2
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = kharijite
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
		}
	}
}

# Wax & Wane of Zoroastrianism
character_event = {
	id = kccwaxwane.0022
	hide_window = yes
	
	is_triggered_only = yes
	
	has_dlc = "Jade Dragon"
	only_playable = yes
	
	trigger = {
		has_landed_title = e_china_west_governor
	}
	
	after = {
		if = {
			limit = {
				check_variable = { which = "global_chinese_zoroastrians" value = 20 }
				NOT = { has_global_flag = zoroastrian_china_one }
			}
			set_global_flag = zoroastrian_china_one
			set_global_flag = kcc_waxwane_zoroastrians
			any_playable_ruler = { narrative_event = { id = kccspread.0003 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_zoroastrians" value = 40 }
				NOT = { has_global_flag = zoroastrian_china_two }
			}
			set_global_flag = zoroastrian_china_two
			set_global_flag = kcc_waxwane_zoroastrians
			any_playable_ruler = { narrative_event = { id = kccspread.0004 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_zoroastrians" value = 100 }
				NOT = { has_global_flag = zoroastrian_china_three }
			}
			set_global_flag = zoroastrian_china_three
			set_global_flag = kcc_waxwane_zoroastrians
			any_playable_ruler = { narrative_event = { id = kccspread.0005 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_zoroastrians" value = 180 }
				NOT = { has_global_flag = zoroastrian_china_four }
				kcc_nontaoist_majority_trigger = yes
			}
			kcc_drop_other_religion_effect = yes
			set_global_flag = zoroastrian_china_four
			set_global_flag = kcc_waxwane_zoroastrians
			any_playable_ruler = { narrative_event = { id = kccspread.0007 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_zoroastrians" value = 180 }
				NOT = { has_global_flag = zoroastrian_china_four }
			}
			set_global_flag = zoroastrian_china_four
			set_global_flag = kcc_waxwane_zoroastrians
			any_playable_ruler = { narrative_event = { id = kccspread.0006 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_zoroastrians" value = 100 } }
				has_global_flag = zoroastrian_china_three
			}
			clr_global_flag = zoroastrian_china_three
			set_global_flag = kcc_waxwane_zoroastrians
			any_playable_ruler = { narrative_event = { id = kccspread.0008 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_zoroastrians" value = 40 } }
				has_global_flag = zoroastrian_china_two
			}
			clr_global_flag = zoroastrian_china_two
			set_global_flag = kcc_waxwane_zoroastrians
			any_playable_ruler = { narrative_event = { id = kccspread.0009 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_zoroastrians" value = 20 } }
				has_global_flag = zoroastrian_china_one
			}
			clr_global_flag = zoroastrian_china_one
			set_global_flag = kcc_waxwane_zoroastrians
			any_playable_ruler = { narrative_event = { id = kccspread.0010 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_zoroastrians" value = 0 } }
				has_global_flag = zoroastrians_in_china
			}
			clr_global_flag = zoroastrians_in_china
			set_variable = { which = "global_chinese_zoroastrians" value = 0 }
			set_global_flag = kcc_waxwane_zoroastrians
			any_playable_ruler = { narrative_event = { id = kccspread.0011 days = 1 } }
		}
	}
	
	weight_multiplier = {
		days = 17
		modifier = {
			factor = 0
			NOT = { has_global_flag = zoroastrians_in_china }
		}
		modifier = {
			factor = 0
			1513 = {
				OR = {
					has_province_modifier = kcc_china_persecuted_mazdans
					has_province_modifier = kcc_china_persecuted_zoroastrians
				}
			}
		}
		modifier = {
			factor = 2
			offmap_china = { offmap_has_like = likes_zoroastrians }
		}
		modifier = {
			factor = 5
			offmap_china = { offmap_ruler = { religion = zoroastrian } }
			NOR = {
				has_global_flag = zoroastrian_china_two
				has_global_flag = zoroastrian_china_three
				has_global_flag = zoroastrian_china_four
			}
		}
		modifier = {
			factor = 4
			offmap_china = { offmap_ruler = { religion = zoroastrian } }
			NOR = {
				has_global_flag = zoroastrian_china_three
				has_global_flag = zoroastrian_china_four
			}
		}
		modifier = {
			factor = 1.5
			offmap_china = { offmap_ruler = { religion = zoroastrian } }
			NOT = { has_global_flag = zoroastrian_china_four }
		}
		modifier = {
			factor = 0
			offmap_china = { offmap_ruler = { religion = zoroastrian } }
			has_global_flag = zoroastrian_china_four
		}
	}
	
	option = { #No change
	
		ai_chance = {
			factor = 30
		}
	}
	
	option = { #Wax
		if = {
			limit = {
				offmap_china = {
					OR = {
						offmap_ruler = { religion = zoroastrian }
						offmap_china = { offmap_has_like = likes_zoroastrians }
					}
				}
			}
			change_variable = { which = "global_chinese_zoroastrians" value = 2 }
		}
		else = {
			change_variable = { which = "global_chinese_zoroastrians" value = 1 }
		}
		
		ai_chance = {
			factor = 60
			modifier = {
				factor = 1.1
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = zoroastrian
						culture = mongol
					}
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = zoroastrian
						OR = {
							culture = khitan
							culture = tangut
							culture = jurchen
							culture_group = chinese_group
						}
					}
				}
			}
			modifier = {
				factor = 1.2
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = zoroastrian
						OR = {
							culture = khitan
							culture = tangut
							culture = jurchen
						}
					}
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = zoroastrian
						culture_group = chinese_group
					}
				}
			}
			modifier = {
				factor = 1.3
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = zoroastrian
						culture_group = chinese_group
					}
				}
			}
			modifier = {
				factor = 5
				OR = {
					offmap_china = { offmap_has_like = likes_zoroastrians }
					offmap_china = { offmap_ruler = { religion = zoroastrian } }
				}
			}
			modifier = {
				factor = 1.5
				AND = {
					offmap_china = { offmap_ruler = { religion = zoroastrian } }
					offmap_china = { offmap_ruler = { culture_group = chinese_group } }
				}
			}
			modifier = {
				factor = 1.5
				AND = {
					offmap_china = { offmap_ruler = { religion = zoroastrian } }
					offmap_china = { has_status = china_golden_age }
				}
			}
			modifier = {
				factor = 0.2
				AND = {
					offmap_china = { offmap_ruler = { religion = zoroastrian } }
					offmap_china = {
						OR = {
							has_status = china_unrest
							has_status = china_famine
							has_status = china_plague
						}
					}
				}
			}
			modifier = {
				factor = 0.01
				AND = {
					offmap_china = { offmap_ruler = { religion = zoroastrian } }
					offmap_china = {
						OR = {
							has_status = china_civil_war
							has_status = china_mongol_invasion
							has_status = china_jurchen_invasion
						}
					}
				}
			}
			modifier = {
				factor = 3
				AND = {
					offmap_china = { offmap_ruler = { NOT = { religion = zoroastrian } } }
					offmap_china = {
						OR = {
							has_status = china_unrest
							has_status = china_civil_war
						}
					}
				}
			}
			modifier = {
				factor = 2
				OR = {
					AND = {
						offmap_china = { offmap_has_like = likes_indians }
						d_zoroastrian = { holder_scope = { culture_group = indo_aryan_group } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_dravidians }
						d_zoroastrian = { holder_scope = { culture_group = dravidian_group } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_tibetans }
						d_zoroastrian = { holder_scope = { culture_group = tibetan_group } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_germanics }
						d_zoroastrian = { holder_scope = {
							OR = {
								culture_group = north_germanic
								culture_group = central_germanic
								culture_group = west_germanic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_latino_iberians }
						d_zoroastrian = { holder_scope = {
							OR = {
								culture_group = latin
								culture_group = iberian
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_byzantines }
						d_zoroastrian = { holder_scope = { culture_group = byzantine } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_celts }
						d_zoroastrian = { holder_scope = { culture_group = celtic } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_finno_ugrics }
						d_zoroastrian = { holder_scope = {
							OR = {
								culture_group = finno_ugric
								culture_group = magyar
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_altaics }
						d_zoroastrian = { holder_scope = { culture_group = altaic } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_balto_slavics }
						d_zoroastrian = { holder_scope = {
							OR = {
								culture_group = baltic
								culture_group = east_slavic
								culture_group = west_slavic
								culture_group = south_slavic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_arabs }
						d_zoroastrian = { holder_scope = { culture_group = arabic } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_iranians }
						d_zoroastrian = { holder_scope = { culture_group = iranian } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_africans }
						d_zoroastrian = { holder_scope = {
							OR = {
								culture_group = west_african
								culture_group = east_african
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_mesoamericans }
						d_zoroastrian = { holder_scope = { culture_group = mesoamerican } }
					}
				}
			}
			modifier = {
				factor = 1.5
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = zoroastrian
					any_realm_province = {
						region = custom_eastern_access
					}
					NOR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
					OR = {
						has_character_modifier = peace_deal_with_china
						has_character_modifier = chinese_imperial_trade_contract
						has_character_modifier = chinese_favored_in_trade
						has_offmap_currency = { offmap = offmap_china value = 1000 }
					}
				}
			}
			modifier = {
				factor = 0.33
				offmap_china = {
					offmap_ruler = {
						religion_group = pagan_group
						has_religion_feature = religion_dogmatic
					}
				}
			}
			modifier = {
				factor = 1.33
				AND = {
					offmap_china = { offmap_ruler = { NOT = { religion = zoroastrian } } }
					has_global_flag = chinese_saoshyant
				}
			}
			modifier = {
				factor = 4
				AND = {
					offmap_china = { offmap_ruler = { religion = zoroastrian } }
					has_global_flag = chinese_saoshyant
				}
			}
		}
	}
	
	option = { #Wane
		if = {
			limit = {
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = zoroastrian
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
			change_variable = { which = "global_chinese_zoroastrians" value = -2 }
		}
		else = {
			change_variable = { which = "global_chinese_zoroastrians" value = -1 }
		}
	
		ai_chance = {
			factor = 30
			modifier = {
				factor = 0
				offmap_china = { offmap_ruler = { religion = zoroastrian } }
			}
			modifier = {
				factor = 0
				offmap_china = { offmap_has_like = likes_zoroastrians }
			}
			modifier = {
				factor = 0.1
				1513 = { has_province_modifier = kcc_recent_zoroastrian_mission }
			}
			modifier = {
				factor = 2
				OR = {
					AND = {
						offmap_china = { offmap_has_dislike = likes_indians }
						d_zoroastrian = { holder_scope = { culture_group = indo_aryan_group } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_dravidians }
						d_zoroastrian = { holder_scope = { culture_group = dravidian_group } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_tibetans }
						d_zoroastrian = { holder_scope = { culture_group = tibetan_group } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_germanics }
						d_zoroastrian = { holder_scope = {
							OR = {
								culture_group = north_germanic
								culture_group = central_germanic
								culture_group = west_germanic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_latino_iberians }
						d_zoroastrian = { holder_scope = {
							OR = {
								culture_group = latin
								culture_group = iberian
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_byzantines }
						d_zoroastrian = { holder_scope = { culture_group = byzantine } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_celts }
						d_zoroastrian = { holder_scope = { culture_group = celtic } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_finno_ugrics }
						d_zoroastrian = { holder_scope = {
							OR = {
								culture_group = finno_ugric
								culture_group = magyar
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_altaics }
						d_zoroastrian = { holder_scope = { culture_group = altaic } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_balto_slavics }
						d_zoroastrian = { holder_scope = {
							OR = {
								culture_group = baltic
								culture_group = east_slavic
								culture_group = west_slavic
								culture_group = south_slavic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_arabs }
						d_zoroastrian = { holder_scope = { culture_group = arabic } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_iranians }
						d_zoroastrian = { holder_scope = { culture_group = iranian } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_africans }
						d_zoroastrian = { holder_scope = {
							OR = {
								culture_group = west_african
								culture_group = east_african
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_mesoamericans }
						d_zoroastrian = { holder_scope = { culture_group = mesoamerican } }
					}
				}
			}
			modifier = {
				factor = 2
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = zoroastrian
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
		}
	}
}

# Wax & Wane of Mazdakism
character_event = {
	id = kccwaxwane.0023
	hide_window = yes
	
	is_triggered_only = yes
	
	has_dlc = "Jade Dragon"
	only_playable = yes
	
	trigger = {
		has_landed_title = e_china_west_governor
	}
	
	after = {
		if = {
			limit = {
				check_variable = { which = "global_chinese_mazdakis" value = 20 }
				NOT = { has_global_flag = mazdaki_china_one }
			}
			set_global_flag = mazdaki_china_one
			set_global_flag = kcc_waxwane_mazdakis
			any_playable_ruler = { narrative_event = { id = kccspread.0003 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_mazdakis" value = 40 }
				NOT = { has_global_flag = mazdaki_china_two }
			}
			set_global_flag = mazdaki_china_two
			set_global_flag = kcc_waxwane_mazdakis
			any_playable_ruler = { narrative_event = { id = kccspread.0004 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_mazdakis" value = 100 }
				NOT = { has_global_flag = mazdaki_china_three }
			}
			set_global_flag = mazdaki_china_three
			set_global_flag = kcc_waxwane_mazdakis
			any_playable_ruler = { narrative_event = { id = kccspread.0005 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_mazdakis" value = 180 }
				NOT = { has_global_flag = mazdaki_china_four }
				kcc_nontaoist_majority_trigger = yes
			}
			kcc_drop_other_religion_effect = yes
			set_global_flag = mazdaki_china_four
			set_global_flag = kcc_waxwane_mazdakis
			any_playable_ruler = { narrative_event = { id = kccspread.0007 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_mazdakis" value = 180 }
				NOT = { has_global_flag = mazdaki_china_four }
			}
			set_global_flag = mazdaki_china_four
			set_global_flag = kcc_waxwane_mazdakis
			any_playable_ruler = { narrative_event = { id = kccspread.0006 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_mazdakis" value = 100 } }
				has_global_flag = mazdaki_china_three
			}
			clr_global_flag = mazdaki_china_three
			set_global_flag = kcc_waxwane_mazdakis
			any_playable_ruler = { narrative_event = { id = kccspread.0008 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_mazdakis" value = 40 } }
				has_global_flag = mazdaki_china_two
			}
			clr_global_flag = mazdaki_china_two
			set_global_flag = kcc_waxwane_mazdakis
			any_playable_ruler = { narrative_event = { id = kccspread.0009 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_mazdakis" value = 20 } }
				has_global_flag = mazdaki_china_one
			}
			clr_global_flag = mazdaki_china_one
			set_global_flag = kcc_waxwane_mazdakis
			any_playable_ruler = { narrative_event = { id = kccspread.0010 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_mazdakis" value = 0 } }
				has_global_flag = mazdakis_in_china
			}
			clr_global_flag = mazdakis_in_china
			set_variable = { which = "global_chinese_mazdakis" value = 0 }
			set_global_flag = kcc_waxwane_mazdakis
			any_playable_ruler = { narrative_event = { id = kccspread.0011 days = 1 } }
		}
	}
	
	weight_multiplier = {
		days = 17
		modifier = {
			factor = 0
			NOT = { has_global_flag = mazdakis_in_china }
		}
		modifier = {
			factor = 0
			1513 = {
				OR = {
					has_province_modifier = kcc_china_persecuted_mazdans
					has_province_modifier = kcc_zoro_china_persecuted_mazdans
					has_province_modifier = kcc_china_persecuted_mazdakis
				}
			}
		}
		modifier = {
			factor = 2
			offmap_china = { offmap_has_like = likes_mazdakis }
		}
		modifier = {
			factor = 5
			offmap_china = { offmap_ruler = { religion = mazdaki } }
			NOR = {
				has_global_flag = mazdaki_china_two
				has_global_flag = mazdaki_china_three
				has_global_flag = mazdaki_china_four
			}
		}
		modifier = {
			factor = 4
			offmap_china = { offmap_ruler = { religion = mazdaki } }
			NOR = {
				has_global_flag = mazdaki_china_three
				has_global_flag = mazdaki_china_four
			}
		}
		modifier = {
			factor = 1.5
			offmap_china = { offmap_ruler = { religion = mazdaki } }
			NOT = { has_global_flag = mazdaki_china_four }
		}
		modifier = {
			factor = 0
			offmap_china = { offmap_ruler = { religion = mazdaki } }
			has_global_flag = mazdaki_china_four
		}
		modifier = {
			factor = 1.33
			offmap_china = { offmap_ruler = { is_female = yes } }
		}
	}
	
	option = { #No change
	
		ai_chance = {
			factor = 30
		}
	}
	
	option = { #Wax
		if = {
			limit = {
				offmap_china = {
					OR = {
						offmap_ruler = { religion = mazdaki }
						offmap_china = { offmap_has_like = likes_mazdakis }
					}
				}
			}
			change_variable = { which = "global_chinese_mazdakis" value = 2 }
		}
		else = {
			change_variable = { which = "global_chinese_mazdakis" value = 1 }
		}
		
		ai_chance = {
			factor = 60
			modifier = {
				factor = 1.1
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = mazdaki
						culture = mongol
					}
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = mazdaki
						OR = {
							culture = khitan
							culture = tangut
							culture = jurchen
							culture_group = chinese_group
						}
					}
				}
			}
			modifier = {
				factor = 1.2
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = mazdaki
						OR = {
							culture = khitan
							culture = tangut
							culture = jurchen
						}
					}
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = mazdaki
						culture_group = chinese_group
					}
				}
			}
			modifier = {
				factor = 1.3
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = mazdaki
						culture_group = chinese_group
					}
				}
			}
			modifier = {
				factor = 5
				OR = {
					offmap_china = { offmap_has_like = likes_mazdakis }
					offmap_china = { offmap_ruler = { religion = mazdaki } }
				}
			}
			modifier = {
				factor = 1.5
				AND = {
					offmap_china = { offmap_ruler = { religion = mazdaki } }
					offmap_china = { offmap_ruler = { culture_group = chinese_group } }
				}
			}
			modifier = {
				factor = 1.5
				AND = {
					offmap_china = { offmap_ruler = { religion = mazdaki } }
					offmap_china = { has_status = china_golden_age }
				}
			}
			modifier = {
				factor = 0.2
				AND = {
					offmap_china = { offmap_ruler = { religion = mazdaki } }
					offmap_china = {
						OR = {
							has_status = china_unrest
							has_status = china_famine
							has_status = china_plague
						}
					}
				}
			}
			modifier = {
				factor = 0.01
				AND = {
					offmap_china = { offmap_ruler = { religion = mazdaki } }
					offmap_china = {
						OR = {
							has_status = china_civil_war
							has_status = china_mongol_invasion
							has_status = china_jurchen_invasion
						}
					}
				}
			}
			modifier = {
				factor = 3
				AND = {
					offmap_china = { offmap_ruler = { NOT = { religion = mazdaki } } }
					offmap_china = {
						OR = {
							has_status = china_unrest
							has_status = china_civil_war
						}
					}
				}
			}
			modifier = {
				factor = 5
				AND = {
					offmap_china = { offmap_ruler = { NOT = { religion = mazdaki } } }
					offmap_china = {
						OR = {
							has_status = china_unrest
							has_status = china_famine
						}
					}
				}
			}
			modifier = {
				factor = 1.5
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = mazdaki
					any_realm_province = {
						region = custom_eastern_access
					}
					NOR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
					OR = {
						has_character_modifier = peace_deal_with_china
						has_character_modifier = chinese_imperial_trade_contract
						has_character_modifier = chinese_favored_in_trade
						has_offmap_currency = { offmap = offmap_china value = 1000 }
					}
				}
			}
			modifier = {
				factor = 0.33
				OR = {
					offmap_china = { offmap_ruler = { religion = zoroastrian } }
					offmap_china = {
						offmap_ruler = {
							religion_group = pagan_group
							has_religion_feature = religion_dogmatic
						}
					}
				}
			}
			modifier = {
				factor = 1.33
				offmap_china = { offmap_ruler = { is_female = yes } }
			}
		}
	}
	
	option = { #Wane
		if = {
			limit = {
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = mazdaki
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
			change_variable = { which = "global_chinese_mazdakis" value = -2 }
		}
		else = {
			change_variable = { which = "global_chinese_mazdakis" value = -1 }
		}
	
		ai_chance = {
			factor = 30
			modifier = {
				factor = 0
				offmap_china = { offmap_ruler = { religion = mazdaki } }
			}
			modifier = {
				factor = 0
				offmap_china = { offmap_has_like = likes_mazdakis }
			}
			modifier = {
				factor = 0.1
				1513 = { has_province_modifier = kcc_recent_mazdaki_mission }
			}
			modifier = {
				factor = 2
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = mazdaki
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
		}
	}
}

# Wax & Wane of Manicheaism
character_event = {
	id = kccwaxwane.0024
	hide_window = yes
	
	is_triggered_only = yes
	
	has_dlc = "Jade Dragon"
	only_playable = yes
	
	trigger = {
		has_landed_title = e_china_west_governor
	}
	
	after = {
		if = {
			limit = {
				check_variable = { which = "global_chinese_manicheans" value = 20 }
				NOT = { has_global_flag = manichean_china_one }
			}
			set_global_flag = manichean_china_one
			set_global_flag = kcc_waxwane_manicheans
			any_playable_ruler = { narrative_event = { id = kccspread.0003 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_manicheans" value = 40 }
				NOT = { has_global_flag = manichean_china_two }
			}
			set_global_flag = manichean_china_two
			set_global_flag = kcc_waxwane_manicheans
			any_playable_ruler = { narrative_event = { id = kccspread.0004 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_manicheans" value = 100 }
				NOT = { has_global_flag = manichean_china_three }
			}
			set_global_flag = manichean_china_three
			set_global_flag = kcc_waxwane_manicheans
			any_playable_ruler = { narrative_event = { id = kccspread.0005 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_manicheans" value = 180 }
				NOT = { has_global_flag = manichean_china_four }
				kcc_nontaoist_majority_trigger = yes
			}
			kcc_drop_other_religion_effect = yes
			set_global_flag = manichean_china_four
			set_global_flag = kcc_waxwane_manicheans
			any_playable_ruler = { narrative_event = { id = kccspread.0007 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_manicheans" value = 180 }
				NOT = { has_global_flag = manichean_china_four }
			}
			set_global_flag = manichean_china_four
			set_global_flag = kcc_waxwane_manicheans
			any_playable_ruler = { narrative_event = { id = kccspread.0006 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_manicheans" value = 100 } }
				has_global_flag = manichean_china_three
			}
			clr_global_flag = manichean_china_three
			set_global_flag = kcc_waxwane_manicheans
			any_playable_ruler = { narrative_event = { id = kccspread.0008 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_manicheans" value = 40 } }
				has_global_flag = manichean_china_two
			}
			clr_global_flag = manichean_china_two
			set_global_flag = kcc_waxwane_manicheans
			any_playable_ruler = { narrative_event = { id = kccspread.0009 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_manicheans" value = 20 } }
				has_global_flag = manichean_china_one
			}
			clr_global_flag = manichean_china_one
			set_global_flag = kcc_waxwane_manicheans
			any_playable_ruler = { narrative_event = { id = kccspread.0010 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_manicheans" value = 0 } }
				has_global_flag = manicheans_in_china
			}
			clr_global_flag = manicheans_in_china
			set_variable = { which = "global_chinese_manicheans" value = 0 }
			set_global_flag = kcc_waxwane_manicheans
			any_playable_ruler = { narrative_event = { id = kccspread.0011 days = 1 } }
		}
	}
	
	weight_multiplier = {
		days = 17
		modifier = {
			factor = 0
			NOT = { has_global_flag = manicheans_in_china }
		}
		modifier = {
			factor = 0
			1513 = {
				OR = {
					has_province_modifier = kcc_china_persecuted_mazdans
					has_province_modifier = kcc_zoro_china_persecuted_mazdans
					has_province_modifier = kcc_china_persecuted_manicheans
				}
			}
		}
		modifier = {
			factor = 2
			offmap_china = { offmap_has_like = likes_manicheans }
		}
		modifier = {
			factor = 5
			offmap_china = { offmap_ruler = { religion = manichean } }
			NOR = {
				has_global_flag = manichean_china_two
				has_global_flag = manichean_china_three
				has_global_flag = manichean_china_four
			}
		}
		modifier = {
			factor = 4
			offmap_china = { offmap_ruler = { religion = manichean } }
			NOR = {
				has_global_flag = manichean_china_three
				has_global_flag = manichean_china_four
			}
		}
		modifier = {
			factor = 1.5
			offmap_china = { offmap_ruler = { religion = manichean } }
			NOT = { has_global_flag = manichean_china_four }
		}
		modifier = {
			factor = 0
			offmap_china = { offmap_ruler = { religion = manichean } }
			has_global_flag = manichean_china_four
		}
	}
	
	option = { #No change
	
		ai_chance = {
			factor = 30
		}
	}
	
	option = { #Wax
		if = {
			limit = {
				offmap_china = {
					OR = {
						offmap_ruler = { religion = manichean }
						offmap_china = { offmap_has_like = likes_manicheans }
					}
				}
			}
			change_variable = { which = "global_chinese_manicheans" value = 2 }
		}
		else = {
			change_variable = { which = "global_chinese_manicheans" value = 1 }
		}
		
		ai_chance = {
			factor = 60
			modifier = {
				factor = 1.1
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = manichean
						culture = mongol
					}
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = manichean
						OR = {
							culture = khitan
							culture = tangut
							culture = jurchen
							culture_group = chinese_group
						}
					}
				}
			}
			modifier = {
				factor = 1.2
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = manichean
						OR = {
							culture = khitan
							culture = tangut
							culture = jurchen
						}
					}
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = manichean
						culture_group = chinese_group
					}
				}
			}
			modifier = {
				factor = 1.3
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = manichean
						culture_group = chinese_group
					}
				}
			}
			modifier = {
				factor = 5
				OR = {
					offmap_china = { offmap_has_like = likes_manicheans }
					offmap_china = { offmap_ruler = { religion = manichean } }
				}
			}
			modifier = {
				factor = 1.5
				AND = {
					offmap_china = { offmap_ruler = { religion = manichean } }
					offmap_china = { offmap_ruler = { culture_group = chinese_group } }
				}
			}
			modifier = {
				factor = 1.5
				AND = {
					offmap_china = { offmap_ruler = { religion = manichean } }
					offmap_china = { has_status = china_golden_age }
				}
			}
			modifier = {
				factor = 0.2
				AND = {
					offmap_china = { offmap_ruler = { religion = manichean } }
					offmap_china = {
						OR = {
							has_status = china_unrest
							has_status = china_famine
							has_status = china_plague
						}
					}
				}
			}
			modifier = {
				factor = 0.01
				AND = {
					offmap_china = { offmap_ruler = { religion = manichean } }
					offmap_china = {
						OR = {
							has_status = china_civil_war
							has_status = china_mongol_invasion
							has_status = china_jurchen_invasion
						}
					}
				}
			}
			modifier = {
				factor = 3
				AND = {
					offmap_china = { offmap_ruler = { NOT = { religion = manichean } } }
					offmap_china = {
						OR = {
							has_status = china_unrest
							has_status = china_civil_war
						}
					}
				}
			}
			modifier = {
				factor = 2
				OR = {
					AND = {
						offmap_china = { offmap_has_like = likes_indians }
						d_manichean = { holder_scope = { culture_group = indo_aryan_group } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_dravidians }
						d_manichean = { holder_scope = { culture_group = dravidian_group } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_tibetans }
						d_manichean = { holder_scope = { culture_group = tibetan_group } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_germanics }
						d_manichean = { holder_scope = {
							OR = {
								culture_group = north_germanic
								culture_group = central_germanic
								culture_group = west_germanic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_latino_iberians }
						d_manichean = { holder_scope = {
							OR = {
								culture_group = latin
								culture_group = iberian
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_byzantines }
						d_manichean = { holder_scope = { culture_group = byzantine } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_celts }
						d_manichean = { holder_scope = { culture_group = celtic } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_finno_ugrics }
						d_manichean = { holder_scope = {
							OR = {
								culture_group = finno_ugric
								culture_group = magyar
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_altaics }
						d_manichean = { holder_scope = { culture_group = altaic } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_balto_slavics }
						d_manichean = { holder_scope = {
							OR = {
								culture_group = baltic
								culture_group = east_slavic
								culture_group = west_slavic
								culture_group = south_slavic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_arabs }
						d_manichean = { holder_scope = { culture_group = arabic } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_iranians }
						d_manichean = { holder_scope = { culture_group = iranian } }
					}
					AND = {
						offmap_china = { offmap_has_like = likes_africans }
						d_manichean = { holder_scope = {
							OR = {
								culture_group = west_african
								culture_group = east_african
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_like = likes_mesoamericans }
						d_manichean = { holder_scope = { culture_group = mesoamerican } }
					}
				}
			}
			modifier = {
				factor = 1.5
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = manichean
					any_realm_province = {
						region = custom_eastern_access
					}
					NOR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
					OR = {
						has_character_modifier = peace_deal_with_china
						has_character_modifier = chinese_imperial_trade_contract
						has_character_modifier = chinese_favored_in_trade
						has_offmap_currency = { offmap = offmap_china value = 1000 }
					}
				}
			}
			modifier = {
				factor = 0.33
				OR = {
					offmap_china = { offmap_ruler = { religion = zoroastrian } }
					offmap_china = { offmap_ruler = { religion_group = christian } }
					offmap_china = {
						offmap_ruler = {
							religion_group = pagan_group
							has_religion_feature = religion_dogmatic
						}
					}
				}
			}
			modifier = {
				factor = 1.33
				AND = {
					offmap_china = { offmap_ruler = { NOT = { religion = manichean } } }
					has_global_flag = yamag_moved_to_china
				}
			}
			modifier = {
				factor = 4
				AND = {
					offmap_china = { offmap_ruler = { religion = manichean } }
					has_global_flag = yamag_moved_to_china
				}
			}
		}
	}
	
	option = { #Wane
		if = {
			limit = {
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = manichean
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
			change_variable = { which = "global_chinese_manicheans" value = -2 }
		}
		else = {
			change_variable = { which = "global_chinese_manicheans" value = -1 }
		}
	
		ai_chance = {
			factor = 30
			modifier = {
				factor = 0
				offmap_china = { offmap_ruler = { religion = manichean } }
			}
			modifier = {
				factor = 0
				offmap_china = { offmap_has_like = likes_manicheans }
			}
			modifier = {
				factor = 0.1
				1513 = { has_province_modifier = kcc_recent_manichean_mission }
			}
			modifier = {
				factor = 2
				OR = {
					AND = {
						offmap_china = { offmap_has_dislike = likes_indians }
						d_manichean = { holder_scope = { culture_group = indo_aryan_group } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_dravidians }
						d_manichean = { holder_scope = { culture_group = dravidian_group } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_tibetans }
						d_manichean = { holder_scope = { culture_group = tibetan_group } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_germanics }
						d_manichean = { holder_scope = {
							OR = {
								culture_group = north_germanic
								culture_group = central_germanic
								culture_group = west_germanic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_latino_iberians }
						d_manichean = { holder_scope = {
							OR = {
								culture_group = latin
								culture_group = iberian
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_byzantines }
						d_manichean = { holder_scope = { culture_group = byzantine } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_celts }
						d_manichean = { holder_scope = { culture_group = celtic } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_finno_ugrics }
						d_manichean = { holder_scope = {
							OR = {
								culture_group = finno_ugric
								culture_group = magyar
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_altaics }
						d_manichean = { holder_scope = { culture_group = altaic } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_balto_slavics }
						d_manichean = { holder_scope = {
							OR = {
								culture_group = baltic
								culture_group = east_slavic
								culture_group = west_slavic
								culture_group = south_slavic
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_arabs }
						d_manichean = { holder_scope = { culture_group = arabic } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_iranians }
						d_manichean = { holder_scope = { culture_group = iranian } }
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_africans }
						d_manichean = { holder_scope = {
							OR = {
								culture_group = west_african
								culture_group = east_african
							} }
						}
					}
					AND = {
						offmap_china = { offmap_has_dislike = likes_mesoamericans }
						d_manichean = { holder_scope = { culture_group = mesoamerican } }
					}
				}
			}
			modifier = {
				factor = 2
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = manichean
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
		}
	}
}

# Wax & Wane of Buddhism
character_event = {
	id = kccwaxwane.0025
	hide_window = yes
	
	is_triggered_only = yes
	
	has_dlc = "Jade Dragon"
	only_playable = yes
	
	trigger = {
		has_landed_title = e_china_west_governor
	}
	
	after = {
		if = {
			limit = {
				check_variable = { which = "global_chinese_buddhists" value = 20 }
				NOT = { has_global_flag = buddhist_china_one }
			}
			set_global_flag = buddhist_china_one
			set_global_flag = kcc_waxwane_buddhists
			any_playable_ruler = { narrative_event = { id = kccspread.0003 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_buddhists" value = 40 }
				NOT = { has_global_flag = buddhist_china_two }
			}
			set_global_flag = buddhist_china_two
			set_global_flag = kcc_waxwane_buddhists
			any_playable_ruler = { narrative_event = { id = kccspread.0004 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_buddhists" value = 100 }
				NOT = { has_global_flag = buddhist_china_three }
			}
			set_global_flag = buddhist_china_three
			set_global_flag = kcc_waxwane_buddhists
			any_playable_ruler = { narrative_event = { id = kccspread.0005 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_buddhists" value = 180 }
				NOT = { has_global_flag = buddhist_china_four }
				kcc_nontaoist_majority_trigger = yes
			}
			kcc_drop_other_religion_effect = yes
			set_global_flag = buddhist_china_four
			set_global_flag = kcc_waxwane_buddhists
			any_playable_ruler = { narrative_event = { id = kccspread.0007 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_buddhists" value = 180 }
				NOT = { has_global_flag = buddhist_china_four }
			}
			set_global_flag = buddhist_china_four
			set_global_flag = kcc_waxwane_buddhists
			any_playable_ruler = { narrative_event = { id = kccspread.0006 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_buddhists" value = 100 } }
				has_global_flag = buddhist_china_three
			}
			clr_global_flag = buddhist_china_three
			set_global_flag = kcc_waxwane_buddhists
			any_playable_ruler = { narrative_event = { id = kccspread.0008 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_buddhists" value = 40 } }
				has_global_flag = buddhist_china_two
			}
			clr_global_flag = buddhist_china_two
			set_global_flag = kcc_waxwane_buddhists
			any_playable_ruler = { narrative_event = { id = kccspread.0009 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_buddhists" value = 20 } }
				has_global_flag = buddhist_china_one
			}
			clr_global_flag = buddhist_china_one
			set_global_flag = kcc_waxwane_buddhists
			any_playable_ruler = { narrative_event = { id = kccspread.0010 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_buddhists" value = 0 } }
				has_global_flag = buddhists_in_china
			}
			clr_global_flag = buddhists_in_china
			set_variable = { which = "global_chinese_buddhists" value = 0 }
			set_global_flag = kcc_waxwane_buddhists
			any_playable_ruler = { narrative_event = { id = kccspread.0011 days = 1 } }
		}
	}
	
	weight_multiplier = {
		days = 17
		modifier = {
			factor = 0
			NOT = { has_global_flag = buddhists_in_china }
		}
		modifier = {
			factor = 0
			1513 = { has_province_modifier = kcc_china_persecuted_dharmans }
		}
		modifier = {
			factor = 2
			offmap_china = { offmap_has_like = likes_buddhists }
		}
		modifier = {
			factor = 5
			offmap_china = { offmap_ruler = { religion = buddhist } }
			NOR = {
				has_global_flag = buddhist_china_two
				has_global_flag = buddhist_china_three
				has_global_flag = buddhist_china_four
			}
		}
		modifier = {
			factor = 4
			offmap_china = { offmap_ruler = { religion = buddhist } }
			NOR = {
				has_global_flag = buddhist_china_three
				has_global_flag = buddhist_china_four
			}
		}
		modifier = {
			factor = 1.5
			offmap_china = { offmap_ruler = { religion = buddhist } }
			NOT = { has_global_flag = buddhist_china_four }
		}
		modifier = {
			factor = 0
			offmap_china = { offmap_ruler = { religion = buddhist } }
			has_global_flag = buddhist_china_four
		}
	}
	
	option = { #No change
	
		ai_chance = {
			factor = 30
		}
	}
	
	option = { #Wax
		if = {
			limit = {
				offmap_china = {
					OR = {
						offmap_ruler = { religion = buddhist }
						offmap_china = { offmap_has_like = likes_buddhists }
					}
				}
			}
			change_variable = { which = "global_chinese_buddhists" value = 2 }
		}
		else = {
			change_variable = { which = "global_chinese_buddhists" value = 1 }
		}
		
		ai_chance = {
			factor = 70
			modifier = {
				factor = 1.1
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = buddhist
						culture = mongol
					}
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = buddhist
						OR = {
							culture = khitan
							culture = tangut
							culture = jurchen
							culture_group = chinese_group
						}
					}
				}
			}
			modifier = {
				factor = 1.2
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = buddhist
						OR = {
							culture = khitan
							culture = tangut
							culture = jurchen
						}
					}
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = buddhist
						culture_group = chinese_group
					}
				}
			}
			modifier = {
				factor = 1.3
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = buddhist
						culture_group = chinese_group
					}
				}
			}
			modifier = {
				factor = 5
				OR = {
					offmap_china = { offmap_has_like = likes_buddhists }
					offmap_china = { offmap_ruler = { religion = buddhist } }
				}
			}
			modifier = {
				factor = 1.5
				AND = {
					offmap_china = { offmap_ruler = { religion = buddhist } }
					offmap_china = { offmap_ruler = { culture_group = chinese_group } }
				}
			}
			modifier = {
				factor = 1.5
				AND = {
					offmap_china = { offmap_ruler = { religion = buddhist } }
					offmap_china = { has_status = china_golden_age }
				}
			}
			modifier = {
				factor = 0.2
				AND = {
					offmap_china = { offmap_ruler = { religion = buddhist } }
					offmap_china = {
						OR = {
							has_status = china_unrest
							has_status = china_famine
							has_status = china_plague
						}
					}
				}
			}
			modifier = {
				factor = 0.01
				AND = {
					offmap_china = { offmap_ruler = { religion = buddhist } }
					offmap_china = {
						OR = {
							has_status = china_civil_war
							has_status = china_mongol_invasion
							has_status = china_jurchen_invasion
						}
					}
				}
			}
			modifier = {
				factor = 3
				AND = {
					offmap_china = { offmap_ruler = { NOT = { religion = buddhist } } }
					offmap_china = {
						OR = {
							has_status = china_unrest
							has_status = china_civil_war
						}
					}
				}
			}
			modifier = {
				factor = 1.5
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = buddhist
					any_realm_province = {
						region = custom_eastern_access
					}
					NOR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
					OR = {
						has_character_modifier = peace_deal_with_china
						has_character_modifier = chinese_imperial_trade_contract
						has_character_modifier = chinese_favored_in_trade
						has_offmap_currency = { offmap = offmap_china value = 1000 }
					}
				}
			}
			modifier = {
				factor = 0.33
				offmap_china = {
					offmap_ruler = {
						religion_group = pagan_group
						has_religion_feature = religion_dogmatic
					}
				}
			}
			modifier = {
				factor = 1.33
				offmap_china = { offmap_ruler = { is_female = yes } }
			}
		}
	}
	
	option = { #Wane
		if = {
			limit = {
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = buddhist
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
			change_variable = { which = "global_chinese_buddhists" value = -2 }
		}
		else = {
			change_variable = { which = "global_chinese_buddhists" value = -1 }
		}
	
		ai_chance = {
			factor = 30
			modifier = {
				factor = 0
				offmap_china = { offmap_ruler = { religion = buddhist } }
			}
			modifier = {
				factor = 0
				offmap_china = { offmap_has_like = likes_buddhists }
			}
			modifier = {
				factor = 0.1
				1513 = { has_province_modifier = kcc_recent_buddhist_mission }
			}
			modifier = {
				factor = 2
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = buddhist
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
		}
	}
}

# Wax & Wane of Jainism
character_event = {
	id = kccwaxwane.0026
	hide_window = yes
	
	is_triggered_only = yes
	
	has_dlc = "Jade Dragon"
	only_playable = yes
	
	trigger = {
		has_landed_title = e_china_west_governor
	}
	
	after = {
		if = {
			limit = {
				check_variable = { which = "global_chinese_jains" value = 20 }
				NOT = { has_global_flag = jain_china_one }
			}
			set_global_flag = jain_china_one
			set_global_flag = kcc_waxwane_jains
			any_playable_ruler = { narrative_event = { id = kccspread.0003 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_jains" value = 40 }
				NOT = { has_global_flag = jain_china_two }
			}
			set_global_flag = jain_china_two
			set_global_flag = kcc_waxwane_jains
			any_playable_ruler = { narrative_event = { id = kccspread.0004 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_jains" value = 100 }
				NOT = { has_global_flag = jain_china_three }
			}
			set_global_flag = jain_china_three
			set_global_flag = kcc_waxwane_jains
			any_playable_ruler = { narrative_event = { id = kccspread.0005 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_jains" value = 180 }
				NOT = { has_global_flag = jain_china_four }
				kcc_nontaoist_majority_trigger = yes
			}
			kcc_drop_other_religion_effect = yes
			set_global_flag = jain_china_four
			set_global_flag = kcc_waxwane_jains
			any_playable_ruler = { narrative_event = { id = kccspread.0007 days = 1 } }
		}
		else_if = {
			limit = {
				check_variable = { which = "global_chinese_jains" value = 180 }
				NOT = { has_global_flag = jain_china_four }
			}
			set_global_flag = jain_china_four
			set_global_flag = kcc_waxwane_jains
			any_playable_ruler = { narrative_event = { id = kccspread.0006 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_jains" value = 100 } }
				has_global_flag = jain_china_three
			}
			clr_global_flag = jain_china_three
			set_global_flag = kcc_waxwane_jains
			any_playable_ruler = { narrative_event = { id = kccspread.0008 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_jains" value = 40 } }
				has_global_flag = jain_china_two
			}
			clr_global_flag = jain_china_two
			set_global_flag = kcc_waxwane_jains
			any_playable_ruler = { narrative_event = { id = kccspread.0009 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_jains" value = 20 } }
				has_global_flag = jain_china_one
			}
			clr_global_flag = jain_china_one
			set_global_flag = kcc_waxwane_jains
			any_playable_ruler = { narrative_event = { id = kccspread.0010 days = 1 } }
		}
		else_if = {
			limit = {
				NOT = { check_variable = { which = "global_chinese_jains" value = 0 } }
				has_global_flag = jains_in_china
			}
			clr_global_flag = jains_in_china
			set_variable = { which = "global_chinese_jains" value = 0 }
			set_global_flag = kcc_waxwane_jains
			any_playable_ruler = { narrative_event = { id = kccspread.0011 days = 1 } }
		}
	}
	
	weight_multiplier = {
		days = 17
		modifier = {
			factor = 0
			NOT = { has_global_flag = jains_in_china }
		}
		modifier = {
			factor = 0
			1513 = { has_province_modifier = kcc_china_persecuted_dharmans }
		}
		modifier = {
			factor = 2
			offmap_china = { offmap_has_like = likes_jains }
		}
		modifier = {
			factor = 5
			offmap_china = { offmap_ruler = { religion = jain } }
			NOR = {
				has_global_flag = jain_china_two
				has_global_flag = jain_china_three
				has_global_flag = jain_china_four
			}
		}
		modifier = {
			factor = 4
			offmap_china = { offmap_ruler = { religion = jain } }
			NOR = {
				has_global_flag = jain_china_three
				has_global_flag = jain_china_four
			}
		}
		modifier = {
			factor = 1.5
			offmap_china = { offmap_ruler = { religion = jain } }
			NOT = { has_global_flag = jain_china_four }
		}
		modifier = {
			factor = 0
			offmap_china = { offmap_ruler = { religion = jain } }
			has_global_flag = jain_china_four
		}
	}
	
	option = { #No change
	
		ai_chance = {
			factor = 30
		}
	}
	
	option = { #Wax
		if = {
			limit = {
				offmap_china = {
					OR = {
						offmap_ruler = { religion = jain }
						offmap_china = { offmap_has_like = likes_jains }
					}
				}
			}
			change_variable = { which = "global_chinese_jains" value = 2 }
		}
		else = {
			change_variable = { which = "global_chinese_jains" value = 1 }
		}
		
		ai_chance = {
			factor = 70
			modifier = {
				factor = 1.1
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = jain
						culture = mongol
					}
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = jain
						OR = {
							culture = khitan
							culture = tangut
							culture = jurchen
							culture_group = chinese_group
						}
					}
				}
			}
			modifier = {
				factor = 1.2
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = jain
						OR = {
							culture = khitan
							culture = tangut
							culture = jurchen
						}
					}
				}
				NOT = {
					any_province = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = jain
						culture_group = chinese_group
					}
				}
			}
			modifier = {
				factor = 1.3
				any_province = {
					AND = {
						OR = {
							region = custom_eastern_access
							region = world_india
						}
						religion = jain
						culture_group = chinese_group
					}
				}
			}
			modifier = {
				factor = 5
				OR = {
					offmap_china = { offmap_has_like = likes_jains }
					offmap_china = { offmap_ruler = { religion = jain } }
				}
			}
			modifier = {
				factor = 1.5
				AND = {
					offmap_china = { offmap_ruler = { religion = jain } }
					offmap_china = { offmap_ruler = { culture_group = chinese_group } }
				}
			}
			modifier = {
				factor = 1.5
				AND = {
					offmap_china = { offmap_ruler = { religion = jain } }
					offmap_china = { has_status = china_golden_age }
				}
			}
			modifier = {
				factor = 0.2
				AND = {
					offmap_china = { offmap_ruler = { religion = jain } }
					offmap_china = {
						OR = {
							has_status = china_unrest
							has_status = china_famine
							has_status = china_plague
						}
					}
				}
			}
			modifier = {
				factor = 0.01
				AND = {
					offmap_china = { offmap_ruler = { religion = jain } }
					offmap_china = {
						OR = {
							has_status = china_civil_war
							has_status = china_mongol_invasion
							has_status = china_jurchen_invasion
						}
					}
				}
			}
			modifier = {
				factor = 3
				AND = {
					offmap_china = { offmap_ruler = { NOT = { religion = jain } } }
					offmap_china = {
						OR = {
							has_status = china_unrest
							has_status = china_civil_war
						}
					}
				}
			}
			modifier = {
				factor = 1.5
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = jain
					any_realm_province = {
						region = custom_eastern_access
					}
					NOR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
					OR = {
						has_character_modifier = peace_deal_with_china
						has_character_modifier = chinese_imperial_trade_contract
						has_character_modifier = chinese_favored_in_trade
						has_offmap_currency = { offmap = offmap_china value = 1000 }
					}
				}
			}
			modifier = {
				factor = 0.33
				offmap_china = {
					offmap_ruler = {
						religion_group = pagan_group
						has_religion_feature = religion_dogmatic
					}
				}
			}
			modifier = {
				factor = 1.33
				offmap_china = { offmap_ruler = { is_female = yes } }
			}
		}
	}
	
	option = { #Wane
		if = {
			limit = {
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = jain
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
			change_variable = { which = "global_chinese_jains" value = -2 }
		}
		else = {
			change_variable = { which = "global_chinese_jains" value = -1 }
		}
	
		ai_chance = {
			factor = 30
			modifier = {
				factor = 0
				offmap_china = { offmap_ruler = { religion = jain } }
			}
			modifier = {
				factor = 0
				offmap_china = { offmap_has_like = likes_jains }
			}
			modifier = {
				factor = 0.1
				1513 = { has_province_modifier = kcc_recent_jain_mission }
			}
			modifier = {
				factor = 2
				any_playable_ruler = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
					religion = jain
					any_realm_province = {
						region = custom_eastern_access
					}
					OR = {
						has_character_modifier = angered_china_modifier
						has_character_modifier = war_with_china_modifier
						has_character_modifier = failed_invasion_of_china
						has_character_modifier = china_raid_active
						has_character_modifier = china_raid_grace_cd
					}
				}
			}
		}
	}
}