﻿
korea_unify_goryeo_reward_effect = {
	# Legend Seed
	gain_heroic_legend_seed_tooltip_effect = yes
	# Create new titles
	create_title_and_vassal_change = {
		type = created
		save_scope_as = title_change
	}
	title:e_goryeo = {
		change_title_holder = {
			holder = scope:king_of_goryeo
			change = scope:title_change
		}
	}
	resolve_title_and_vassal_change = scope:title_change
	tgp_setup_ceremonial_regent_title_effect = {
		FOUNDER = this
		CEREMONIAL_TITLE = title:k_yongson_throne
	}
	# Destroy old titles
	title:k_silla = { add_to_list = korea_kingdoms }
	title:k_baekje = { add_to_list = korea_kingdoms }
	title:k_goguryeo = { add_to_list = korea_kingdoms }
	every_in_list = {
		list = korea_kingdoms
		limit = { holder = scope:king_of_goryeo }
		save_scope_as = korean_kingdom 
		scope:king_of_goryeo = { destroy_title = scope:korean_kingdom }
	}
	# Cultural acceptance (move towards Goryeo culture)
	every_culture_global = {
		limit = {
			NOT = { this = scope:king_of_goryeo.culture }
			OR = {
				has_cultural_pillar = heritage_buyeo
				has_cultural_pillar = heritage_korean
				any_parent_culture = {
					OR = {
						has_cultural_pillar = heritage_buyeo
						has_cultural_pillar = heritage_korean
					}
				}
			}
			any_culture_county = {
				any_county_province = { geographical_region = world_asia_korea }
			}
		}
		add_to_list = goryeo_cultures
	}
	every_in_list = {
		list = goryeo_cultures
		change_cultural_acceptance = {
			target = root.culture
			value = 25
			desc = cultural_acceptance_gain_unify_goryeo
		}
	}
}

tgp_create_ceremonial_regent_title_effect = {
	$FOUNDER$ = { save_scope_as = founder }
	create_dynamic_title = {
		tier = kingdom
		name = MERITOCRATIC_CEREMONIAL_LIEGE_TITLE
	}
	scope:new_title = {
		set_variable = {
			name = ceremonial_title
			value = scope:founder.primary_title
		}
		set_definitive_form = yes
		set_coa = scope:founder.house
	}
	tgp_setup_ceremonial_regent_title_effect = {
		FOUNDER = scope:founder
		CEREMONIAL_TITLE = scope:new_title
	}
}

tgp_setup_ceremonial_regent_title_effect = {
	$CEREMONIAL_TITLE$ = { save_scope_as = new_title }
	$FOUNDER$ = { save_scope_as = founder }
	create_title_and_vassal_change = {
		type = created
		save_scope_as = change
		add_claim_on_loss = yes
	}
	scope:new_title = {
		change_title_holder = {
			holder = scope:founder
			change = scope:change
		}
	}
	resolve_title_and_vassal_change = scope:change
	scope:new_title = { add_title_law = single_heir_succession_law } # Regency inherited separately
	scope:founder.primary_title = {
		save_scope_as = regent_title
		set_variable = {
			name = administrative_ui_special_title
			value = scope:new_title
		}
	}
	scope:founder = {
		add_realm_law_skip_effects = single_heir_succession_law # Regency inherited separately
	}
}
