﻿long_night_story = {
	on_setup = {
			
	story_owner = {
	if = { limit = { game_start_date >= 8300.1.1 }
	add_character_flag = { flag = long_night_cooldown years = 2 }	 
	}
	add_character_flag = { flag = war_for_dawn_cooldown years = 10 }
	add_character_flag = mw_init_event_blocker
	add_character_flag = agot_immersion_bannermen_blocker
	save_scope_as = thegreatother
	set_house = house:house_theothers
	every_courtier = { 
	if = { limit = { has_trait = dwarf } remove_trait = dwarf }
	if = { limit = { has_trait = gluttonous } remove_trait = gluttonous }
	set_culture = culture:frostborn
	set_character_faith = faith:cold_gods
	#set_father = scope:thegreatother
	set_house = house:house_theothers
	add_trait = other_trait
	add_trait = spindly
	make_trait_inactive = cool_silver_hair
	make_trait_inactive = blue_eyes
	change_age = 7000
	change_first_name = other_name
	 add_character_flag = agot_immersion_bannermen_blocker
	 ### Sword
	set_artifact_rarity_illustrious = yes
	create_artifact = {
		name = others_sword
		visuals = others_sword_visuals
		description = others_sword_description
		type = sword
		wealth = scope:wealth
		quality = scope:quality
		template = others_sword_template
		history = {
			type = created_before_history
			date = 50.1.1
		}
		modifier = others_sword_modifier
		save_scope_as = newly_created_artifact
		decaying = yes
	}
	scope:newly_created_artifact = {
		set_variable = { name = historical_unique_artifact value = yes }
		equip_artifact_to_owner = yes
	}
	}
	every_character_artifact = { limit = {  has_variable = crown_of_true_winter_artifact } equip_artifact_to_owner = yes }
	
	
	}
	
	}
	on_end = {
	
	### Reform Nightswatch
	if = { limit = { NOT = { title:c_castle_black.holder = { has_government = nights_watch_government } }
	title:c_castle_black.holder = { is_ai = yes }
	}
		 longnight_reform_nightswatch_effect = yes
		 }
		 
	
	title:e_others.holder = { 
	save_scope_as = lastother
		destroy_others_kingdom_titles = yes
		random_courtier = { limit = { has_trait = other_trait
										is_female = yes}
							add_character_flag = nightsqueen
							save_scope_as nightsqueen
							add_trait = disinherited
							}
		culture = {
			clear_culture_traditions = yes
			add_culture_tradition = agot_tradition_wildling
			add_culture_tradition = tradition_mountain_homes
			add_culture_tradition = tradition_winter_warriors
			add_culture_tradition = tradition_tribe_unity
		set_culture_name = {
noun = frostborn_culture_name
collective_noun = frostborn_culture_name
prefix = frostborn_culture_name
}
		}
		
		
		#destroy_title = title:e_others
		}
		house:house_theothers = {  every_house_member = { limit = { NOT = { has_character_flag = nightsqueen } } death = {
						
						death_reason = death_vanished
					} } }
					
		
	if = { limit = { has_game_rule = longnight_iron_throne_reformation_on }	 
	if = { limit = { exists = title:e_the_iron_throne.holder} 
	title:e_the_iron_throne.holder = { trigger_event = {
						id = others_maintenance.2
						days = 1
					}
					}
					
	}
	}
		
		
		
	
		
		
		every_player = {
					trigger_event = {
						id = others.3
						days = 1
					}
				}
		

	
	}
	
	on_owner_death = { 
	
	if = { limit = { has_game_rule = others_death_resolution }
	
	end_story = yes
	}
	else = {
	make_story_owner = story_owner.primary_heir
	 story_owner = { add_trait = nightking 
	 if = { limit = { has_game_rule = others_weak_invasion } add_character_modifier = others_weak_modifier }
								if = { limit = { has_game_rule = others_standard_invasion } add_character_modifier = others_standard_modifier }
								if = { limit = { has_game_rule = others_strong_invasion } add_character_modifier = others_strong_modifier }
								if = { limit = { has_game_rule = others_insane_invasion } add_character_modifier = others_insane_modifier }
	 
	 
	 }
	}
	if = { limit = { AND = { has_game_rule = others_war_resolution 
							 has_global_variable = war_for_dawn_victory
							}
							}
							end_story = yes
	}
	
	}
	
	effect_group = {
        days = 30

	
	triggered_effect = {
			trigger = {

			NOT = { story_owner = { is_at_war = yes } } 
			
			NOR = { story_owner = { has_character_flag = long_night_peace }
					story_owner = { has_character_flag = long_night_over }
					story_owner = { has_character_flag = long_night_cooldown }
					}
			}	# otherwise, check for this trigger
			effect = {
		story_owner = {	random_neighboring_top_liege_realm_owner = {
			limit = {
				NOR = {
					culture = {
						has_cultural_parameter = other_parameter
					}
					faith = faith:cold_gods
					has_trait = other_trait
				}
				is_independent_ruler = yes
				highest_held_title_tier >= tier_county
				is_landed = yes
			}
			save_scope_as = othervictim_character
		}
		if = { limit = { OR = { 	
scope:othervictim_character = { any_sub_realm_county = { count >= 4 } }
scope:othervictim_character = { highest_held_title_tier = tier_empire }
scope:othervictim_character = { is_ai = no }
}				}
		start_war = {
			casus_belli = other_cb
			target = scope:othervictim_character
		}
		}
		else = {
			create_title_and_vassal_change = {
		type = swear_fealty
		save_scope_as = change
					}
	scope:othervictim_character = {
		change_liege = {
			liege = title:e_others.holder
			change = scope:change
		}
	}
	resolve_title_and_vassal_change = scope:change
		
		
			}
			}

			

			}
		}
		
	
	

		
			}
			
			
			effect_group = {
        days = 10

	
			triggered_effect = {
		trigger = { 
					story_owner = { has_culture = culture:frostborn }
					}
		effect = {
		story_owner = {
		add_stress = -300
		if = { limit = { gold >= 250 }
		remove_reserved_gold = 250
		}
		if = { limit = { gold < 1 }
		add_gold = 100
		}
			
			every_character_artifact = { limit = {  has_variable = crown_of_true_winter_artifact } equip_artifact_to_owner_replace = yes }
		save_scope_as = thegreatother
		every_courtier = { 
								if =  { limit = { AND = { has_culture = culture:frostborn
											has_faith = faith:cold_gods 
											NOT = { has_trait = other_trait} }
											

														}
											if = { limit = { has_trait = dwarf } remove_trait = dwarf }
											add_trait = other_trait
											add_trait = spindly
											make_trait_inactive = cool_silver_hair
											make_trait_inactive = blue_eyes
										 change_age = 7000
										 change_first_name = other_name
										 add_character_flag = agot_immersion_bannermen_blocker
										 #set_father = scope:thegreatother
										 set_house = scope:thegreatother.house
											}
										 
							if = { limit = { NOT = { has_faith = faith:cold_gods }
											NOT = { has_trait = dragon }
								    }
							 
							 random_list = {
			50 = {
				death = {
					killer = scope:thegreatother
					death_reason = death_sacrificed_to_gods
				}
			}
			50 = {
				death = {
					killer = scope:thegreatother
					death_reason = death_ripped_apart_limb_by_limb
				}
			}
		}
		}
		}
			every_prisoner = {
		random_list = {
				50 = {
					death = {
						killer = scope:thegreatother
						death_reason = death_sacrificed_to_gods
					}
				}
				50 = {
					death = {
						killer = scope:thegreatother
						death_reason = death_ripped_apart_limb_by_limb
					}
				}
			}
		
		}
			
	
								
		}								
		
		
		}
		
	}
		
	
	

		
			}
			
			
#		effect_group = {
#        days = 180
#
#	
#			triggered_effect = {
#		trigger = { 
#					story_owner = { has_culture = culture:frostborn
#									completely_controls = title:c_castle_black
#									NOT = { has_character_flag = war_for_dawn_cooldown }
#									 has_character_flag = long_night_cooldown 
#
#					}
#					}
#		effect = {
#		story_owner = {
#		save_scope_as = thegreatother
#		ordered_vassal = {
#		limit = { NOT = { has_faith = faith:cold_gods } }
#		order_by = {
#					value = 0
#					add = max_military_strength
#				}
#		save_scope_as = uprising_vassal
#			title:e_others.holder = { if = { limit = { any_character_war = {
#								is_defender = title:e_others.holder
#								using_cb = war_for_the_dawn_cb	}
#										   }
#								random_character_war = {
#								limit = {
#								is_defender = title:e_others.holder
#								using_cb = war_for_the_dawn_cb
#							}
#
#							add_attacker = scope:uprising_vassal
#						}
#							}
#							else = {
#						scope:uprising_vassal = {
#							start_war = {
#								cb = war_for_the_dawn_cb
#								target = title:e_others.holder
#							
#							}
#						}
#					}
#									
#	}
#		
#		
#		
#		}
#	
#	
#	}
#	}
#	
#		
#	}
#	
#
#		
#			}
			
			effect_group = {
        days = 365

	
			triggered_effect = {
		trigger = { 
					story_owner = { has_culture = culture:frostborn
									

					}
					}
		effect = {
		story_owner = {
		save_scope_as = thegreatother
		every_vassal_or_below = {
			limit = { NOT = { has_character_flag = others_sacrifice_event }
					NOT = { is_at_war_with_liege = yes }
					highest_held_title_tier >= tier_county
			}
			add_character_flag = { flag = others_sacrifice_event years = 5 }
			trigger_event = others_occupation.1
		
		
		
		}
	
	
	}
	}
	
		
	}
	

		
			}
			
			
			effect_group = {
        days = 180

	
			triggered_effect = {
		trigger = { 
					story_owner = { has_culture = culture:frostborn
									

					}
					}
		effect = {
		story_owner = {
		save_scope_as = thegreatother
		every_vassal_or_below = { 
								if =  { limit = { AND = { has_culture = culture:frostborn
											has_faith = faith:cold_gods 
											NOT = { has_trait = other_trait} }

														}
														change_first_name = other_name
														 add_character_flag = agot_immersion_bannermen_blocker
											if = { limit = { has_trait = dwarf } remove_trait = dwarf }
											if = { limit = { has_trait = gluttonous } remove_trait = gluttonous }
											add_trait = other_trait
											add_trait = spindly
											change_age = 7000
											set_house = scope:thegreatother.house
											#set_father = scope:thegreatother
											}
										 
							
		}
		every_vassal = { limit = { AND = {  is_ai = yes
											NOT = { has_faith = faith:cold_gods }
											NOT = { has_character_flag = cannot_be_knight_and_commander  }
											NOT = { is_at_war = yes }
												}
												}
									add_character_flag = { flag = cannot_be_knight_and_commander years = 1 }
									}
	
	
	}
	}
	
		
	}
	

		
			}
			
			
			
			
			#### Take HArrenhal
			
			effect_group = {
        years = 2

	
			triggered_effect = {
		trigger = { 
					story_owner = { has_culture = culture:frostborn
					completely_controls = title:c_harrenhal
					NOT = { has_title = title:c_harrenhal }
					}
					title:c_harrenhal.holder = { is_ai = yes }
					}
		effect = {
		story_owner = {
		save_scope_as = thegreatother
		get_title = title:c_harrenhal
		set_realm_capital = title:c_harrenhal
	
	
	}
	}
	
		
	}
	

		
			}
	### Ice Dragon	
			effect_group = {
        years = 3

	
			triggered_effect = {
		trigger = { 
					has_game_rule = agot_long_night_dragon_on
					agot_dragon_population_extinct = no
					story_owner = { 
					has_trait = other_trait
					NOT = { has_trait = dragonrider }
					}
					
					
					}
		effect = {
		story_owner = {
		if = { limit = { has_trait = dragonless_dragonrider  }
		remove_trait = dragonless_dragonrider 
		}
		agot_spawn_adult_ice_dragon_effect = yes
		
	
		}
	}
	
		
	}
	

		
			}
			
			#### Fix the Story Owner
			
			effect_group = {
        years = 1

	
			triggered_effect = {
		trigger = { 
					story_owner = { NOT = { has_title = title:e_others } 
					}
					
					}
		effect = {
		save_scope_as = originalnightking
		title:e_others.holder = { if = { limit = { has_trait = other_trait } make_story_owner = this add_trait = nightking } 
								  else = { random_ruler = { limit = { has_trait = other_trait NOT = { this = scope:originalnightking } } save_scope_as = thegreatother add_trait nightking }  make_story_owner = scope:thegreatother set_designated_heir = scope:thegreatother depose = yes }
								}
}								
								 
	}
	
		
	}
	

		
			}
			
			
			
			
			
			
			
			
			
			}
			
			
			
	



				
			
					
					
					
					
			
					
					
					
	
		