
namespace = DuelMaidAdv

# An ambitious character with no inheritance begins to plan an adventure for a foreign title
character_event = {
	id = DuelMaidAdv.1210
	
	hide_window = yes # Only fires for unplayable landless characters
	
	min_age = 30
	max_age = 50
	capable_only = yes
	prisoner = no
	
	trigger = {
		has_dlc = "The Old Gods"
		
		NOT = {
			has_game_rule = {
				name = adventurers
				value = none
			}
		}
		
		is_ruler = no
		#NOT = { any_spouse = { is_ruler = yes } }
		
		OR = {
			religion = norse_pagan
			religion = norse_pagan_reformed
			}
		OR = {
			has_game_rule = {
				name = flavor_events
				value = equal
			}
			is_female = yes
		}
		OR = {
			trait = shieldmaiden
			trait = heroicblood
		}
		trait = ambitious
		NOR = {
			trait = craven
			trait = content
		}
	
		
		#NOT = { # Somewhat clunky way of checking that the character does not stand to inherit any titles
		#	any_heir_title = {
		#		always = yes
		#	}
		#}
		
		NOT = { any_close_relative = { is_ruler = yes } }
		
		#OR = { #Charakter muss wenigstens einen Elternteil besitzen, der einen County-Titel hat
		#	father_even_if_dead = {
		#		OR = {
		#			primary_title = { higher_tier_than = BARON }
		#			father_even_if_dead = {
		#				primary_title = { higher_tier_than = BARON }
		#			}
		#			mother_even_if_dead = {
		#				primary_title = { higher_tier_than = BARON }
		#			}
		#		}
		#	}
		#	mother_even_if_dead = {
		#		OR = {
		#			primary_title = { higher_tier_than = BARON }
		#			father_even_if_dead = {
		#				primary_title = { higher_tier_than = BARON }
		#			}
		#			mother_even_if_dead = {
		#				primary_title = { higher_tier_than = BARON }
		#			}
		#		}
		#	}
		#}
		
		NOT = { has_character_modifier = planning_duchy_adventure }
	}
	
	mean_time_to_happen = {		# Nach dieser Zeit beginnt ein Charakter das Abenteuer nach Erfllung der Voraussetzungen zu starten. Ggf hinaufsetzen
		days = 180
	}
	
	immediate = {
		random_independent_ruler = {
			limit = {
				NOR = {
					religion = norse_pagan
					religion = norse_pagan_reformed }
				is_landed = yes
				independent = yes
				NOT = { is_vassal_or_below = ROOT }
				any_realm_province = {
					OR = {
						AND = {
							port = yes
							ROOT = {
								NOT = { culture_group = altaic }
								NOT = { culture = hungarian }
							}
							NOT = {
								distance = {
									who = ROOT
									value = 800
								}
							}
						}
						any_neighbor_province = {	#Der anvisierte Herrscher grenzt nicht an den Realm an indem sich der Abenteurer aufhlt
							owner = {
								same_realm = ROOT
							}
						}
					}
					NOT = {
						region = world_europe_north
					}
					NOT = {
						duchy = {
							title = d_bjarmia
						}
					}
				}
				ROOT = {
					NOR = {
						obedient = PREV		# Nicht gehorsam gegenber dem anvisierten Herrscher
						non_interference = PREV
					}
				}
			}
			
			random_realm_province = {
				limit = {
					OR = {
						AND = {
							port = yes
							ROOT = {
								NOT = { culture_group = altaic }
								NOT = { culture = hungarian }
							}
							NOT = {
								distance = {
									who = ROOT
									value = 800
								}
							}
						}
						any_neighbor_province = {
							owner = {
								same_realm = ROOT
							}
						}
					}
					NOT = {
						region = world_europe_north
					}
					NOT = {
						duchy = {
							title = d_bjarmia
						}
					}
				}
				
				ROOT = {
					opinion = {
						who = PREVPREV
						years = 3
						modifier = opinion_duchy_adventure_target
					}
					add_character_modifier = {
						name = planning_duchy_adventure
						hidden = yes
						days = 730
					}
					character_event = {
						id = DuelMaidAdv.1212 # Fire the attack
						days = 730
					}
				}
				PREV = {
					character_event = {
						id = DuelMaidAdv.1211 # Warn the target
					}
				}
			}
		}
		end_inaccessibility_effect = yes #removes in hiding or in_seclusion
		
		set_character_flag = do_not_disturb
		character_event = { id = DuelMaidAdv.1215 days = 730 }
	}
	
	option = {
		name = OK
	}
}

character_event = {
	id = DuelMaidAdv.1211
	desc = EVTDESC_TOG_1211
	picture = GFX_evt_crusaders
	border = GFX_event_normal_frame_war
	
	is_triggered_only = yes
	
	immediate = {
		opinion = {
			who = FROM
			modifier = opinion_targeted_by_adventurer
			months = 24
		}
	}
	
	option = {
		name = "EVTOPTA_TOG_1211"
	}
}

# An ambitious character with no inheritance starts an adventure for a foreign title
# (Temporary title created and a war declared)
character_event = {
	id = DuelMaidAdv.1212
	
	hide_window = yes # Only fires for unplayable landless characters
	
	is_triggered_only = yes

	prisoner = no
	only_capable = yes
	
	trigger = {
		has_dlc = "The Old Gods"
		
		is_ruler = no
		NOT = { any_spouse = { is_ruler = yes } }
		
		NOT = {
			any_heir_title = {
				always = yes
			}
		}
		
		any_independent_ruler = {
			NOR = {
				religion = norse_pagan
				religion = norse_pagan_reformed
				}
			is_landed = yes
			independent = yes
			NOT = { is_vassal_or_below = ROOT }
			any_realm_province = {
				OR = {
					AND = {
						port = yes
						ROOT = {
							NOT = { culture_group = altaic }
							NOT = { culture = hungarian }
						}
					}
					any_neighbor_province = {
						owner = {
							same_realm = ROOT
						}
					}
				}
				NOT = {
					region = world_europe_north
				}
				NOT = {
					duchy = {
						title = d_bjarmia
					}
				}
			}
			ROOT = {
				NOR = {
					obedient = PREV
					non_interference = PREV
				}
			}
			reverse_has_opinion_modifier = {
				who = ROOT
				modifier = opinion_duchy_adventure_target
			}
		}
	}
	
	immediate = {
		wealth = 500
		clr_character_flag = do_not_disturb
		
		liege = {
			character_event = {
				id = DuelMaidAdv.1213
				days = 1
			}
		}
		
		liege = {
			capital_scope = {
				random_independent_ruler = {
					limit = {
						NOR = {
							religion = norse_pagan
							religion = norse_pagan_reformed
							}
						is_landed = yes
						independent = yes
						NOT = { is_vassal_or_below = ROOT }
						any_realm_province = {
							OR = {
								AND = {
									port = yes
									ROOT = {
										NOT = { culture_group = altaic }
										NOT = { culture = hungarian }
									}
								}
								any_neighbor_province = {
									owner = {
										same_realm = ROOT
									}
								}
							}
							NOT = {
								region = world_europe_north
							}
							NOT = {
								duchy = {
									title = d_bjarmia
								}
							}
						}
						ROOT = {
							NOR = {
								obedient = PREV
								non_interference = PREV
							}
						}
						reverse_has_opinion_modifier = {
							who = ROOT
							modifier = opinion_duchy_adventure_target
						}
					}
					random_realm_province = {
						limit = {
							OR = {
								AND = {
									port = yes
									ROOT = {
										NOT = { culture_group = altaic }
										NOT = { culture = hungarian }
									}
								}
								any_neighbor_province = {
									owner = {
										same_realm = ROOT
									}
								}
							}
							NOT = {
								region = world_europe_north
							}
							NOT = {
								duchy = {
									title = d_bjarmia
								}
							}
						}
						
						ROOT = {
							set_defacto_liege = ROOT
							create_title = {
								tier = DUKE
								landless = yes
								temporary = yes
								adventurer = yes
								culture = ROOT
								name = "CLAIMANT_ADVENTURE"
								holder = ROOT
							}
							
							set_character_flag = duchy_adventurer
						
							spawn_unit = {
								province = PREVPREVPREV
								home = PREVPREVPREV
								owner = THIS
								#leader = THIS
								match_character = PREVPREV
								match_mult = 0.125
								match_min = 500
								match_max = 10000
								attrition = 0.25
							}
							spawn_unit = {
								province = PREVPREVPREV
								home = PREVPREVPREV
								owner = THIS
								match_character = PREVPREV
								match_mult = 0.125
								match_min = 500
								match_max = 10000
								attrition = 0.25
							}
							spawn_unit = {
								province = PREVPREVPREV
								home = PREVPREVPREV
								owner = THIS
								match_character = PREVPREV
								match_mult = 0.125
								match_min = 500
								match_max = 10000
								attrition = 0.25
							}
							war = {
								target = PREVPREV
								casus_belli = duchy_adventure
								thirdparty_title = PREV
								tier = DUKE
							}
							remove_opinion = {
								who = PREVPREV
								modifier = opinion_duchy_adventure_target
							}
						}
					}
				}
			}
		}
		
		# Create some decent commander characters
		create_random_soldier = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 30
		}
		create_random_soldier = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 25
		}
		
		if  = {
			limit = {
				NOT = { culture_group = altaic }
				NOT = { culture = hungarian }
			}
			
			# Create a fleet, just to be sure
			spawn_fleet = {
				province = closest # closest sea zone
				owner = ROOT
				disband_on_peace = yes
				troops =
				{
					galleys = { 200 200 }
				}
			}
		}
	}
	
	option = {
		name = OK
	}
}

character_event = {
	id = DuelMaidAdv.1213
	desc = EVTDESC_TOG_1213
	picture = GFX_evt_crusaders
	border = GFX_event_normal_frame_war
	
	is_triggered_only = yes
	
	trigger = {
		FROM = { is_ruler = yes } # The DoW worked and the adventurer has a temporary title
	}
	
	immediate = {
		FROM = {
			add_trait = adventurer
		}
		any_liege = {
			character_event = {
				id = DuelMaidAdv.1214
			}
		}
	}
	
	option = {
		name = "EVTOPTA_TOG_1203"
	}
}

character_event = {
	id = DuelMaidAdv.1214
	desc = EVTDESC_TOG_1214
	picture = GFX_evt_crusaders
	border = GFX_event_normal_frame_war
	
	show_from_from = yes
	
	is_triggered_only = yes
	
	option = {
		name = "EVTOPTA_TOG_1203"
	}
}

#safety clear of DND
character_event = {
	id = DuelMaidAdv.1215
	
	is_triggered_only = yes
	
	hide_window = yes
	
	immediate = {
		clr_character_flag = do_not_disturb
	}
}