namespace = FAT

narrative_event = {
	id = FAT.1000
	title = FAT1000T
	desc = FAT1000
	picture = GFX_evt_riots_byzantine
	border = GFX_event_narrative_frame_religion
	
	major = yes
	
	only_independent = yes
	only_playable = yes
	religion_group = muslim
	
	trigger = {
		NOT = {year = 1000}
		year = 893
		NOT = { religion = shiite }
		higher_tier_than = DUKE
		OR = {
			has_landed_title = k_africa
			any_realm_title = {
				title = c_tunis
			}
			
		}
		d_shiite = {
			OR = {
				has_holder = no
				holder_scope = {
					ai = yes
				}
			}
		}
		NOT = { has_global_flag = fatimid}
		NOT = { has_global_flag = shia_caliphate_revolt_ongoing }
		any_independent_ruler = {
			any_realm_character = {
				dynasty = 589
				age = 16
				NOT = {age = 40}
				is_female = no
				
				father_even_if_dead = {
					OR = {
						is_alive = no
						is_ruler = no
					}
				}
				is_ruler = no
			}
		}
	}
	
	mean_time_to_happen = {
		months = 120
	}
	
	immediate = {
		
		hidden_tooltip = {
			if = {
				limit = {NOT = { has_global_flag = shia_caliphate_revolt_ongoing }}
				
				if = {
					limit = {
						d_shiite = {
							has_holder = yes
							holder_scope = {
								ai = yes
							}
						}
					}
					d_shiite = {
						destroy_landed_title = THIS
					}
				}
				set_character_flag = shia_caliphate_revolt
				set_global_flag = shia_caliphate_revolt_ongoing
				set_global_flag = fatimid
				decadence = -30 # Do not want to be hit with a decadence revolt as well!
				any_realm_province = {
					limit = {port = yes}
					add_province_modifier = {
						name = fatimid_galleys
						duration = 36500
					}
				}
				random_realm_province = {
					limit = {
						kingdom = {
							OR = {
								has_holder = no
								holder_scope = {
									character = ROOT
								}
							}
							NOT = {title = k_sicily}
						}
					}
					
					random_independent_ruler = {
						limit = {
							any_realm_character = {
								dynasty = 589
								is_female = no
								age = 16
								NOT = {age = 40}
								father_even_if_dead = {
									OR = {
										is_alive = no
										is_ruler = no
									}
								}
								is_ruler = no
							}
						}
						random_realm_character = {
							limit = {
								dynasty = 589
								is_female = no
								age = 16
								NOT = {age = 40}
								father_even_if_dead = {
									OR = {
										is_alive = no
										is_ruler = no
									}
								}
								is_ruler = no
							}
							imprison = no
							add_trait = genius
							add_trait = strong
							add_trait = ambitious
							add_trait = diligent
							set_character_flag = fatimid_invasion
							if = {
								limit = {NOT = {has_character_flag = wpn}}
								add_trait = scimitar3
								set_character_flag = wpn
							}
							remove_trait = decadent
							set_guardian = none
							unsafe_religion = shiite
							
							any_child = {
								unsafe_religion = shiite
								set_character_flag = fatimid_invasion
								any_child = {
									unsafe_religion = shiite
									set_character_flag = fatimid_invasion
								}
							}
							set_character_flag = shia_caliphate_pretender
							create_title = {
								tier = DUKE
								landless = yes
								temporary = yes
								culture = ROOT
								name = SHIA_CALIPHATE_REVOLT
								holder = THIS
							}
							unsafe_religion = shiite
							create_character = {
								name = "Manad"
								random_traits = no
								dynasty = 595
								religion = THIS
								culture = maghreb_arabic
								female = no
								age = 40
								trait = underhanded_rogue
								trait = ambitious
								trait = shrewd
								trait = greedy
								trait = gregarious
								trait = just
								attributes = {
									diplomacy = 12
									stewardship = 10
								}
							}
							new_character = {
								add_trait = scimitar4
								add_trait = combat_exp
								set_character_flag = wpn
								spawn_unit = {
									province = 817
									
									owner = PREV
									#leader = THIS
									troops = {
										horse_archers = { 1412 1412 }
										light_cavalry = { 1333 1333 }
										light_infantry = { 123 123 }
										camel_cavalry = { 1550 1550 }
									}
									attrition = 0.0
								}
								save_event_target_as = target_manad
							}
							
							create_character = {
								name = "Ziri"
								dynasty = 595
								religion = shiite
								culture = maghreb_arabic
								female = no
								age = 0
								attributes = {
									diplomacy = 1
									stewardship = 1
								}
							}
							new_character = {
								set_father = event_target:target_manad
							}
							clear_event_target = target_manad
							create_character = {
								random_traits = yes
								dynasty = none
								religion = shiite
								culture = THIS
								female = no
								age = 27
								trait = brilliant_strategist
							}
							new_character = {
								add_trait = scimitar1
								set_character_flag = wpn
								spawn_unit = {
									province = 817
									
									owner = PREV
									#leader = THIS
									troops = {
										horse_archers = { 1430 1430 }
										light_cavalry = { 1402 1402 }
										light_infantry = { 1444 1444 }
										camel_cavalry = { 1502 1502 }
									}
									attrition = 0.0
									
								}
							}
							create_character = {
								random_traits = yes
								dynasty = none
								religion = THIS
								culture = THIS
								female = no
								age = 25
								trait = skilled_tactician
							}
							new_character = {
								add_trait = scimitar2
								set_character_flag = wpn
								spawn_unit = {
									province = 817
									
									owner = PREV
									#leader = THIS
									troops = {
										horse_archers = { 400 400 }
										light_cavalry = { 400 400 }
										light_infantry = { 411 411 }
										camel_cavalry = { 400 400 }
									}
									attrition = 0.0
								}
							}
							create_character = {
								random_traits = yes
								dynasty = none
								religion = THIS
								culture = THIS
								female = no
								age = 23
								trait = skilled_tactician
							}
							new_character = {
								add_trait = scimitar2
								set_character_flag = wpn
								spawn_unit = {
									province = 817
									
									owner = PREV
									#leader = THIS
									troops = {
										horse_archers = { 400 400 }
										light_cavalry = { 445 445 }
										light_infantry = { 400 400 }
										camel_cavalry = { 400 400 }
									}
									attrition = 0.0
								}
							}
							create_character = {
								random_traits = yes
								dynasty = none
								religion = THIS
								culture = THIS
								female = no
								age = 27
								trait = skilled_tactician
							}
							new_character = {
								add_trait = scimitar4
								set_character_flag = wpn
								spawn_unit = {
									province = 817
									
									owner = PREV
									#leader = THIS
									troops = {
										horse_archers = { 465 462 }
										light_cavalry = { 400 400 }
										light_infantry = { 400 400 }
										camel_cavalry = { 400 400 }
									}
									attrition = 0.0
								}
							}
							create_character = {
								random_traits = yes
								dynasty = none
								religion = THIS
								culture = THIS
								female = no
								age = 24
								trait = skilled_tactician
							}
							new_character = {
								add_trait = scimitar3
								set_character_flag = wpn
								spawn_unit = {
									province = 817
									
									owner = PREV
									#leader = THIS
									troops = {
										horse_archers = { 400 400 }
										light_cavalry = { 421 421 }
										light_infantry = { 400 400 }
										camel_cavalry = { 1400 1400 }
									}
									attrition = 0.0
								}
							}
							create_character = {
								random_traits = yes
								dynasty = none
								religion = THIS
								culture = THIS
								female = no
								age = 32
								trait = brilliant_strategist
							}
							new_character = {
								add_trait = scimitar4
								set_character_flag = wpn
								spawn_unit = {
									province = 817
									
									owner = PREV
									#leader = THIS
									troops = {
										horse_archers = { 400 400 }
										light_cavalry = { 431 431 }
										light_infantry = { 400 400 }
										camel_cavalry = { 1400 1400 }
									}
									attrition = 0.0
								}
							}
							create_character = {
								random_traits = yes
								dynasty = none
								religion = THIS
								culture = THIS
								female = no
								age = 25
								trait = skilled_tactician
							}
							new_character = {
								add_trait = scimitar2
								set_character_flag = wpn
								spawn_unit = {
									province = 817
									
									owner = PREV
									#leader = THIS
									troops = {
										horse_archers = { 400 400 }
										light_cavalry = { 442 442 }
										light_infantry = { 400 400 }
										camel_cavalry = { 1400 1400 }
									}
									attrition = 0.0
								}
							}
							create_character = {
								random_traits = yes
								dynasty = none
								religion = THIS
								culture = THIS
								female = no
								age = 28
								trait = skilled_tactician
							}
							new_character = {
								add_trait = scimitar4
								set_character_flag = wpn
								spawn_unit = {
									province = 817
									
									owner = PREV
									troops = {
										horse_archers = { 423 423 }
										light_cavalry = { 444 444 }
										light_infantry = { 411 411 }
										camel_cavalry = { 1401 1401 }
									}
									reinforce_rate_multiplier = 1
									attrition = 0.0
								}
							}
							create_character = {
								random_traits = yes
								dynasty = none
								religion = THIS
								culture = THIS
								female = no
								age = 28
								trait = tough_soldier
							}
							new_character = {
								add_trait = scimitar5
								set_character_flag = wpn
								spawn_unit = {
									province = 817
									
									owner = PREV
									troops = {
										horse_archers = { 400 400 }
										light_cavalry = { 487 487 }
										light_infantry = { 400 400 }
										camel_cavalry = { 1412 1412 }
									}
									attrition = 0.0
									reinforce_rate_multiplier = 1
								}
							}
							create_character = {
								random_traits = yes
								dynasty = none
								religion = THIS
								culture = THIS
								female = no
								age = 28
								trait = skilled_tactician
							}
							new_character = {
								add_trait = scimitar2
								set_character_flag = wpn
								spawn_unit = {
									province = 817
									
									owner = PREV
									troops = {
										horse_archers = { 420 420 }
										light_cavalry = { 440 440 }
										light_infantry = { 420 420 }
										camel_cavalry = { 412 412 }
									}
									attrition = 0.0
									reinforce_rate_multiplier = 1
								}

							}
							
							war = {
								target = ROOT
								casus_belli = shia_caliphate_rising
								thirdparty_title = PREVPREV
								tier = KING
							}
							
						}
					}

					
				}
			}
		}
	}
	
	option = {
		name = "FAT1000A"
		trigger = {
			has_character_flag = shia_caliphate_revolt 
		}
		clr_character_flag = shia_caliphate_revolt
	}
	
	option = {
		name = "FAT1000B"
		trigger = {
			religion = shiite
		}
	}
	option = {
		name = "FAT1000C"
		trigger = {
			religion_group = muslim
			NOT = { religion = shiite }
			NOT = { has_character_flag = shia_caliphate_revolt }
		}
	}
	option = {
		name = "FAT1000D"
		trigger = {
			NOT = { religion_group = muslim }
			NOT = { has_character_flag = shia_caliphate_revolt }
		}
	}
}


character_event = {
	id = FAT.900
	only_independent = yes
	only_playable = yes
	religion_group = muslim
	hide_window = yes
	trigger = {
		NOT = {year = 1050}
		year = 950
		has_landed_title = d_shiite
		NOT = { has_global_flag = jawhar}
	}
	
	mean_time_to_happen = {
		years = 10
	}
	immediate = {
		set_global_flag = jawhar
		create_character = {
			name = "Jawhar"
			random_traits = no
			dynasty = none
			religion = ROOT
			culture = greek
			dna = "ixwigwrcrnu"
			female = no
			age = 27
			health = 5
			fertility = 0.5
			attributes = {
				martial = 9
				diplomacy = 9
			}
			trait = became_unlanded
			trait = brilliant_strategist
			trait = prison_life
			trait = quick
			trait = robust
			trait = shrewd
			trait = brave
			trait = diligent
			trait = ambitious
			trait = wroth
			trait = inspiring_leader
			trait = sympathy_christendom
		}
		hidden_tooltip = {
			new_character = {
				culture = ROOT
				add_trait = combat_exp
				add_trait = swordsman4
				set_character_flag = wpn
				character_event = {id = FAT.910 days = 1}
			}	
		}
		
	}
}



character_event = {
	id = FAT.500
	hide_window = yes
	
	is_triggered_only = yes
	trigger = {has_landed_title = d_shiite}
	immediate = {
		current_heir = {
			unsafe_religion = shiite
		}
	}
}

character_event = {
	id = FAT.910
	hide_window = yes
	
	is_triggered_only = yes
	
	immediate = {
		FROM = {character_event = {id = FAT.1001 days = 1}}
		
	}
}

narrative_event = { #Jawhar
	id = FAT.1001
	title = FAT1001T
	desc = FAT1001
	picture = GFX_evt_emissary
	border = GFX_event_narrative_frame_religion
	
	is_triggered_only = yes
	
	
	
	option = {
		ai_chance = {
			factor = 100
		}
		job_chancellor = {
			opinion = {
				modifier = opinion_fired_from_council
				years = 5
				who = ROOT
			}
		}
		FROM = {
			give_job_title = job_chancellor
			give_minor_title = title_commander
			hidden_tooltip = {
				character_event = {id = FAT.920 days = 2920 random = 365}
			}
		}
		
		name = "FAT1001A"
	}
	
	option = {
		ai_chance = {
			factor = 0
		}
		name = "FAT1001B"
	}
}

character_event = {
	id = FAT.920
	hide_window = yes
	
	is_triggered_only = yes
	trigger = {
		any_liege = {
			has_landed_title = d_shiite
		}
	}
	immediate = {
		if = {
			limit = {
				OR = {
					liege = {war = yes}
					NOT = {
						any_independent_ruler = {
							any_realm_title = {title = k_egypt}
							NOT = {has_landed_title = d_shiite}
						}
					}
				}
			}
			character_event = {id = FAT.920 days = 60}
			break = yes
		}
		
		any_liege = {
			if = {
				limit = {has_landed_title = d_shiite}
				character_event = {id = FAT.1002 days = 1}
			}
		}
	}
}

narrative_event = { #Jawhar
	id = FAT.1002
	title = FAT1002T
	desc = FAT1002
	picture = GFX_evt_emissary
	border = GFX_event_narrative_frame_religion
	
	is_triggered_only = yes

	trigger = {
		has_landed_title = d_shiite
		any_independent_ruler = {
			any_realm_title = {title = k_egypt}
			NOT = {has_landed_title = d_shiite}
		}
	}
	option = {
		ai_chance = {
			factor = 100
		}
		hidden_tooltip = {
			FROM = {give_minor_title = title_commander}
		}
		prestige = 100
		piety = 100
		add_claim = k_egypt
		k_egypt = {
			holder_scope = {
				reverse_war = {
					target = ROOT
					casus_belli = claim
					thirdparty_title = PREV
					infamy = 0
				}
			}
		}
		capital_scope = {
			ROOT = {
				
				spawn_unit = {
					province = 817
					
					owner = ROOT
					#leader = THIS
					troops = {
						horse_archers = { 1430 1430 }
						light_cavalry = { 1402 1402 }
						light_infantry = { 1444 1444 }
						camel_cavalry = { 1502 1502 }
					}
					disband_on_peace = yes
					
				}
								
				spawn_unit = {
					province = 817
					
					owner = ROOT
					#leader = THIS
					troops = {
						horse_archers = { 1430 1430 }
						light_cavalry = { 1402 1402 }
						light_infantry = { 1444 1444 }
						camel_cavalry = { 1502 1502 }
					}
					disband_on_peace = yes
					
				}
				
				spawn_unit = {
					province = 817
					
					owner = ROOT
					#leader = THIS
					troops = {
						horse_archers = { 1430 1430 }
						light_cavalry = { 1402 1402 }
						light_infantry = { 1444 1444 }
						camel_cavalry = { 1502 1502 }
					}
					disband_on_peace = yes
					
				}
				
				spawn_unit = {
					province = 817
					
					owner = ROOT
					#leader = THIS
					troops = {
						horse_archers = { 1430 1430 }
						light_cavalry = { 1402 1402 }
						light_infantry = { 1444 1444 }
						camel_cavalry = { 1502 1502 }
					}
					disband_on_peace = yes
					
				}
				
				spawn_unit = {
					province = 817
					
					owner = ROOT
					#leader = THIS
					troops = {
						horse_archers = { 1430 1430 }
						light_cavalry = { 1402 1402 }
						light_infantry = { 1444 1444 }
						camel_cavalry = { 1502 1502 }
					}
					disband_on_peace = yes
					
				}
				spawn_unit = {
					province = 817
					
					owner = ROOT
					#leader = THIS
					troops = {
						horse_archers = { 1430 1430 }
						light_cavalry = { 1402 1402 }
						light_infantry = { 1444 1444 }
						camel_cavalry = { 1502 1502 }
					}
					disband_on_peace = yes
					
				}
			}
		}
		name = "FAT1002A"
	}
	option = {
		ai_chance = {
			factor = 0
		}
		prestige = -100
		piety = -100
		name = "FAT1002B"
	}
}