#########################################################
#
# Landless Character Adventures for The Old Gods DLC
# ( TOG.1200 to TOG.1499)
#
#
#########################################################

# Written by Henrik Fhraeus

namespace = UBB
character_event = {
	id = UBB.992

	ai = yes
	only_independent = yes
	culture_group = north_germanic
	
	hide_window = yes
	
	trigger = {
		year = 1020
		NOT = {year = 1030}
		higher_tier_than = DUKE
		any_realm_lord = {
			has_landed_title = c_gotland
			OR = {
				tier = COUNT
				tier = DUKE
			}
			OR = {
				is_tribal = yes
				is_feudal = yes
			}
			ai = yes
		}
		NOT = {has_global_flag = gotland_found}
	}
	
	mean_time_to_happen = {
		months = 60
	}

	immediate = {
		set_global_flag = gotland_found
		random_realm_lord = {
			limit = {has_landed_title = c_gotland}
			save_event_target_as = gotland_merchant
			if = {
				limit = {
					tier = COUNT
				}
				if = {
					limit = {
						d_gotland = {
							has_holder = yes
						}
					}
					c_gotland = {
						event_target:gotland_merchant = {
							create_title = {
								tier = DUKE
								landless = no
								temporary = no
								custom_created = yes
								culture = event_target:gotland_merchant
								holder = event_target:gotland_merchant
								base_title = PREV
							}
						}
					}
				}
				#CREATE GOTLAND
			}
			if = {
				limit = {
					d_gotland = {
						has_holder = no
					}
				}
				d_gotland = {
					grant_title = PREV
					make_primary_title = yes
				}
			}
			create_family_palace = yes
			
			set_government_type = merchant_republic_government
			set_defacto_liege = ROOT
			create_character = {
				random_traits = yes
				is_female = no
				name = "Likair"
				age = 46
				dynasty = 495
				culture = THIS
				religion = THIS
			}
			new_character = {
				add_trait = swordsman2
				set_character_flag = wpn
				set_government_type = merchant_republic_government
				create_family_palace = yes
				create_character = {
					random_traits = no
					female = no
					name = "Munkair"
					age = 13
					dynasty = 495
					culture = PREV
					religion = PREV
					trait = brave
					trait = gregarious
					trait = proud
				}
				new_character = {
					add_trait = underhanded_rogue
					add_character_modifier = {
						name = gedu
						duration = 3650
						hidden = yes
					}
					set_father = PREV
				}
				create_character = {
					random_traits = no
					female = yes
					name = "Rodiaud"
					age = 13
					dynasty = 495
					culture = PREV
					religion = PREV
					trait = kind
					trait = lustful
				}
				new_character = {
					set_father = PREV
					add_trait = thrifty_clerk
					add_character_modifier = {
						name = gedu
						duration = 3650
						hidden = yes
					}
				}
			}
			create_character = {
				random_traits = yes
				female = no
				name = "Tjudmund"
				age = 26
				dynasty = 9517
				culture = THIS
				religion = THIS
			}
			new_character = {
				add_trait = swordsman3
				set_character_flag = wpn
				set_government_type = merchant_republic_government
				create_family_palace = yes
				create_character = {
					random_traits = yes
					female = no
					name = "Kettil"
					age = 1
					dynasty = 9517
					culture = PREV
					religion = PREV
				}
				new_character = {
					set_father = PREV
				}
			}
			
			create_character = {
				random_traits = yes
				female = no
				name = "Hkan"
				age = 21
				dynasty = 9519
				culture = THIS
				religion = THIS
			}
			new_character = {
				set_government_type = merchant_republic_government
				create_family_palace = yes
			}
			
			create_character = {
				random_traits = yes
				female = no
				name = "Faste"
				age = 16
				dynasty = 9518
				culture = THIS
				religion = THIS
			}
			new_character = {
				add_trait = swordsman1
				set_character_flag = wpn
				set_government_type = merchant_republic_government
				create_family_palace = yes
			}
			
			any_demesne_title = {
				limit = {
					tier = baron
					holding_type = tribal
				}
				convert_to = CITY
				refill_holding_levy = yes
				
				if = {
					limit = {
						dejure_liege_title = {
							holder = event_target:gotland_merchant
							location = {
								num_of_empty_holdings = 2
							}
							NOT = {
								any_direct_de_jure_vassal_title = {
									holding_type = castle
								}
							}
						}
					}
					location = {
						build_holding = {
							type = castle
						}
					}
				}
				if = {
					limit = {
						dejure_liege_title = {
							holder = event_target:gotland_merchant
							location = {
								num_of_empty_holdings = 2
							}
							NOT = {
								any_direct_de_jure_vassal_title = {
									holding_type = temple
								}
							}
						}
					}
					location = {
						build_holding  ={
							type = temple
						}
					}
				}
			}
		}
			
	}
}


character_event = {
	id = UBB.1000
	
	is_triggered_only = yes
	hide_window = yes
	
	trigger = {
		NOT = {year = 869}

		character = 163119
		NOT = {has_global_flag = devon_attack}
	}
	immediate = {
		character_event = {id = UBB.1001 days = 3650 random = 30}
		set_global_flag = devon_attack
	}
}

character_event = {
	id = UBB.1001
	
	is_triggered_only = yes
	hide_window = yes
	
	trigger = {
		is_landed = no
		NOT = {trait = incapable}
	}
	
	immediate = {		
		character_event = {id = UBB.1210 days = 1}
	}
}


character_event = {
	id = UBB.1210
	
	hide_window = yes # Only fires for unplayable landless characters
	
	is_triggered_only = yes
	
	trigger = {
		is_landed = no
		NOT = { has_character_modifier = planning_duchy_adventure }
	}
	
	immediate = {
		if = {
			limit = { prisoner = yes }
			imprison = no
		}
		random_independent_ruler = {
			limit = {
				#NOT = { is_vassal_or_below = ROOT }

				NOT = {
					culture = norman
					culture = norse
				}

				in_revolt = no
				any_realm_province = {
					county = {
						title = c_devon
					}
				}
			}
			
			random_realm_province = {
				limit = {
					county = {
						title = c_devon
					}
				}
				
				ROOT = {
					character_event = {
						id = UBB.1212 # Fire the attack
						days = 30
					}
					opinion = {
						who = PREVPREV
						months = 3
						modifier = opinion_duchy_adventure_target
					}
					reverse_opinion = {
						who = PREVPREV
						months = 3
						modifier = rsp
					}
					add_character_modifier = {
						name = planning_duchy_adventure
						hidden = yes
						months = 1
					}
					
				}
				PREV = {
					character_event = {
						id = TOG.1211 # Warn the target
					}
				}
			}
		}
		if = {
			limit = { trait = in_hiding	}
			remove_trait = in_hiding
			add_character_modifier = {
				name = went_out_of_hiding_timer
				duration = 180
				hidden = yes
			}
			hidden_tooltip = { character_event = { id = CM.6400 } } # Notify plotters and family
		}
		character_event = { id = TOG.1215 days = 30 }
	}

}



# An ambitious character with no inheritance starts an adventure for a foreign title
# (Temporary title created and a war declared)
character_event = {
	id = UBB.1212
	
	hide_window = yes # Only fires for unplayable landless characters
	
	is_triggered_only = yes
	prisoner = no
	
	trigger = {
		is_landed = no
		
		NOT = { trait = incapable }
		
		religion = norse_pagan
		
		any_independent_ruler = {
			any_realm_province = {
				county = {
					title = c_devon
				}
			}
			has_opinion_modifier = {
				who = ROOT
				modifier = rsp
			}
		 }
	}
	
	immediate = {
		wealth = 1000
		clr_character_flag = do_not_disturb
		
		liege = {
			character_event = {
				id = TOG.1213
				days = 1
			}
		}
		
		liege = {
			capital_scope = {
				random_independent_ruler = {
					limit = {
						any_realm_province = {
							county = {
								title = c_devon
							}
						}
						
						has_opinion_modifier = {
							who = ROOT
							modifier = rsp
						}
					}
					random_realm_province = {
						limit = {
							county = {
								title = c_devon
							}
						}
						
						ROOT = {
							set_defacto_liege = ROOT
							create_title = {
								tier = DUKE
								landless = yes
								temporary = yes
								culture = ROOT
								name = "VIKING_CONQUEST"
								holder = ROOT
							}
							religion = norse_pagan
							add_trait = berserker
							
							spawn_unit = {
								province = PREVPREVPREV
								home = PREV
								owner = THIS
								leader = THIS
								match_character = PREVPREV
								match_mult = 2.0
								match_min = 1124
								match_max = 1236
								attrition = 0.25
								disband_on_peace = yes
							}
							
							# Create a fleet, just to be sure
							spawn_fleet = {
								province = 57 # closest sea zone
								owner = ROOT
								disband_on_peace = yes
								troops =
								{
									galleys = { 20 20 }
								}
							}
							
							
							
							spawn_unit = {
								province = PREVPREVPREV
								home = PREV
								owner = THIS
								match_character = PREVPREV
								match_mult = 0.7
								match_min = 1278
								match_max = 1526
								attrition = 0.25
								disband_on_peace = yes
							}
							spawn_fleet = {
								province = 57 # closest sea zone
								owner = ROOT
								disband_on_peace = yes
								troops =
								{
									galleys = { 20 20 }
								}
							}
							
							spawn_unit = {
								province = PREVPREVPREV
								home = PREV
								owner = THIS
								match_character = PREVPREV
								match_mult = 0.7
								match_min = 1621
								match_max = 1801
								attrition = 0.25
								disband_on_peace = yes
							}
							spawn_fleet = {
								province = 57 # closest sea zone
								owner = ROOT
								disband_on_peace = yes
								troops =
								{
									galleys = { 20 20 }
								}
							}
							war = {
								target = PREVPREV
								casus_belli = pagan_county_conquest
								thirdparty_title = PREV
								#tier = COUNT
							}
							remove_opinion = {
								who = PREVPREV
								modifier = opinion_duchy_adventure_target
							}
							reverse_remove_opinion = {
								who = PREVPREV
								modifier = rsp
							}
						}
					}
				}
			}
		}
		
		# Create some decent commander characters
		create_random_soldier = {
			random_traits = no
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
		}
		new_character = {
			add_trait = combat_exp
			add_trait = axe2
			
			set_character_flag = wpn
		}
		create_random_soldier = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
		}
		new_character = {
			add_trait = spear1
			set_character_flag = wpn

		}
		
		
		
	}
	
	option = {
		name = OK
	}
}




character_event = {
	id = UBB.2000
	
	is_triggered_only = yes
	hide_window = yes
	
	trigger = {
		NOT = {year = 869}

		character = 161303
		NOT = {has_global_flag = orkney_attack}
	}
	immediate = {
		character_event = {id = UBB.2001 days = 1500 random = 1000}
		set_global_flag = orkney_attack
	}
}

character_event = {
	id = UBB.2001
	
	is_triggered_only = yes
	hide_window = yes
	
	trigger = {
		is_landed = no
		NOT = {trait = incapable}
	}
	
	immediate = {		
		character_event = {id = UBB.2210 days = 1}
	}
}


character_event = {
	id = UBB.2210
	
	hide_window = yes # Only fires for unplayable landless characters
	
	is_triggered_only = yes
	
	trigger = {
		is_landed = no
		NOT = { has_character_modifier = planning_duchy_adventure }
	}
	
	immediate = {
		if = {
			limit = { prisoner = yes }
			imprison = no
		}
		random_independent_ruler = {
			limit = {
				in_revolt = no
				any_realm_province = {
					county = {
						title = c_faereyar
					}
				}
			}
			
			random_realm_province = {
				limit = {
					county = {
						title = c_faereyar
					}
				}
				
				ROOT = {
					character_event = {
						id = UBB.2212 # Fire the attack
						days = 700
					}
					opinion = {
						who = PREVPREV
						months = 36
						modifier = opinion_duchy_adventure_target
					}
					reverse_opinion = {
						who = PREVPREV
						months = 36
						modifier = rsp
					}
					add_character_modifier = {
						name = planning_duchy_adventure
						hidden = yes
						duration = 730
					}
					
				}
				PREV = {
					character_event = {
						id = TOG.1211 # Warn the target
					}
				}
			}
		}
		if = {
			limit = { trait = in_hiding	}
			remove_trait = in_hiding
			add_character_modifier = {
				name = went_out_of_hiding_timer
				duration = 180
				hidden = yes
			}
			hidden_tooltip = { character_event = { id = CM.6400 } } # Notify plotters and family
		}
		character_event = { id = TOG.1215 days = 30 }
	}

}



# An ambitious character with no inheritance starts an adventure for a foreign title
# (Temporary title created and a war declared)
character_event = {
	id = UBB.2212
	
	hide_window = yes # Only fires for unplayable landless characters
	
	is_triggered_only = yes
	prisoner = no
	
	trigger = {
		is_landed = no
		
		NOT = { trait = incapable }

		any_independent_ruler = {
			any_realm_province = {
				county = {
					title = c_faereyar
				}
			}
			has_opinion_modifier = {
				who = ROOT
				modifier = rsp
			}
		 }
	}
	
	immediate = {
		wealth = 1000
		clr_character_flag = do_not_disturb
		
		liege = {
			character_event = {
				id = TOG.1213
				days = 1
			}
		}
		
		liege = {
			capital_scope = {
				random_independent_ruler = {
					limit = {
						any_realm_province = {
							county = {
								title = c_faereyar
							}
						}
						
						has_opinion_modifier = {
							who = ROOT
							modifier = rsp
						}
					}
					random_realm_province = {
						limit = {
							county = {
								title = c_faereyar
							}
						}
						
						ROOT = {
							add_trait = adventurer
							set_character_flag = duchy_adventurer
							
							set_defacto_liege = ROOT
							set_government_type = tribal_government
							create_title = {
								tier = DUKE
								landless = yes
								temporary = yes
								culture = ROOT
								name = "VIKING_CONQUEST"
								holder = ROOT
							}
							spawn_unit = {
								province = PREVPREVPREV
								owner = ROOT
								troops = {
									light_infantry = { 250 250 }
									archers = { 140 140 }
								}
								attrition = 0.25
							}
							
							# Create a fleet, just to be sure
							spawn_fleet = {
								province = PREVPREVPREV # closest sea zone
								owner = ROOT
								disband_on_peace = yes
								troops =
								{
									galleys = { 5 5 }
								}
							}
							
							
							
							spawn_unit = {
								province = PREVPREVPREV
								owner = ROOT
								troops = {
									light_infantry = { 250 250 }
									archers = { 140 140 }
								}
								attrition = 0.25
							}
							spawn_fleet = {
								province = PREVPREVPREV # closest sea zone
								owner = ROOT
								disband_on_peace = yes
								
								troops =
								{
									galleys = { 5 5 }
								}
							}
							
							spawn_unit = {
								province = PREVPREVPREV
								owner = ROOT
								troops = {
									light_infantry = { 350 350 }
									archers = { 140 140 }
								}
								attrition = 0.25
							}
							spawn_unit = {
								province = PREVPREVPREV
								owner = ROOT
								troops = {
									light_infantry = { 350 350 }
									archers = { 140 140 }
								}
								attrition = 0.25
							}
							spawn_unit = {
								province = PREVPREVPREV
								owner = ROOT
								troops = {
									light_infantry = { 250 250 }
									archers = { 390 390 }
								}
								attrition = 0.25
							}
							spawn_fleet = {
								province = PREVPREVPREV # closest sea zone
								owner = ROOT
								disband_on_peace = yes
								troops =
								{
									galleys = { 5 5 }
								}
							}
							spawn_fleet = {
								province = PREVPREVPREV # closest sea zone
								owner = ROOT
								disband_on_peace = yes
								troops =
								{
									galleys = { 5 5 }
								}
							}
							spawn_fleet = {
								province = PREVPREVPREV # closest sea zone
								owner = ROOT
								disband_on_peace = yes
								troops =
								{
									galleys = { 15 15 }
								}
							}
							war = {
								target = PREVPREV
								casus_belli = duchy_adventure
								thirdparty_title = PREV
								tier = DUKE
							}
							remove_opinion = {
								who = PREVPREV
								modifier = opinion_duchy_adventure_target
							}
							reverse_remove_opinion = {
								who = PREVPREV
								modifier = rsp
							}
						}
					}
				}
			}
		}
		
		# Create some decent commander characters
		create_random_soldier = {
			random_traits = no
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
		}
		new_character = {
			add_trait = combat_exp
			add_trait = axe2
			
			set_character_flag = wpn
		}
		create_random_soldier = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
		}
		new_character = {
			add_trait = spear3
			set_character_flag = wpn

		}
		
		
		
	}
	
	option = {
		name = OK
	}
}
