﻿create_artifact_excalibur_effect = {
	# Get the character the artifact is being made for.
	$OWNER$ = { save_scope_as = owner }
	# Not really used, but if we don't set the scopes we get errors in the feature selection
	set_artifact_rarity_common = yes

	# Create the artifact
	create_artifact = {
		name = excalibur_name
		description = excalibur_description
		type = pedestal
		visuals = excalibur
		wealth = scope:wealth
		quality = scope:quality
		history = {
			type = created_before_history
		}
		modifier = excalibur_modifier
		save_scope_as = newly_created_artifact
		decaying = no
	}

	scope:newly_created_artifact = {
		set_variable = { name = historical_unique_artifact value = yes }
		set_variable = excalibur
		save_scope_as = epic
	}
}

create_artifact_crown_wenceslas_effect = { # Crown of Saint Wenceslas
	# Get the character the artifact is being made for.
	$OWNER$ = { save_scope_as = owner }
	# Not really used, but if we don't set the scopes we get errors in the feature selection
	set_artifact_rarity_famed = yes

	# Create the artifact
	create_artifact = {
		name = crown_wenceslas_name
		description = crown_wenceslas_description
		modifier = crown_wenceslas_modifier
		template = generic_template
		type = pedestal
		visuals = crown_wenceslas_court
		wealth = scope:wealth
		quality = scope:quality
		decaying = no
		save_scope_as = newly_created_artifact
		history = {
			type = created_before_history
			date = 1346.1.1
			location = province:4125 #Praha
		}
	}

	scope:newly_created_artifact = {
		set_variable = { name = historical_unique_artifact value = yes }
		set_variable = crown_wenceslas
		save_scope_as = epic
		add_artifact_history = {
			type = given
			date = 2521.4.3
			recipient = character:zapadoslavia0003 # Dalibor Karlovec
		}
		add_artifact_history = {
			type = given
			date = 2546.4.11
			recipient = character:zapadoslavia0001 # Bedrich Karlovec
		}
		add_artifact_history = {
			type = stolen
			date = 2552.4.12
			recipient = character:zapadoslavia0002 # Bedrich Karlovec
		}
	}
}

create_artifact_sword_wenceslas_effect = { # Ceremonial Czech Sword
	$OWNER$ = { save_scope_as = owner }
	set_artifact_rarity_famed = yes

	create_artifact = {
		name = sword_wenceslas_name
		description = sword_wenceslas_description
		modifier = sword_wenceslas_modifier
		template = sword_wenceslas_template
		type = pedestal
		visuals = sword_wenceslas
		wealth = scope:wealth
		quality = scope:quality
		decaying = no
		save_scope_as = newly_created_artifact
		history = {
			type = created_before_history
			date = 950.1.1
			location = province:4125 #Praha
		}
	}

	scope:newly_created_artifact = {
		set_variable = { name = historical_unique_artifact value = yes }
		set_variable = sword_wenceslas
		save_scope_as = epic
		add_artifact_history = {
			type = given
			date = 2521.4.3
			recipient = character:zapadoslavia0003 # Dalibor Karlovec
		}
		add_artifact_history = {
			type = given
			date = 2546.4.11
			recipient = character:zapadoslavia0001 # Bedrich Karlovec
		}
	}
}

create_artifact_codex_gigas_effect = { # Codex Gigas - largest medieval manuscript
	$OWNER$ = { save_scope_as = owner }
	set_artifact_rarity_illustrious = yes

	create_artifact = {
		name = codex_gigas_name
		description = codex_gigas_description
		modifier = codex_gigas_modifier
		template = codex_template
		type = chronicle
		visuals = chronicle
		wealth = scope:wealth
		quality = scope:quality
		decaying = no
		save_scope_as = newly_created_artifact
		history = {
			type = created_before_history
			date = 1215.1.1
			location = province:4160 #Pardubice
		}
	}

	scope:newly_created_artifact = {
		set_variable = { name = historical_unique_artifact value = yes }
		set_variable = codex_gigas
		save_scope_as = epic
	}
}

create_artifact_crown_stephen_effect = { # Crown of St. Stephen
	$OWNER$ = { save_scope_as = owner }
	set_artifact_rarity_illustrious = yes

	create_artifact = {
		name = crown_stephen_name
		description = crown_stephen_description
		modifier = crown_stephen_modifier
		template = generic_template
		type = helmet
		visuals = pedestal_justinian
		wealth = scope:wealth
		quality = scope:quality
		decaying = no
		save_scope_as = newly_created_artifact
		history = {
			type = created_before_history
			date = 1100.1.1
			location = province:3581 #Višegrad
		}
	}

	scope:newly_created_artifact = {
		set_variable = { name = historical_unique_artifact value = yes }
		set_variable = crown_stephen
		save_scope_as = epic
	}
}

create_artifact_crown_charlemagne_effect = { # Crown of St. Stephen
	$OWNER$ = { save_scope_as = owner }
	set_artifact_rarity_illustrious = yes

	create_artifact = {
		name = crown_charlemagne_name
		description = crown_charlemagne_description
		modifier = crown_charlemagne_modifier
		template = generic_template
		type = helmet
		visuals = crown
		wealth = scope:wealth
		quality = scope:quality
		decaying = no
		save_scope_as = newly_created_artifact
		history = {
			type = created_before_history
			date = 1804.1.1
			location = province:2333 #Paris
		}
	}

	scope:newly_created_artifact = {
		set_variable = { name = historical_unique_artifact value = yes }
		set_variable = crown_charlemagne
		save_scope_as = epic
	}
}

create_artifact_pearl_crown_effect = {
	# Get the character the artifact is being made for.
	$OWNER$ = { save_scope_as = owner }
	# Not really used, but if we don't set the scopes we get errors in the feature selection
	set_artifact_rarity_illustrious = yes
	create_artifact = {
		name = artifact_pearl_crown_name
		description = artifact_pearl_crown_description
		type = helmet
		visuals = pearl_crown
		wealth = scope:wealth
		quality = scope:quality
		history = {
			type = created_before_history
		}
		modifier = pearl_crown_modifier
		save_scope_as = newly_created_artifact
		decaying = no
	}
	scope:newly_created_artifact = {
		set_variable = { name = historical_unique_artifact value = yes }
		set_variable = pearl_crown
		set_variable = {
			name = portrait_remains_after_death
			value = yes
		}
		set_variable = {
			name = artifact_succession_title
			value = title:e_nistrenia
		}
		add_artifact_title_history = {
			target = title:e_nistrenia
			date = 2282.1.11
		}
		save_scope_as = epic
		save_scope_value_as = {
			name = pearl_crown
			value = yes
		}
	}
}

create_artifact_st_edwards_crown_effect = {
	# Get the character the artifact is being made for.
	$OWNER$ = { save_scope_as = owner }
	# Not really used, but if we don't set the scopes we get errors in the feature selection
	set_artifact_rarity_illustrious = yes
	create_artifact = {
		name = artifact_st_edwards_crown_name
		description = artifact_st_edwards_crown_description
		type = helmet
		visuals = st_edwards_crown
		wealth = scope:wealth
		quality = scope:quality
		history = {
			type = created_before_history
		}
		modifier = st_edwards_crown_modifier
		save_scope_as = newly_created_artifact
		decaying = no
	}
	scope:newly_created_artifact = {
		set_variable = { name = historical_unique_artifact value = yes }
		set_variable = st_edwards_crown
		set_variable = {
			name = portrait_remains_after_death
			value = yes
		}
		set_variable = {
			name = artifact_succession_title
			value = title:e_britannia
		}
		add_artifact_title_history = {
			target = title:e_britannia
			date = 2212.1.1
		}
		save_scope_as = epic
		save_scope_value_as = {
			name = st_edwards_crown
			value = yes
		}
	}
}

create_artifact_ak_mace_effect = {
	$OWNER$ = { save_scope_as = owner }
	set_artifact_rarity_masterwork = yes
	create_artifact = {	
		name = artifact_ak_mace_name
		description = artifact_ak_mace_description
		type = regalia
		visuals = ak_mace
		wealth = scope:wealth
		quality = scope:quality
		template = general_unique_template
		history = {
			type = created_before_history
		}
		modifier = ak_mace_modifier
		save_scope_as = newly_created_artifact
	}
	scope:newly_created_artifact = {
		set_variable = { name = historical_unique_artifact value = yes }
		set_variable = ak_mace
		save_scope_as = epic
	}
}

create_artifact_chad_ironside_skull_effect = {
	$OWNER$ = { save_scope_as = owner }
	set_artifact_rarity_illustrious = yes

	scope:owner = {
		create_artifact = {
			name = skull_saint_chad_name
			description = skull_saint_chad_desc
			template = skull_chad_ironside_template
			type = pedestal
			visuals = human_skull
			wealth = scope:wealth
			quality = scope:quality
			modifier = skull_saint_chad_modifier
			decaying = no
			save_scope_as = newly_created_artifact
			history = {
				type = created_before_history
			}
		}
	}

	scope:newly_created_artifact = {
		set_variable = { name = historical_unique_artifact value = yes }
		set_variable = { name = neow_chad_ironside_skull value = yes }
		save_scope_as = epic

		# Make the initial identity match the first owner.
		neow_chad_ironside_skull_effect = yes
	}
}

neow_chad_ironside_skull_effect = {
	if = {
		limit = {
			has_variable = neow_chad_ironside_skull
			exists = artifact_owner
		}

		if = {
			limit = {
				artifact_owner = {
					OR = {
						has_religion = religion:britannic_religion
						has_religion = religion:thelema_religion
					}
				}
			}

			# Britannic or Thelemic interpretation: the Ironside.
			set_artifact_name = skull_ironside_name
			set_artifact_description = skull_ironside_desc

			if = {
				limit = {
					has_artifact_modifier = skull_saint_chad_modifier
				}
				remove_artifact_modifier = skull_saint_chad_modifier
			}

			if = {
				limit = {
					NOT = {
						has_artifact_modifier = skull_ironside_modifier
					}
				}
				add_artifact_modifier = skull_ironside_modifier
			}
		}
		else = {
			# All other owners: Saint Chad.
			set_artifact_name = skull_saint_chad_name
			set_artifact_description = skull_saint_chad_desc

			if = {
				limit = {
					has_artifact_modifier = skull_ironside_modifier
				}
				remove_artifact_modifier = skull_ironside_modifier
			}

			if = {
				limit = {
					NOT = {
						has_artifact_modifier = skull_saint_chad_modifier
					}
				}
				add_artifact_modifier = skull_saint_chad_modifier
			}
		}
	}
}

