﻿
elevate_mann_and_the_isles_scripted_effect = {
	# You gain the Legacy of Piracy dynasty modifier.
	dynasty = {
		add_dynasty_modifier = {
			modifier = fp1_legacy_of_piracy_modifier
			years = 100
		}
		# Also gain a large amount of dynasty prestige.
		add_dynasty_prestige = excessive_dynasty_prestige_gain
	}
	# Cool nickname distributed elsewhere.
	# Mann becomes a kingdom.
	title:d_the_isles = { set_de_jure_liege_title = title:k_mann_the_isles }
	create_title_and_vassal_change = {
		type = created
		save_scope_as = title_change
	}
	title:k_mann_the_isles = {
		change_title_holder = {
			holder = scope:founder
			change = scope:title_change
		}
	}
	resolve_title_and_vassal_change = scope:title_change
	# Buff the Isle of Mann.
	title:c_isle_of_man = {
		# Give it some extra building slots
		title_province = { 
			add_province_modifier = elevate_mann_and_the_isles_modifier
		}
		# And a decent development boost.
		change_development_level = medium_development_level_gain
	}
	# Make it your capital if it wasn't already.
	if = {
		limit = {
			NOT = { capital_county = title:c_isle_of_man }
		}
		set_realm_capital = title:c_isle_of_man
	}
	# And convert it to your culture if it wasn't some flavour of North Germanic.
	if = {
		limit = {
			NOR = {
				title:c_isle_of_man.culture = {
					has_cultural_pillar = heritage_north_germanic
				}
				title:c_isle_of_man.culture = culture:norman
			}
		}
		title:c_isle_of_man = {
			E_kCAFG_convert_culture_in_all_county_provinces = {
				FACTOR = 0.85
				VARIANCE = 0.1
				CULTURE = scope:founder.culture
				MAX = 0.9
			}
		}
	}
	# Have a huge, terrifying event army.
	spawn_army = {
		levies = 5000
		men_at_arms = {
			type = jomsviking_pirates
			stacks = 5
		}
		men_at_arms = {
			type = jomsviking_pirates
			stacks = 5
		}
		men_at_arms = {
			type = varangian_veterans
			stacks = 5
		}
		men_at_arms = {
			type = bondi
			stacks = 5
		}
		men_at_arms = {
			type = bondi
			stacks = 5
		}
		location = title:c_isle_of_man.title_province
		name = fp1_mann_event_troops
	}
	# Mann gets a huge modernising boost.
	title:c_isle_of_man = {
		add_county_modifier = {
			modifier = fp1_mann_pirate_capital_modifier
			years = 100
		}
	}
	# If completely controlled, you integrate the duchies of the Western Isles, the Northern Isles, and Strathclyde.
	## The Western Isles.
	if = {
		limit = { completely_controls = title:d_northern_isles }
		title:d_northern_isles = { set_de_jure_liege_title = title:k_mann_the_isles }
	}
	## The Northern Isles.
	if = {
		limit = { completely_controls = title:d_western_isles }
		title:d_western_isles = { set_de_jure_liege_title = title:k_mann_the_isles }
	}
	## Strathclyde.
	if = {
		limit = { completely_controls = title:d_galloway }
		title:d_galloway = { set_de_jure_liege_title = title:k_mann_the_isles }
	}
	# Plus, if you weren't already, become feudal.
	if = {
		limit = { government_has_flag = government_is_tribal }
		convert_whole_realm_to_feudalism_effect = yes
	}
}
