namespace = EADOAD

#character_event = {
#    id = EADOAD.1
#
#   hide_window = yes
#	religion = catholic
#	min_age = 16
#	show_root = no
#	hide_from = yes
#	
#	is_triggered_only = yes
#	
#	has_dlc = "Jade Dragon"
#
#   trigger = {
#			OR = {
#				has_global_flag = elven_empire_has_fallen
#				has_global_flag = dwarven_empire_has_fallen
#				has_global_flag = dark_elven_empire_has_fallen
#				has_global_flag = dark_dwarven_empire_has_fallen
#				has_global_flag = cathrian_empire_has_fallen
#			}
#			NOT = {
#			    has_global_flag = rise_of_otherwordlen_pretender
#			}
#			controls_religion = yes # Let it happen for the Pope. He's always around.
#		}
#   }
#
#   immediate = {
#		ROOT = { character_event = { id = EADOAD.2 } #Spawns an otherworlden adventurer... }
#		set_global_flag = rise_of_otherwordlen_pretender
#   }
#}

#A wild adventurer appears!
character_event = {
	id = EADOAD.2
	hide_window = yes
	religion = catholic
	min_age = 16
	is_triggered_only = yes
	
	has_dlc = "Jade Dragon"
	
	trigger = {
		OR = {
			has_global_flag = elven_empire_has_fallen
			has_global_flag = dwarven_empire_has_fallen
			has_global_flag = dark_elven_empire_has_fallen
			has_global_flag = dark_dwarven_empire_has_fallen
			has_global_flag = cathrian_empire_has_fallen
			has_global_flag = orcish_horde_has_fallen
		}
		NOT = {
		    has_global_flag = rise_of_otherwordlen_pretender
		}
		controls_religion = yes # Let it happen for the Pope. He's always around.
    }

    immediate = {
        set_global_flag = rise_of_otherwordlen_pretender
    	save_event_target_as = that_fgt_in_tiara
    	if = {
			limit = { 
				has_global_flag = elven_empire_has_fallen
			}
			random_list = {
    			1 = {
				    create_character = { #Elven Prince
						age = 27
						random_traits = yes
						female = no
						religion = elven
						culture = high_elven
						dynasty = actually_culture
						trait = brilliant_strategist
						martial = 10
						flag = elven_prince
						historical = yes
					}
				}
				1 = {
			    	create_character = { #Elven Princess
						age = 27
						random_traits = yes
						female = yes
						religion = elven
						culture = high_elven
						dynasty = actually_culture
						trait = brilliant_strategist
						martial = 10
						flag = elven_princess
						historical = yes
					}
				}
				1 = {
				    create_character = { #Blood Elven Prince
						age = 27
						random_traits = yes
						female = no
						religion = elven_heresy
						culture = blood_elven
						dynasty = actually_culture
						trait = brilliant_strategist
						martial = 10
						flag = blood_elven_prince
						historical = yes
					}
				}
				1 = {
				    create_character = { #Blood Elven Princess
						age = 27
						random_traits = yes
						female = yes
						religion = elven_heresy
						culture = blood_elven
						dynasty = actually_culture
						trait = brilliant_strategist
						martial = 10
						flag = blood_elven_princess
						historical = yes
					}
				}
			}
			new_character = {
				change_martial = 7
				add_trait = ambitious
				add_trait = brave
				random_list = {
					33 = {
						trigger = {
							can_have_more_leadership_traits = yes
							NOT = { trait = inspiring_leader }
						}
						add_trait = inspiring_leader
					}
					33 = {
						trigger = {
							can_have_more_leadership_traits = yes
							NOT = { trait = organizer }
						}
						add_trait = organizer
					}
					33 = {
						trigger = {
							can_have_more_leadership_traits = yes
							NOT = { trait = siege_leader }
						}
						add_trait = siege_leader
					}
				}
				set_character_flag = is_otherworled_adventurer
				save_event_target_as = otherworled_adventurer
				save_event_target_as = the_otherworled_adventurer #loc based on what flag this target has
				wealth = 200
				log = "Other World Logging:"
				log = "[This.GetFullName] ID [This.GetID] is the Elven Adventurer"
				character_event = { id = EADOAD.3 } #Create title and pick target to notify
			}
		}
		else_if = {
		    limit = { 
				has_global_flag = dwarven_empire_has_fallen
			}
				create_character = { #Dwarven warrior
				age = 27
				random_traits = yes
				female = no
				religion = dwarven
				culture = dwarven_dawi
				dynasty = actually_culture
				trait = brilliant_strategist
				martial = 10
				flag = dwarven_warrior
				historical = yes
			}
			new_character = {
				change_martial = 7
				add_trait = ambitious
				add_trait = brave
				random_list = {
					33 = {
						trigger = {
							can_have_more_leadership_traits = yes
							NOT = { trait = inspiring_leader }
						}
						add_trait = inspiring_leader
					}
					33 = {
						trigger = {
							can_have_more_leadership_traits = yes
							NOT = { trait = organizer }
						}
						add_trait = organizer
					}
					33 = {
						trigger = {
							can_have_more_leadership_traits = yes
							NOT = { trait = siege_leader }
						}
						add_trait = siege_leader
					}
				}
				set_character_flag = is_otherworled_adventurer
				save_event_target_as = otherworled_adventurer
				save_event_target_as = the_otherworled_adventurer #loc based on what flag this target has
				wealth = 200
				log = "Other World Logging:"
				log = "[This.GetFullName] ID [This.GetID] is the Otherworlden Adventurer"
				character_event = { id = EADOAD.3 } #Create title and pick target to notify
			}
		}
		else_if = {
		    limit = { 
				has_global_flag = dark_elven_empire_has_fallen
			}
			random_list = {
    			1 = {
				    	create_character = { #Dark Elven Prince
						age = 27
						random_traits = yes
						female = no
						religion = elven_tribunal
						culture = dark_elven
						dynasty = actually_culture
						trait = brilliant_strategist
						martial = 10
						flag = dark_elven_prince
						historical = yes
					}
				}
				1 = {
			    	create_character = { #Dark Elven Princess
						age = 27
						random_traits = yes
						female = yes
						religion = elven_tribunal
						culture = dark_elven
						dynasty = actually_culture
						trait = brilliant_strategist
						martial = 10
						flag = dark_elven_princess
						historical = yes
					}
				}
				1 = {
				    	create_character = { #Dark Elven Nomad Prince
						age = 27
						random_traits = yes
						female = no
						religion = elven_tribunal_heresy
						culture = dark_elven
						dynasty = actually_culture
						trait = brilliant_strategist
						martial = 10
						flag = dark_elven_nomad_prince
						historical = yes
					}
				}
				1 = {
			    	create_character = { #Dark Elven Nomad Princess
						age = 27
						random_traits = yes
						female = yes
						religion = elven_tribunal_heresy
						culture = dark_elven
						dynasty = actually_culture
						trait = brilliant_strategist
						martial = 10
						flag = dark_elven_nomad_princess
						historical = yes
					}
				}
			}
			new_character = {
				change_martial = 7
				add_trait = ambitious
				add_trait = brave
				random_list = {
					33 = {
						trigger = {
							can_have_more_leadership_traits = yes
							NOT = { trait = inspiring_leader }
						}
						add_trait = inspiring_leader
					}
					33 = {
						trigger = {
							can_have_more_leadership_traits = yes
							NOT = { trait = organizer }
						}
						add_trait = organizer
					}
					33 = {
						trigger = {
							can_have_more_leadership_traits = yes
							NOT = { trait = siege_leader }
						}
						add_trait = siege_leader
					}
				}
				set_character_flag = is_otherworled_adventurer
				save_event_target_as = otherworled_adventurer
				save_event_target_as = the_otherworled_adventurer #loc based on what flag this target has
				wealth = 200
				log = "Other World Logging:"
				log = "[This.GetFullName] ID [This.GetID] is the Dark Elven Adventurer"
				character_event = { id = EADOAD.7 } #Create title and pick target to notify
			}
		}
		else_if = {
		    limit = { 
				has_global_flag = dark_dwarven_empire_has_fallen
			}
			random_list = {
				1 = {
					create_character = { #Dark Dwarven Warrior
					age = 27
					random_traits = yes
					female = no
					religion = dwarven_dwemer
					culture = dark_dwarven
					dynasty = actually_culture
					trait = brilliant_strategist
					martial = 10
					flag = dark_dwarven_warrior
					historical = yes
					}
				}
				1 = {
					create_character = { #Dark Dwarven (Chaos) Warrior
					age = 27
					random_traits = yes
					female = no
					religion = dwarven_dwemer_heresy_hashut
					culture = dark_dwarven
					dynasty = actually_culture
					trait = brilliant_strategist
					martial = 10
					flag = dark_dwarven_warrior
					historical = yes
					}
				}
			}
			new_character = {
				change_martial = 7
				add_trait = ambitious
				add_trait = brave
				random_list = {
					33 = {
						trigger = {
							can_have_more_leadership_traits = yes
							NOT = { trait = inspiring_leader }
						}
						add_trait = inspiring_leader
					}
					33 = {
						trigger = {
							can_have_more_leadership_traits = yes
							NOT = { trait = organizer }
						}
						add_trait = organizer
					}
					33 = {
						trigger = {
							can_have_more_leadership_traits = yes
							NOT = { trait = siege_leader }
						}
						add_trait = siege_leader
					}
				}
				set_character_flag = is_otherworled_adventurer
				save_event_target_as = otherworled_adventurer
				save_event_target_as = the_otherworled_adventurer #loc based on what flag this target has
				wealth = 200
				log = "Other World Logging:"
				log = "[This.GetFullName] ID [This.GetID] is the Otherworlden Adventurer"
				character_event = { id = EADOAD.3 } #Create title and pick target to notify
			}
		}
		else_if = {
		    limit = { 
				has_global_flag = cathrian_empire_has_fallen
			}
			random_list = {
    			1 = {
				    	create_character = { #Cat Folk Noble
						age = 27
						random_traits = yes
						female = no
						religion = cat_folk_religion
						culture = cat_folk
						dynasty = actually_culture
						trait = brilliant_strategist
						martial = 10
						flag = cathrian_nobleman
						historical = yes
					}
				}
				1 = {
			    	create_character = { #Cat Folk Noble Women
						age = 27
						random_traits = yes
						female = yes
						religion = cat_folk_religion
						culture = cat_folk
						dynasty = actually_culture
						trait = brilliant_strategist
						martial = 10
						flag = cathrian_noblewoman
						historical = yes
					}
				}
			}
			new_character = {
				change_martial = 7
				add_trait = ambitious
				add_trait = brave
				random_list = {
					33 = {
						trigger = {
							can_have_more_leadership_traits = yes
							NOT = { trait = inspiring_leader }
						}
						add_trait = inspiring_leader
					}
					33 = {
						trigger = {
							can_have_more_leadership_traits = yes
							NOT = { trait = organizer }
						}
						add_trait = organizer
					}
					33 = {
						trigger = {
							can_have_more_leadership_traits = yes
							NOT = { trait = siege_leader }
						}
						add_trait = siege_leader
					}
				}
				set_character_flag = is_otherworled_adventurer
				save_event_target_as = otherworled_adventurer
				save_event_target_as = the_otherworled_adventurer #loc based on what flag this target has
				wealth = 200
				log = "Other World Logging:"
				log = "[This.GetFullName] ID [This.GetID] is the Cathrian Adventurer"
				character_event = { id = EADOAD.7 } #Create title and pick target to notify
			}
		}
		else_if = {
		    limit = { 
				has_global_flag = orcish_horde_has_fallen
			}
			random_list = {
    			1 = {
				    	create_character = { #Oruk
						age = 27
						random_traits = yes
						female = no
						religion = orc_religion
						culture = oruk
						dynasty = actually_culture
						trait = brilliant_strategist
						martial = 10
						flag = oruk_warchief
						historical = yes
					}
				}
				1 = {
			    	create_character = { #Oruk Hai
						age = 27
						random_traits = yes
						female = no
						religion = orc_religion_dark_lord
						culture = oruk_hai
						dynasty = actually_culture
						trait = brilliant_strategist
						martial = 10
						flag = oruk_hai_warchief
						historical = yes
					}
				}
			}
			new_character = {
				change_martial = 7
				add_trait = ambitious
				add_trait = brave
				random_list = {
					33 = {
						trigger = {
							can_have_more_leadership_traits = yes
							NOT = { trait = inspiring_leader }
						}
						add_trait = inspiring_leader
					}
					33 = {
						trigger = {
							can_have_more_leadership_traits = yes
							NOT = { trait = organizer }
						}
						add_trait = organizer
					}
					33 = {
						trigger = {
							can_have_more_leadership_traits = yes
							NOT = { trait = siege_leader }
						}
						add_trait = siege_leader
					}
				}
				set_character_flag = is_otherworled_adventurer
				save_event_target_as = otherworled_adventurer
				save_event_target_as = the_otherworled_adventurer #loc based on what flag this target has
				wealth = 200
				log = "Other World Logging:"
				log = "[This.GetFullName] ID [This.GetID] is the Otherworlden Adventurer"
				character_event = { id = EADOAD.3 } #Create title and pick target to notify
			}
		}

		#News event, informed about adventurer
		any_player = {
			limit = {
				is_within_diplo_range = ROOT
			}
			narrative_event = { id = EADOAD.13 days = 1 }
		}
    }
}
#Setup the adventurer's titles for Europe and warn target
character_event = {
	id = EADOAD.3

	hide_window = yes

	is_triggered_only = yes
	capable_only = yes
	prisoner = no
	
	trigger = {
		NOT = {
			has_game_rule = {
				name = adventurers
				value = none
			}
		}
	}

	immediate = {
		###Picks worst and overwrites as better targets are found
		log = "Other World Logging:"
		#Worst case, pick any ruler in the invasion region
		random_independent_ruler = {
			limit = {
			    any_realm_province = {
					OR = {
					    region = world_europe_west
						region = world_europe_north
						region = world_europe_south
						region = world_europe_east
					}
				}
				in_revolt = no
#				is_within_diplo_range = event_target:that_fgt_in_tiara
				is_landed = yes
				is_nomadic = no
				higher_tier_than = BARON
			}
			save_event_target_as = otherworlden_adventurer_target
			log = "[otherworlden_adventurer_target.GetFullName] ID [otherworlden_adventurer_target.GetID] is the Elven Adventurer's Worst Case Target."
		}
		#Avoid WP target, pick a normal Count ruler
		random_independent_ruler = {
			limit = {
				any_realm_province = {
					OR = {
					    region = world_europe_west
						region = world_europe_north
						region = world_europe_south
						region = world_europe_east
					}
				}
				NOT = { event_target:that_fgt_in_tiara = { character = PREV } }
				in_revolt = no
#				is_within_diplo_range = event_target:that_fgt_in_tiara
				is_landed = yes
				is_nomadic = no
				higher_tier_than = BARON
			}
			save_event_target_as = otherworlden_adventurer_target
			log = "[otherworlden_adventurer_target.GetFullName] ID [otherworlden_adventurer_target.GetID] is the Elven Adventurer's  Worst Case Target."
		}
		#A a duke with a decent amount of land
		random_independent_ruler = {
			limit = {
				any_realm_province = {
					OR = {
					    region = world_europe_west
						region = world_europe_north
						region = world_europe_south
						region = world_europe_east
					}
				}
				NOT = { event_target:that_fgt_in_tiara = { character = PREV } }
				in_revolt = no
#				is_within_diplo_range = event_target:that_fgt_in_tiara
				is_landed = yes
				is_nomadic = no
    			higher_tier_than = COUNT
				num_of_count_titles_in_realm = 5
			}
			save_event_target_as = otherworlden_adventurer_target
			log = "[otherworlden_adventurer_target.GetFullName] ID [otherworlden_adventurer_target.GetID] is the Elven Adventurer's Duke Target."
		}
		#A king with plenty of land
		random_independent_ruler = {
			limit = {
				any_realm_province = {
					OR = {
					    region = world_europe_west
						region = world_europe_north
						region = world_europe_south
						region = world_europe_east
					}
				}
				NOT = { event_target:that_fgt_in_tiara = { character = PREV } }
				in_revolt = no
#				is_within_diplo_range = event_target:that_fgt_in_tiara
				is_landed = yes
				is_nomadic = no
    			higher_tier_than = DUKE
				num_of_count_titles_in_realm = 15
			}
			save_event_target_as = otherworlden_adventurer_target
			log = "[otherworlden_adventurer_target.GetFullName] ID [otherworlden_adventurer_target.GetID] is the Elven Adventurer's King Target."
		}
		#An emperor with lots of land
		random_independent_ruler = {
			limit = {
				any_realm_province = {
					OR = {
					    region = world_europe_west
						region = world_europe_north
						region = world_europe_south
						region = world_europe_east
					}
				}
				NOT = { event_target:that_fgt_in_tiara = { character = PREV } }
				in_revolt = no
#				is_within_diplo_range = event_target:that_fgt_in_tiara
				is_landed = yes
				is_nomadic = no
    			higher_tier_than = KING
				num_of_count_titles_in_realm = 30
			}
			save_event_target_as = otherworlden_adventurer_target
			log = "[otherworlden_adventurer_target.GetFullName] ID [otherworlden_adventurer_target.GetID] is the Elven Adventurer's Emperor Target."
		}

		#!!!If still no target then stop it all!!!
		if = {
			limit = { NOT = { event_target:otherworlden_adventurer_target = { always = yes } } }
			death = { death_reason = death_missing }
			log = "[This.GetFullName] ID [This.GetID] is the Elven Adventurer and could not find a target therefore he is getting removed."
			break = yes
		}
		
		log = "[otherworlden_adventurer_target.GetFullName] ID [otherworlden_adventurer_target.GetID] is the Elven Adventurer's Final Target."

		#Create title after finding target so if all goes wrong don't need to delete title
		create_title = {
			tier = EMPEROR
			temporary = no
			landless = yes
			custom_created = yes
			culture = ROOT
			name = "CLAIMANT_ADVENTURE"
			holder = ROOT
			base_title = THIS
			short_name = yes
		}
		new_title = { save_event_target_as = adventurers_title }
		set_defacto_liege = ROOT

		trigger_switch = {
			on_trigger = has_character_flag
			elven_prince = {
				create_character = {
					age = 24
					random_traits = yes
					female = yes
					religion = elven
					culture = high_elven
					historical = yes
				}
				new_character = {
					add_spouse = ROOT
					create_character = {
						age = 6
						random_traits = yes
						female = 50
						religion = elven
						culture = high_elven
						genetic_father = ROOT
						genetic_mother = PREV
						historical = yes
					}
					new_character = {
						dynasty = ROOT
						set_father = ROOT
						set_mother = PREV
					}
					create_character = {
						age = 6
						random_traits = yes
						female = 50
						religion = elven
						culture = high_elven
						genetic_father = ROOT
						genetic_mother = PREV
						historical = yes
					}
					new_character = {
						dynasty = ROOT
						set_father = ROOT
						set_mother = PREV
					}
				}
				set_global_flag = elven_prince_host
			}
			elven_princess = {
				create_character = {
					age = 24
					random_traits = yes
					female = no
					religion = elven
					culture = high_elven
					historical = yes
				}
				new_character = {
					add_spouse = ROOT
					create_character = {
						age = 6
						random_traits = yes
						female = 50
						religion = elven
						culture = high_elven
						genetic_father = ROOT
						genetic_mother = PREV
						historical = yes
					}
					new_character = {
						dynasty = ROOT
						set_father = ROOT
						set_mother = PREV
					}
					create_character = {
						age = 6
						random_traits = yes
						female = 50
						religion = elven
						culture = high_elven
						genetic_father = ROOT
						genetic_mother = PREV
						historical = yes
					}
					new_character = {
						dynasty = ROOT
						set_father = ROOT
						set_mother = PREV
					}
				}
				set_global_flag = elven_prince_host
			}
			blood_elven_prince = {
				create_character = {
					age = 24
					random_traits = yes
					female = yes
					religion = elven_heresy
					culture = blood_elven
					historical = yes
				}
				new_character = {
					add_spouse = ROOT
					create_character = {
						age = 6
						random_traits = yes
						female = 50
						religion = elven_heresy
						culture = blood_elven
						genetic_father = ROOT
						genetic_mother = PREV
						historical = yes
					}
					new_character = {
						dynasty = ROOT
						set_father = ROOT
						set_mother = PREV
					}
					create_character = {
						age = 6
						random_traits = yes
						female = 50
						religion = elven_heresy
						culture = blood_elven
						genetic_father = ROOT
						genetic_mother = PREV
						historical = yes
					}
					new_character = {
						dynasty = ROOT
						set_father = ROOT
						set_mother = PREV
					}
				}
				set_global_flag = blood_elven_prince_host
			}
			blood_elven_princess = {
				create_character = {
					age = 24
					random_traits = yes
					female = no
					religion = elven_heresy
					culture = blood_elven
					historical = yes
				}
				new_character = {
					add_spouse = ROOT
					create_character = {
						age = 6
						random_traits = yes
						female = 50
						religion = elven_heresy
						culture = blood_elven
						genetic_father = ROOT
						genetic_mother = PREV
						historical = yes
					}
					new_character = {
						dynasty = ROOT
						set_father = ROOT
						set_mother = PREV
					}
					create_character = {
						age = 6
						random_traits = yes
						female = 50
						religion = elven_heresy
						culture = blood_elven
						genetic_father = ROOT
						genetic_mother = PREV
						historical = yes
					}
					new_character = {
						dynasty = ROOT
						set_father = ROOT
						set_mother = PREV
					}
				}
				set_global_flag = blood_elven_prince_host
			}
			dwarven_warrior = {
				create_character = {
					age = 24
					random_traits = yes
					female = yes
					religion = dwarven
					culture = dwarven_dawi
					historical = yes
				}
				new_character = {
					add_spouse = ROOT
					create_character = {
						age = 6
						random_traits = yes
						female = 50
						religion = dwarven
						culture = dwarven_dawi
						genetic_father = ROOT
						genetic_mother = PREV
						historical = yes
					}
					new_character = {
						dynasty = ROOT
						set_father = ROOT
						set_mother = PREV
					}
					create_character = {
						age = 6
						random_traits = yes
						female = 50
						religion = dwarven
						culture = dwarven_dawi
						genetic_father = ROOT
						genetic_mother = PREV
						historical = yes
					}
					new_character = {
						dynasty = ROOT
						set_father = ROOT
						set_mother = PREV
					}
				}
				set_global_flag = dwarven_warrior_host
			}
		}
		clr_character_flag = elven_prince
		clr_character_flag = elven_princess
		clr_character_flag = dwarven_warrior
		set_global_flag = adventurer_in_europe
		prestige = 500

		#Warn the target of the incoming invasion
		event_target:otherworlden_adventurer_target = { narrative_event = { id = EADOAD.4 days = 5 } }
	}
}
#Informed an adventurer has picked you as a target
narrative_event = {
	id = EADOAD.4
	title = EVT_TITLE_EADOAD_4
	border = GFX_event_normal_frame_war
	
	desc = {
       trigger = { has_global_flag = elven_prince_host }
       text = EVT_DESC_EADOAD_4_A
       picture = GFX_evt_elven_adventurer
    }
	
	desc = {
       trigger = { has_global_flag = dwarven_warrior_host }
       text = EVT_DESC_EADOAD_4_B
       picture = GFX_evt_dwarven_adventurer
    }
	
	desc = {
       trigger = { has_global_flag = dark_elven_prince_host }
       text = EVT_DESC_EADOAD_4_C
       picture = GFX_evt_elven_adventurer
    }
	
	desc = {
       trigger = { has_global_flag = dark_dwarven_warrior_host }
       text = EVT_DESC_EADOAD_4_D
       picture = GFX_evt_dwarven_adventurer
    }
	
	desc = {
       trigger = { has_global_flag = cathrian_nobleman_host }
       text = EVT_DESC_EADOAD_4_E
       picture = GFX_evt_battle_byzantine
    }
	desc = {
       trigger = { has_global_flag = blood_elven_prince_host }
       text = EVT_DESC_EADOAD_4_F
       picture = GFX_evt_blood_elven_hero
    }

	is_triggered_only = yes
	hide_new = yes

	option = {
		name = EVT_OPTA_JD_60202
		#custom_tooltip = { text = rebel_general_will_invade_tt }
		hidden_effect = { 
		    character_event = { id = EADOAD.5 days = 10 random = 5 } 	
		}
	}
}
#Spawn the troops and start the war
character_event = {
	id = EADOAD.5
	hide_window = yes
	
	is_triggered_only = yes
	

	trigger = { event_target:otherworled_adventurer = { is_alive = yes } }

	fail_trigger_effect = { character_event = { id = EADOAD.6 } } #inform target the general died

	immediate = {
		event_target:otherworled_adventurer = { 
			war = {
				casus_belli = otherworlden_adventurer_submission
				target = event_target:otherworlden_adventurer_target
			}

			####### Spawn troop effects taken from JD.30040, for the Elven Adventurer he has less troops but better generals based on his martial
			### To manipulate the troop spawning for specific situations modify the parameter valiables (china_war_troop_quantity, china_war_troop_quality, china_war_target_match_mult, and china_war_minimum_commander_martial) after the following block.
			set_variable = {
				which = china_war_troop_quantity
				value = 10
				# 10 regiments of ~500 units
			}
			set_variable = {
				which = china_war_target_match_mult
				value = 1
			}
			set_variable = {
				which = china_war_troop_quality
				value = 3
				# Value between 1-7
			}
			set_variable = {
				which = china_war_minimum_commander_martial
				value = 14
			}
			###

			# Increase min martial by 1/4 of the Elven Adventurer's martial
			export_to_variable = { which = "rebel_general_martial" value = martial }
			divide_variable = { which = "rebel_general_martial" value = 4 }
			change_variable = { which = "china_war_minimum_commander_martial" which = "rebel_general_martial" }
			# Manipulate the parameter variables dependent on the current century.
			china_war_modify_variables_by_century_effect = yes
			
			### Match mult calculation against the opponents troops.
			export_to_variable = {
				which = china_temp_troop_calc
				value = realm_levies_plus_allies
				who = FROM
			}
			
			divide_variable = {
				which = china_temp_troop_calc
				value = 500
			}
			
			multiply_variable = {
				which = china_temp_troop_calc
				which = china_war_target_match_mult
			}
			
			change_variable = {
				which = china_war_troop_quantity
				which = china_temp_troop_calc
			}
			###
			
			any_courtier_or_vassal = { # Copy the variable to all courtiers and vassals
				set_variable = {
					which = china_war_minimum_commander_martial
					which = PREV
				}
			}
			
			if = {
				limit = {
					NOT = {
						any_courtier_or_vassal = {
							count = 5
							martial = china_war_minimum_commander_martial
						}
					}
				} # Not enough proficient commanders, create more
				# Custom effect utilizes china_war_minimum_commander_martial variable
				china_spawn_commander_effect = yes
				china_spawn_commander_effect = yes
				china_spawn_commander_effect = yes
				china_spawn_commander_effect = yes
				china_spawn_commander_effect = yes
			}
			
			
			if = {
				limit = { 
					has_global_flag = adventurer_in_europe
				}
				306 = { # Rostok
					save_event_target_as = spawn_province
				}
				spawn_fleet = { #Just in case
					province = closest # closest sea zone
					disband_on_peace = yes
					troops =
					{
						galleys = { 600 600 }
					}
			    }
				clr_global_flag = adventurer_in_europe
			}
			else_if = {
				limit = { 
					has_global_flag = adventurer_in_asia
				}
				641 = { # Hormuz
					save_event_target_as = spawn_province
				}
				spawn_fleet = { #Just in case
					province = closest # closest sea zone
					disband_on_peace = yes
					troops =
					{
						galleys = { 600 600 }
					}
			    }
				clr_global_flag = adventurer_in_asia
			}
			else_if = {
				limit = { 
					has_global_flag = adventurer_in_africa
				}
				817 = { # Tunis
					save_event_target_as = spawn_province
				}
				spawn_fleet = { #Just in case
					province = closest # closest sea zone
					disband_on_peace = yes
					troops =
					{
						galleys = { 600 600 }
					}
			    }
				clr_global_flag = adventurer_in_africa
			}
			
			china_war_spawn_troops_no_disband_effect = yes
			# Requires the current things to function properly:
			# event_target:spawn_province
			# variable: china_war_troop_quality
			# variable: china_war_troop_quantity
		}
	}
}

#Inform Otherworlden Adventurer died so no invasion
character_event = {
	id = EADOAD.6
	desc = EVT_DESC_EADOAD_6
	picture = GFX_evt_elven_adventurer
	border = GFX_event_normal_frame_war

	is_triggered_only = yes

	immediate = {
		event_target:adventurers_title = {
			holder_scope = { 
				any_courtier = { death = { death_reason = death_missing } }
			}
			activate_title = { title = THIS status = no }
			destroy_landed_title = THIS
		}
		clr_global_flag = rise_of_otherwordlen_pretender
		clr_global_flag = elven_prince_host
		clr_global_flag = dwarven_warrior_host
		clr_global_flag = dark_dwarven_warrior_host
		clr_global_flag = dark_elven_prince_host
		clr_global_flag = cathrian_nobleman_host
		clr_global_flag = blood_elven_prince_host
	}

	option = {
		name = EVT_OPTA_EADOAD_6
	}
}

#Setup the adventurer's titles for Middle East and warn target
character_event = {
	id = EADOAD.7

	hide_window = yes

	is_triggered_only = yes
	capable_only = yes
	prisoner = no
	
	trigger = {
		NOT = {
			has_game_rule = {
				name = adventurers
				value = none
			}
		}
	}

	immediate = {
		###Picks worst and overwrites as better targets are found
		log = "Other World Logging:"
		#Worst case, pick any ruler in the invasion region
		random_independent_ruler = {
			limit = {
				OR = {
				    region = world_middle_east_jerusalem
					region = world_middle_east_arabia
					region = world_persia
					region = world_asia_minor
				}
				in_revolt = no
#				is_within_diplo_range = event_target:that_fgt_in_tiara
				is_landed = yes
				is_nomadic = no
				higher_tier_than = BARON
			}
			save_event_target_as = otherworlden_adventurer_target
			log = "[otherworlden_adventurer_target.GetFullName] ID [otherworlden_adventurer_target.GetID] is the Elven Adventurer's Worst Case Target."
		}
		#Avoid WP target, pick a normal Count ruler
		random_independent_ruler = {
			limit = {
			    any_realm_province = {
					OR = {
					    region = world_middle_east_jerusalem
						region = world_middle_east_arabia
						region = world_persia
						region = world_asia_minor
					}
				}
				NOT = { event_target:that_fgt_in_tiara = { character = PREV } }
				in_revolt = no
#				is_within_diplo_range = event_target:that_fgt_in_tiara
				is_landed = yes
				is_nomadic = no
				higher_tier_than = BARON
			}
			save_event_target_as = otherworlden_adventurer_target
			log = "[otherworlden_adventurer_target.GetFullName] ID [otherworlden_adventurer_target.GetID] is the Elven Adventurer's  Worst Case Target."
		}
		#A a duke with a decent amount of land
		random_independent_ruler = {
			limit = {
				any_realm_province = {
					OR = {
					    region = world_middle_east_jerusalem
						region = world_middle_east_arabia
						region = world_persia
						region = world_asia_minor
					}
				}
				NOT = { event_target:that_fgt_in_tiara = { character = PREV } }
				in_revolt = no
#				is_within_diplo_range = event_target:that_fgt_in_tiara
				is_landed = yes
				is_nomadic = no
    			higher_tier_than = COUNT
				num_of_count_titles_in_realm = 5
			}
			save_event_target_as = otherworlden_adventurer_target
			log = "[otherworlden_adventurer_target.GetFullName] ID [otherworlden_adventurer_target.GetID] is the Elven Adventurer's Duke Target."
		}
		#A king with plenty of land
		random_independent_ruler = {
			limit = {
				any_realm_province = {
					OR = {
					    region = world_middle_east_jerusalem
						region = world_middle_east_arabia
						region = world_persia
						region = world_asia_minor
					}
				}
				NOT = { event_target:that_fgt_in_tiara = { character = PREV } }
				in_revolt = no
#				is_within_diplo_range = event_target:that_fgt_in_tiara
				is_landed = yes
				is_nomadic = no
    			higher_tier_than = DUKE
				num_of_count_titles_in_realm = 15
			}
			save_event_target_as = otherworlden_adventurer_target
			log = "[otherworlden_adventurer_target.GetFullName] ID [otherworlden_adventurer_target.GetID] is the Elven Adventurer's King Target."
		}
		#An emperor with lots of land
		random_independent_ruler = {
			limit = {
				any_realm_province = {
					OR = {
					    region = world_middle_east_jerusalem
						region = world_middle_east_arabia
						region = world_persia
						region = world_asia_minor
					}
				}
				NOT = { event_target:that_fgt_in_tiara = { character = PREV } }
				in_revolt = no
#				is_within_diplo_range = event_target:that_fgt_in_tiara
				is_landed = yes
				is_nomadic = no
    			higher_tier_than = KING
				num_of_count_titles_in_realm = 30
			}
			save_event_target_as = otherworlden_adventurer_target
			log = "[otherworlden_adventurer_target.GetFullName] ID [otherworlden_adventurer_target.GetID] is the Elven Adventurer's Emperor Target."
		}

		#!!!If still no target then stop it all!!!
		if = {
			limit = { NOT = { event_target:otherworlden_adventurer_target = { always = yes } } }
			death = { death_reason = death_missing }
			log = "[This.GetFullName] ID [This.GetID] is the Elven Adventurer and could not find a target therefore he is getting removed."
			break = yes
		}
		
		log = "[otherworlden_adventurer_target.GetFullName] ID [otherworlden_adventurer_target.GetID] is the Elven Adventurer's Final Target."

		#Create title after finding target so if all goes wrong don't need to delete title
		create_title = {
			tier = EMPEROR
			temporary = no
			landless = yes
			custom_created = yes
			culture = ROOT
			name = "CLAIMANT_ADVENTURE"
			holder = ROOT
			base_title = THIS
			short_name = yes
		}
		new_title = { save_event_target_as = adventurers_title }
		set_defacto_liege = ROOT

		trigger_switch = {
			on_trigger = has_character_flag
			dark_elven_prince = {
				create_character = {
					age = 24
					random_traits = yes
					female = yes
					religion = elven_tribunal
					culture = dark_elven
					historical = yes
				}
				new_character = {
					add_spouse = ROOT
					create_character = {
						age = 6
						random_traits = yes
						female = 50
						religion = elven_tribunal
						culture = dark_elven
						genetic_father = ROOT
						genetic_mother = PREV
						historical = yes
					}
					new_character = {
						dynasty = ROOT
						set_father = ROOT
						set_mother = PREV
					}
					create_character = {
						age = 6
						random_traits = yes
						female = 50
						religion = elven_tribunal
						culture = dark_elven
						genetic_father = ROOT
						genetic_mother = PREV
						historical = yes
					}
					new_character = {
						dynasty = ROOT
						set_father = ROOT
						set_mother = PREV
					}
				}
				set_global_flag = dark_elven_prince_host
			}
			dark_elven_princess = {
				create_character = {
					age = 24
					random_traits = yes
					female = no
					religion = elven_tribunal
					culture = dark_elven
					historical = yes
				}
				new_character = {
					add_spouse = ROOT
					create_character = {
						age = 6
						random_traits = yes
						female = 50
						religion = elven_tribunal
						culture = dark_elven
						genetic_father = ROOT
						genetic_mother = PREV
						historical = yes
					}
					new_character = {
						dynasty = ROOT
						set_father = ROOT
						set_mother = PREV
					}
					create_character = {
						age = 6
						random_traits = yes
						female = 50
						religion = elven_tribunal
						culture = dark_elven
						genetic_father = ROOT
						genetic_mother = PREV
						historical = yes
					}
					new_character = {
						dynasty = ROOT
						set_father = ROOT
						set_mother = PREV
					}
				}
				set_global_flag = dark_elven_prince_host
			}
			dark_dwarven_warrior = {
				create_character = {
					age = 24
					random_traits = yes
					female = yes
					religion = dwarven_dwemer
					culture = dark_dwarven
					historical = yes
				}
				new_character = {
					add_spouse = ROOT
					create_character = {
						age = 6
						random_traits = yes
						female = 50
						religion = dwarven_dwemer
						culture = dark_dwarven
						genetic_father = ROOT
						genetic_mother = PREV
						historical = yes
					}
					new_character = {
						dynasty = ROOT
						set_father = ROOT
						set_mother = PREV
					}
					create_character = {
						age = 6
						random_traits = yes
						female = 50
						religion = dwarven_dwemer
						culture = dark_dwarven
						genetic_father = ROOT
						genetic_mother = PREV
						historical = yes
					}
					new_character = {
						dynasty = ROOT
						set_father = ROOT
						set_mother = PREV
					}
				}
				set_global_flag = dark_dwarven_warrior_host
			}
		}
		clr_character_flag = dark_elven_prince
		clr_character_flag = dark_elven_princess
		clr_character_flag = dark_dwarven_warrior
		set_global_flag = adventurer_in_asia
		prestige = 500

		#Warn the target of the incoming invasion
		event_target:otherworlden_adventurer_target = { narrative_event = { id = EADOAD.4 days = 5 } }
	}
}

#Setup the adventurer's titles for Africa and warn target
character_event = {
	id = EADOAD.8

	hide_window = yes

	is_triggered_only = yes
	capable_only = yes
	prisoner = no
	
	trigger = {
		NOT = {
			has_game_rule = {
				name = adventurers
				value = none
			}
		}
	}

	immediate = {
		###Picks worst and overwrites as better targets are found
		log = "Other World Logging:"
		#Worst case, pick any ruler in the invasion region
		random_independent_ruler = {
			limit = {
			    any_realm_province = {
					region = world_africa
				}
				in_revolt = no
				is_within_diplo_range = event_target:that_fgt_in_tiara
				is_landed = yes
				is_nomadic = no
				higher_tier_than = BARON
			}
			save_event_target_as = otherworlden_adventurer_target
			log = "[otherworlden_adventurer_target.GetFullName] ID [otherworlden_adventurer_target.GetID] is the Elven Adventurer's Worst Case Target."
		}
		#Avoid WP target, pick a normal Count ruler
		random_independent_ruler = {
			limit = {
				any_realm_province = {
					region = world_africa
				}
				NOT = { event_target:that_fgt_in_tiara = { character = PREV } }
				in_revolt = no
				is_within_diplo_range = event_target:that_fgt_in_tiara
				is_landed = yes
				is_nomadic = no
				higher_tier_than = BARON
			}
			save_event_target_as = otherworlden_adventurer_target
			log = "[otherworlden_adventurer_target.GetFullName] ID [otherworlden_adventurer_target.GetID] is the Elven Adventurer's  Worst Case Target."
		}
		#A a duke with a decent amount of land
		random_independent_ruler = {
			limit = {
				any_realm_province = {
					region = world_africa
				}
				NOT = { event_target:that_fgt_in_tiara = { character = PREV } }
				in_revolt = no
				is_within_diplo_range = event_target:that_fgt_in_tiara
				is_landed = yes
				is_nomadic = no
    			higher_tier_than = COUNT
				num_of_count_titles_in_realm = 5
			}
			save_event_target_as = otherworlden_adventurer_target
			log = "[otherworlden_adventurer_target.GetFullName] ID [otherworlden_adventurer_target.GetID] is the Elven Adventurer's Duke Target."
		}
		#A king with plenty of land
		random_independent_ruler = {
			limit = {
				any_realm_province = {
					region = world_africa
				}
				NOT = { event_target:that_fgt_in_tiara = { character = PREV } }
				in_revolt = no
				is_within_diplo_range = event_target:that_fgt_in_tiara
				is_landed = yes
				is_nomadic = no
    			higher_tier_than = DUKE
				num_of_count_titles_in_realm = 15
			}
			save_event_target_as = otherworlden_adventurer_target
			log = "[otherworlden_adventurer_target.GetFullName] ID [otherworlden_adventurer_target.GetID] is the Elven Adventurer's King Target."
		}
		#An emperor with lots of land
		random_independent_ruler = {
			limit = {
				any_realm_province = {
					region = world_africa
				}
				NOT = { event_target:that_fgt_in_tiara = { character = PREV } }
				in_revolt = no
				is_within_diplo_range = event_target:that_fgt_in_tiara
				is_landed = yes
				is_nomadic = no
    			higher_tier_than = KING
				num_of_count_titles_in_realm = 30
			}
			save_event_target_as = otherworlden_adventurer_target
			log = "[otherworlden_adventurer_target.GetFullName] ID [otherworlden_adventurer_target.GetID] is the Elven Adventurer's Emperor Target."
		}

		#!!!If still no target then stop it all!!!
		if = {
			limit = { NOT = { event_target:otherworlden_adventurer_target = { always = yes } } }
			death = { death_reason = death_missing }
			log = "[This.GetFullName] ID [This.GetID] is the Elven Adventurer and could not find a target therefore he is getting removed."
			break = yes
		}
		
		log = "[otherworlden_adventurer_target.GetFullName] ID [otherworlden_adventurer_target.GetID] is the Elven Adventurer's Final Target."

		#Create title after finding target so if all goes wrong don't need to delete title
		create_title = {
			tier = EMPEROR
			temporary = no
			landless = yes
			custom_created = yes
			culture = ROOT
			name = "CLAIMANT_ADVENTURE"
			holder = ROOT
			base_title = THIS
			short_name = yes
		}
		new_title = { save_event_target_as = adventurers_title }
		set_defacto_liege = ROOT

		trigger_switch = {
			on_trigger = has_character_flag
			cathrian_nobleman = {
				create_character = {
					age = 24
					random_traits = yes
					female = yes
					religion = cat_folk_religion
					culture = cat_folk
					historical = yes
				}
				new_character = {
					add_spouse = ROOT
					create_character = {
						age = 6
						random_traits = yes
						female = 50
						religion = cat_folk_religion
						culture = cat_folk
						genetic_father = ROOT
						genetic_mother = PREV
						historical = yes
					}
					new_character = {
						dynasty = ROOT
						set_father = ROOT
						set_mother = PREV
					}
					create_character = {
						age = 6
						random_traits = yes
						female = 50
						religion = cat_folk_religion
						culture = cat_folk
						genetic_father = ROOT
						genetic_mother = PREV
						historical = yes
					}
					new_character = {
						dynasty = ROOT
						set_father = ROOT
						set_mother = PREV
					}
				}
				set_global_flag = cathrian_nobleman_host
			}
			cathrian_noblewoman = {
				create_character = {
					age = 24
					random_traits = yes
					female = no
					religion = cat_folk_religion
					culture = cat_folk
					historical = yes
				}
				new_character = {
					add_spouse = ROOT
					create_character = {
						age = 6
						random_traits = yes
						female = 50
						religion = cat_folk_religion
						culture = cat_folk
						genetic_father = ROOT
						genetic_mother = PREV
						historical = yes
					}
					new_character = {
						dynasty = ROOT
						set_father = ROOT
						set_mother = PREV
					}
					create_character = {
						age = 6
						random_traits = yes
						female = 50
						religion = cat_folk_religion
						culture = cat_folk
						genetic_father = ROOT
						genetic_mother = PREV
						historical = yes
					}
					new_character = {
						dynasty = ROOT
						set_father = ROOT
						set_mother = PREV
					}
				}
				set_global_flag = cathrian_nobleman_host
			}
		}
		clr_character_flag = cathrian_nobleman
		clr_character_flag = cathrian_noblewoman
		set_global_flag = adventurer_in_africa
		prestige = 500

		#Warn the target of the incoming invasion
		event_target:otherworlden_adventurer_target = { narrative_event = { id = EADOAD.4 days = 5 } }
	}
}

#News Event: Inform adventurer won and founded Empire
narrative_event = {
	id = EADOAD.9
    title = EVT_TITLE_EADOAD_9
    desc = {
        trigger = { 
	        ROOT = { 
				is_earth_or_otherworlden_elven_culture = yes
            }
		}
        text = EVT_DESC_EADOAD_9_A
        picture = GFX_evt_elven_adventurer
    }
	
	desc = {
        trigger = { 
	        ROOT = { 
				is_earth_or_otherworlden_dwarven_culture = yes
            }
		}
        text = EVT_DESC_EADOAD_9_B
        picture = GFX_evt_dwarven_adventurer
    }
	
	desc = {
        trigger = { 
	        ROOT = { 
				is_earth_or_otherworlden_dark_elven_culture = yes
            }
		}
        text = EVT_DESC_EADOAD_9_C
        picture = GFX_evt_elven_adventurer
    }
	
	desc = {
        trigger = { 
	        ROOT = { 
				is_earth_or_otherworlden_dark_dwarven_culture = yes
            }
		}
        text = EVT_DESC_EADOAD_9_D
        picture = GFX_evt_dwarven_adventurer
    }
	
	desc = {
        trigger = { 
	        ROOT = { 
				is_earth_or_otherworlden_cat_folk_culture = yes
            }
		}
        text = EVT_DESC_EADOAD_9_E
        picture = GFX_evt_battle_byzantine
    }
	
	desc = {
        trigger = { 
	        ROOT = { 
				is_earth_or_otherworlden_oruk_culture = yes
            }
		}
        text = EVT_DESC_EADOAD_9_E
        picture = GFX_evt_battle_oruk
    }
    is_triggered_only = yes
	major = yes
	
	immediate = {
	    clr_global_flag = rise_of_otherwordlen_pretender
		if = {
		    limit = {
				ROOT = {
				    is_earth_or_otherworlden_elven_culture = yes
				}
			}
			clr_global_flag = elven_empire_has_fallen
			set_global_flag = elven_empire_landed
		}
		else_if = {
		    limit = {
				ROOT = {
				    is_earth_or_otherworlden_dwarven_culture = yes
				}
			}
			clr_global_flag = dwarven_empire_has_fallen
			set_global_flag = dwarven_empire_landed
		}
		else_if = {
		    limit = {
				ROOT = {
				    is_earth_or_otherworlden_dark_elven_culture = yes
				}
			}
			clr_global_flag = dark_elven_empire_has_fallen
			set_global_flag = dark_elven_empire_landed
		}
		else_if = {
		    limit = {
				ROOT = {
				    is_earth_or_otherworlden_dark_dwarven_culture = yes
				}
			}
			clr_global_flag = dark_dwarven_empire_has_fallen
			set_global_flag = dark_dwarven_empire_landed
		}
		else_if = {
		    limit = {
				ROOT = {
				    is_earth_or_otherworlden_cat_folk_culture = yes
				}
			}
			clr_global_flag = cathrian_empire_has_fallen
			set_global_flag = cat_folk_empire_landed
		}
		else_if = {
		    limit = {
				ROOT = {
				    is_earth_or_otherworlden_oruk_culture = yes
				}
			}
			clr_global_flag = orcish_horde_defeated
			set_global_flag = orcish_horde_landed
		}
	}

    option = {
        name = EVT_OPTA_EADOAD_9
		clr_global_flag = elven_prince_host
		clr_global_flag = dwarven_warrior_host
		clr_global_flag = dark_dwarven_warrior_host
		clr_global_flag = dark_elven_prince_host
		clr_global_flag = cathrian_nobleman_host
		clr_global_flag = blood_elven_prince_host
		clr_global_flag = oruk_warchief_host
    }
}

#News Event: Inform adventurer have lost
narrative_event = {
	id = EADOAD.10
    title = EVT_TITLE_EADOAD_10
    desc = EVTDESC_EADOAD_10
	picture = GFX_evt_elven_adventurer
    is_triggered_only = yes
	major = yes
	
	immediate = {
	    clr_global_flag = rise_of_otherwordlen_pretender
		clr_global_flag = elven_prince_host
		clr_global_flag = dwarven_warrior_host
		clr_global_flag = dark_dwarven_warrior_host
		clr_global_flag = dark_elven_prince_host
		clr_global_flag = cathrian_nobleman_host
		clr_global_flag = blood_elven_prince_host
		clr_global_flag = oruk_warchief_host
	}

    option = {
        name = EVT_OPTA_EADOAD_10
    }
}


#Starting spawning the adventurers
narrative_event = {
	id = EADOAD.11
    title = EVT_TITLE_EADOAD_11
    desc = EVTDESC_EADOAD_11
	picture = GFX_evt_elven_adventurer
	hide_window = yes
	
	is_triggered_only = yes
	
	trigger = {
	    NOT = {
		    has_global_flag = otherworlden_adventures_begins
		}
		has_global_flag = everyone_invaded
	    OR = {
		    AND = {
			    AND = { 
				    OR = { 
					    has_global_flag = elven_empire_landed 
					    has_global_flag = elven_empire_defeated
					}
				    e_elven_empire = { has_holder = no }
			    }
				NOR = {
				    any_independent_ruler = {
					    is_earth_or_otherworlden_elven_culture = yes
						is_landed = yes
					}
					ROOT = {
				        is_earth_or_otherworlden_elven_culture = yes
						independent = yes
				    }
				}
			}
			AND = {
			    AND = { 
				    OR = { 
					    has_global_flag = dwarven_empire_landed 
					    has_global_flag = dwarven_empire_defeated
					}
				    e_dwarven_empire = { has_holder = no }
			    }
				NOR = {
				    any_independent_ruler = {
					    is_earth_or_otherworlden_dwarven_culture = yes
						is_landed = yes
					}
					ROOT = {
				        is_earth_or_otherworlden_dwarven_culture = yes
						independent = yes
				    }
				}
			}
			AND = {
			    AND = { 
				    OR = { 
					    has_global_flag = dark_elven_empire_landed 
					    has_global_flag = dark_elven_empire_defeated
					}
				    e_dark_elven_empire = { has_holder = no }
			    }
				NOR = {
				    any_independent_ruler = {
					    is_earth_or_otherworlden_dark_elven_culture = yes
						is_landed = yes
					}
					ROOT = {
				        is_earth_or_otherworlden_dark_elven_culture = yes
						independent = yes
				    }
				}
			}
			AND = {
			    AND = { 
				    OR = { 
					    has_global_flag = dark_dwarven_empire_landed 
					    has_global_flag = dark_dwarven_empire_defeated
					}
				    e_dark_dwarven_empire = { has_holder = no }
			    }
				NOR = {
				    any_independent_ruler = {
					    is_earth_or_otherworlden_dark_dwarven_culture = yes
						is_landed = yes
					}
					ROOT = {
					    is_earth_or_otherworlden_dark_dwarven_culture = yes
						independent = yes
				    }
				}
			}
			AND = {
			    AND = { 
				    OR = { 
					    has_global_flag = cat_folk_empire_landed 
					    has_global_flag = cat_folk_empire_defeated
					}
				    e_cat_folk_empire = { has_holder = no }
			    }
				NOR = {
				    any_independent_ruler = {
					    is_earth_or_otherworlden_cat_folk_culture = yes
						is_landed = yes
					}
					ROOT = {
				        is_earth_or_otherworlden_cat_folk_culture = yes
						independent = yes
				    }
				}
			}
			
			AND = {
			    AND = { 
				    OR = { 
					    has_global_flag = orcish_horde_landed 
					    has_global_flag = orcish_horde_defeated
					}
				    e_orcish_horde = { has_holder = no }
			    }
				NOR = {
				    any_independent_ruler = {
					    is_earth_or_otherworlden_oruk_culture = yes
						is_landed = yes
					}
					ROOT = {
				        is_earth_or_otherworlden_oruk_culture = yes
						independent = yes
				    }
				}
			}
		}
	}
	
	immediate = {
	    set_global_flag = otherworlden_adventures_begins
	    if = {
			limit = {
			    AND = {
			 	    AND = { 
					    OR = { 
						    has_global_flag = elven_empire_landed 
						    has_global_flag = elven_empire_defeated
						}
					    e_elven_empire = { has_holder = no }
			    	}
					NOR = {
					    any_independent_ruler = {
						    is_earth_or_otherworlden_elven_culture = yes
							is_landed = yes
						}
						ROOT = {
					        is_earth_or_otherworlden_elven_culture = yes
							independent = yes
					    }
					}
			    }
			}
			set_global_flag = elven_empire_has_fallen
			clr_global_flag = elven_empire_landed
		}
		else_if = {
			limit = {
			    AND = {
				    AND = { 
					    OR = { 
						    has_global_flag = dwarven_empire_landed 
						    has_global_flag = dwarven_empire_defeated
						}
					    e_dwarven_empire = { has_holder = no }
				    }
					NOR = {
					    any_independent_ruler = {
						    is_earth_or_otherworlden_dwarven_culture = yes
							is_landed = yes
						}
						ROOT = {
				    	    is_earth_or_otherworlden_dwarven_culture = yes
							independent = yes
					    }
					}
				}
			}
			set_global_flag = dwarven_empire_has_fallen
			clr_global_flag = dwarven_empire_landed
		}
		else_if = {
			limit = {
			    AND = {
				    AND = { 
					    OR = { 
						    has_global_flag = dark_elven_empire_landed 
						    has_global_flag = dark_elven_empire_defeated
						}
					    e_dark_elven_empire = { has_holder = no }
				    }
					NOR = {
					    any_independent_ruler = {
						    is_earth_or_otherworlden_dark_elven_culture = yes
							is_landed = yes
						}
						ROOT = {
					        is_earth_or_otherworlden_dark_elven_culture = yes
							independent = yes
					    }
					}
				}				
			}
			set_global_flag = dark_elven_empire_has_fallen
			clr_global_flag = dark_elven_empire_landed
		}
		else_if = {
			limit = {
			    AND = {
				    AND = { 
					    OR = { 
						    has_global_flag = dark_dwarven_empire_landed 
						    has_global_flag = dark_dwarven_empire_defeated
						}
					    e_dark_dwarven_empire = { has_holder = no }
				    }
					NOR = {
					    any_independent_ruler = {
						    is_earth_or_otherworlden_dark_dwarven_culture = yes
							is_landed = yes
						}
						ROOT = {
					        is_earth_or_otherworlden_dark_dwarven_culture = yes
							independent = yes
					    }
					}
				}
			}
			set_global_flag = dark_dwarven_empire_has_fallen
			clr_global_flag = dark_dwarven_empire_landed
		}
		else_if = {
			limit = {
			    AND = {
				    AND = { 
					    OR = { 
						    has_global_flag = cat_folk_empire_landed 
						    has_global_flag = cat_folk_empire_defeated
						}
					    e_cat_folk_empire = { has_holder = no }
				    }
					NOR = {
					    any_independent_ruler = {
						    is_earth_or_otherworlden_cat_folk_culture = yes
							is_landed = yes
						}
						ROOT = {
					        is_earth_or_otherworlden_cat_folk_culture = yes
							independent = yes
					    }
					}
				}
			}
			set_global_flag = cathrian_empire_has_fallen
			clr_global_flag = cat_folk_empire_landed
		}
		else_if = {
			limit = {
			    AND = {
				    AND = { 
					    OR = { 
						    has_global_flag = orcish_horde_landed 
						    has_global_flag = orcish_horde_defeated
						}
					    e_orcish_horde = { has_holder = no }
				    }
					NOR = {
					    any_independent_ruler = {
						    is_earth_or_otherworlden_oruk_culture = yes
							is_landed = yes
						}
						ROOT = {
					        is_earth_or_otherworlden_oruk_culture = yes
							independent = yes
					    }
					}
				}
			}
			set_global_flag = orcish_horde_has_fallen
			clr_global_flag = orcish_horde_landed
		}
		narrative_event = { id = EADOAD.4 days = 5 }
	}

    option = {
        name = EVT_OPTA_EADOAD_11
    }
}

#News Event: Inform adventurer has started his campaign
narrative_event = {
	id = EADOAD.13
	title = EVT_TITLE_EADOAD_13
	border = GFX_event_narrative_frame_war
	major = yes
	
	desc = {
       trigger = { has_global_flag = elven_prince_host }
       text = EVT_DESC_EADOAD_13_A
       picture = GFX_evt_elven_adventurer
    }
	
	desc = {
       trigger = { has_global_flag = dwarven_warrior_host }
       text = EVT_DESC_EADOAD_13_B
       picture = GFX_evt_dwarven_adventurer
    }
	
	desc = {
       trigger = { has_global_flag = dark_elven_prince_host }
       text = EVT_DESC_EADOAD_13_C
       picture = GFX_evt_elven_adventurer
    }
	
	desc = {
       trigger = { has_global_flag = dark_dwarven_warrior_host }
       text = EVT_DESC_EADOAD_13_D
       picture = GFX_evt_dwarven_adventurer
    }
	
	desc = {
       trigger = { has_global_flag = cathrian_nobleman_host }
       text = EVT_DESC_EADOAD_13_E
       picture = GFX_evt_battle_byzantine
    }
	
	desc = {
       trigger = { has_global_flag = blood_elven_prince_host }
       text = EVT_DESC_EADOAD_13_F
       picture = GFX_evt_blood_elven_hero
    }
	
	desc = {
       trigger = { has_global_flag = oruk_warchief_host }
       text = EVT_DESC_EADOAD_13_G
       picture = GFX_evt_battle_oruk
    }

	is_triggered_only = yes
	hide_new = yes

	option = {
		name = EVT_OPTA_EADOAD_13
	}
}

#News Event: Otherworlden realm has fallen, here comes the adventurers
narrative_event = {
	id = EADOAD.14
    title = EVT_TITLE_EADOAD_11
    desc = EVTDESC_EADOAD_11
	picture = GFX_evt_elven_adventurer
	major = yes
	
	is_triggered_only = yes

	option = {
        name = EVT_OPTA_EADOAD_11
    }
}	


#Setup the adventurer's titles for Asia and warn target
character_event = {
	id = EADOAD.15

	hide_window = yes

	is_triggered_only = yes
	capable_only = yes
	prisoner = no
	
	trigger = {
		NOT = {
			has_game_rule = {
				name = adventurers
				value = none
			}
		}
	}

	immediate = {
		###Picks worst and overwrites as better targets are found
		log = "Other World Logging:"
		#Worst case, pick any ruler in the invasion region
		random_independent_ruler = {
			limit = {
			    any_realm_province = {
					OR = {
						region = world_steppe_east
						region = world_india
						region = world_himalayas
					}
				}
				in_revolt = no
#				is_within_diplo_range = event_target:that_fgt_in_tiara
				is_landed = yes
				is_nomadic = no
				higher_tier_than = BARON
			}
			save_event_target_as = otherworlden_adventurer_target
			log = "[otherworlden_adventurer_target.GetFullName] ID [otherworlden_adventurer_target.GetID] is the Elven Adventurer's Worst Case Target."
		}
		#Avoid WP target, pick a normal Count ruler
		random_independent_ruler = {
			limit = {
				any_realm_province = {
					OR = {
						region = world_steppe_east
						region = world_india
						region = world_himalayas
					}
				}
				NOT = { event_target:that_fgt_in_tiara = { character = PREV } }
				in_revolt = no
#				is_within_diplo_range = event_target:that_fgt_in_tiara
				is_landed = yes
				is_nomadic = no
				higher_tier_than = BARON
			}
			save_event_target_as = otherworlden_adventurer_target
			log = "[otherworlden_adventurer_target.GetFullName] ID [otherworlden_adventurer_target.GetID] is the Elven Adventurer's  Worst Case Target."
		}
		#A a duke with a decent amount of land
		random_independent_ruler = {
			limit = {
				any_realm_province = {
					region = world_africa
				}
				NOT = { event_target:that_fgt_in_tiara = { character = PREV } }
				in_revolt = no
#				is_within_diplo_range = event_target:that_fgt_in_tiara
				is_landed = yes
				is_nomadic = no
    			higher_tier_than = COUNT
				num_of_count_titles_in_realm = 5
			}
			save_event_target_as = otherworlden_adventurer_target
			log = "[otherworlden_adventurer_target.GetFullName] ID [otherworlden_adventurer_target.GetID] is the Elven Adventurer's Duke Target."
		}
		#A king with plenty of land
		random_independent_ruler = {
			limit = {
				any_realm_province = {
					region = world_africa
				}
				NOT = { event_target:that_fgt_in_tiara = { character = PREV } }
				in_revolt = no
#				is_within_diplo_range = event_target:that_fgt_in_tiara
				is_landed = yes
				is_nomadic = no
    			higher_tier_than = DUKE
				num_of_count_titles_in_realm = 15
			}
			save_event_target_as = otherworlden_adventurer_target
			log = "[otherworlden_adventurer_target.GetFullName] ID [otherworlden_adventurer_target.GetID] is the Elven Adventurer's King Target."
		}
		#An emperor with lots of land
		random_independent_ruler = {
			limit = {
				any_realm_province = {
					region = world_africa
				}
				NOT = { event_target:that_fgt_in_tiara = { character = PREV } }
				in_revolt = no
#				is_within_diplo_range = event_target:that_fgt_in_tiara
				is_landed = yes
				is_nomadic = no
    			higher_tier_than = KING
				num_of_count_titles_in_realm = 30
			}
			save_event_target_as = otherworlden_adventurer_target
			log = "[otherworlden_adventurer_target.GetFullName] ID [otherworlden_adventurer_target.GetID] is the Elven Adventurer's Emperor Target."
		}

		#!!!If still no target then stop it all!!!
		if = {
			limit = { NOT = { event_target:otherworlden_adventurer_target = { always = yes } } }
			death = { death_reason = death_missing }
			log = "[This.GetFullName] ID [This.GetID] is the Elven Adventurer and could not find a target therefore he is getting removed."
			break = yes
		}
		
		log = "[otherworlden_adventurer_target.GetFullName] ID [otherworlden_adventurer_target.GetID] is the Elven Adventurer's Final Target."

		#Create title after finding target so if all goes wrong don't need to delete title
		create_title = {
			tier = EMPEROR
			temporary = no
			landless = yes
			custom_created = yes
			culture = ROOT
			name = "CLAIMANT_ADVENTURE"
			holder = ROOT
			base_title = THIS
			short_name = yes
		}
		new_title = { save_event_target_as = adventurers_title }
		set_defacto_liege = ROOT

		trigger_switch = {
			on_trigger = has_character_flag
			oruk_warchief = {
				create_character = {
					age = 24
					random_traits = yes
					female = yes
					religion = orc_religion
					culture = oruk
					historical = yes
				}
				new_character = {
					add_spouse = ROOT
					create_character = {
						age = 6
						random_traits = yes
						female = 50
						religion = orc_religion
						culture = oruk
						genetic_father = ROOT
						genetic_mother = PREV
						historical = yes
					}
					new_character = {
						dynasty = ROOT
						set_father = ROOT
						set_mother = PREV
					}
					create_character = {
						age = 6
						random_traits = yes
						female = 50
						religion = orc_religion
						culture = oruk
						genetic_father = ROOT
						genetic_mother = PREV
						historical = yes
					}
					new_character = {
						dynasty = ROOT
						set_father = ROOT
						set_mother = PREV
					}
				}
				set_global_flag = oruk_warchief_host
			}
			oruk_hai_warchief = {
				create_character = {
					age = 24
					random_traits = yes
					female = yes
					religion = orc_religion_dark_lord
					culture = oruk_hai
					historical = yes
				}
				new_character = {
					add_spouse = ROOT
					create_character = {
						age = 6
						random_traits = yes
						female = 50
						religion = orc_religion_dark_lord
						culture = oruk_hai
						genetic_father = ROOT
						genetic_mother = PREV
						historical = yes
					}
					new_character = {
						dynasty = ROOT
						set_father = ROOT
						set_mother = PREV
					}
					create_character = {
						age = 6
						random_traits = yes
						female = 50
						religion = orc_religion_dark_lord
						culture = oruk_hai
						genetic_father = ROOT
						genetic_mother = PREV
						historical = yes
					}
					new_character = {
						dynasty = ROOT
						set_father = ROOT
						set_mother = PREV
					}
				}
				set_global_flag = oruk_warchief_host
			}
		}
		clr_character_flag = oruk_warchief_host
		set_global_flag = adventurer_in_asia
		prestige = 500

		#Warn the target of the incoming invasion
		event_target:otherworlden_adventurer_target = { narrative_event = { id = EADOAD.4 days = 5 } }
	}
}