﻿##########################################
# Court Artifact Creation and Decoration #
##########################################

###############
# CHEST

create_artifact_chest_effect = {
	# Get the character the artifact is being made for.
	$OWNER$ = { save_scope_as = owner }
	$CARPENTER$ = { save_scope_as = carpenter }
	hidden_effect_new_object = {
		# Get artifact quality, wealth, and materials
		get_artifact_quality_effect = yes
		get_artifact_wealth_effect = yes

		scope:owner = {
			# Create the artifact
			create_artifact = {	
				name = artifact_chest_name
				creator = scope:carpenter
				description = placeholder # Will be regenerated in the post-creation effects
				visuals = chest
				type = chest
				modifier = artifact_placeholder_modifier
				save_scope_as = newly_created_artifact
				wealth = scope:wealth
				quality = scope:quality
				#decaying = no
			}
		}

		scope:newly_created_artifact = {
			get_artifact_feature_references_effect = yes
			set_artifact_description = artifact_chest_description
			set_variable = {
				name = big_chest
				value = yes
			}
			
			add_scaled_artifact_modifier_grandeur_small_effect = yes
			add_scaled_artifact_modifier_piety_effect = yes
			if = {
				limit = {
					OR = {
						rarity = famed
						rarity = illustrious
					}
				}
				add_scaled_artifact_modifier_dynasty_prestige_effect = yes
			}
			remove_artifact_modifier = artifact_placeholder_modifier
		}
	}	
}

create_artifact_cabinet_effect = {
	# Get the character the artifact is being made for.
	$OWNER$ = { save_scope_as = owner }
	$CARPENTER$ = { save_scope_as = carpenter }
	hidden_effect_new_object = {
		# Get artifact quality, wealth, and materials
		get_artifact_quality_effect = yes
		get_artifact_wealth_effect = yes

		# Create the artifact
		# Indian cabinets are actually diwans!
		if = {
			limit = {
				scope:carpenter = { artifact_use_indian_building_visuals_trigger = yes }
			}
			scope:owner = {
				create_artifact = {
					name = artifact_diwan_name
					creator = scope:carpenter
					description = placeholder # Will be regenerated in the post-creation effects
					visuals = diwan
					type = cabinet
					modifier = artifact_placeholder_modifier
					save_scope_as = newly_created_artifact
					wealth = scope:wealth
					quality = scope:quality
					#decaying = no
				}
			}
		}
		#Mena cabinets are actually tables!
		else_if = {
			limit = {
				scope:carpenter = {
					OR = {
						artifact_use_mena_building_visuals_trigger = yes
						artifact_use_iranian_building_visuals_trigger = yes
						artifact_use_steppe_building_visuals_trigger = yes
					}
				}
			}
			scope:owner = {
				create_artifact = {
					name = artifact_table_name
					creator = scope:carpenter
					description = placeholder # Will be regenerated in the post-creation effects
					visuals = table
					type = cabinet
					modifier = artifact_placeholder_modifier
					save_scope_as = newly_created_artifact
					wealth = scope:wealth
					quality = scope:quality
					#decaying = no
				}
			}
		}
		else = {
			scope:owner = {
				create_artifact = {
					name = artifact_cabinet_name
					creator = scope:carpenter
					description = placeholder # Will be regenerated in the post-creation effects
					visuals = cabinet
					type = cabinet
					modifier = artifact_placeholder_modifier
					save_scope_as = newly_created_artifact
					wealth = scope:wealth
					quality = scope:quality
					#decaying = no
				}
			}
		}
		scope:newly_created_artifact = {
			get_artifact_feature_references_effect = yes

			add_scaled_artifact_modifier_grandeur_small_effect = yes
			add_scaled_artifact_modifier_piety_effect = yes
			if = {
				limit = {
					OR = {
						rarity = famed
						rarity = illustrious
					}
				}
				add_scaled_artifact_modifier_dynasty_prestige_effect = yes
			}
			remove_artifact_modifier = artifact_placeholder_modifier
			# Indian cabinets are actually diwans!
			if = {
				limit = {
					scope:carpenter = { artifact_use_indian_building_visuals_trigger = yes }
				}
				set_artifact_description = artifact_diwan_description
			}
			else_if = {
				limit = {
					scope:carpenter = {
						OR = {
							artifact_use_mena_building_visuals_trigger = yes
							artifact_use_iranian_building_visuals_trigger = yes
							artifact_use_steppe_building_visuals_trigger = yes
						}
					}
				}
				set_artifact_description = artifact_table_description
			}
			else = {
				set_variable = {
					name = cabinet
					value = yes
				}
				set_artifact_description = artifact_cabinet_description
			}
		}
	}
}

create_artifact_throne_effect = {
	# Get the character the artifact is being made for.
	$OWNER$ = { save_scope_as = owner }
	$MAKER$ = { save_scope_as = maker }
	hidden_effect_new_object = {
		# Get artifact quality, wealth, and materials
		get_artifact_quality_effect = yes
		get_artifact_wealth_effect = yes

		# Create the artifact
		scope:owner = {
			create_artifact = {	
				name = artifact_throne_name
				description = placeholder # Will be regenerated in the post-creation effects
				creator = scope:maker
				visuals = throne
				type = throne
				modifier = artifact_placeholder_modifier
				save_scope_as = newly_created_artifact
				wealth = scope:wealth
				quality = scope:quality
				#decaying = no
			}
		}
		scope:newly_created_artifact = {
			set_artifact_description = artifact_throne_description
			
			#Let's add modifiers!
			add_scaled_artifact_modifier_prestige_effect = yes
			if = {
				limit = { rarity = illustrious }
				add_scaled_artifact_modifier_majesty_effect = yes
				add_scaled_artifact_modifier_rulership_effect = yes
			}
			else_if = {
				limit = { rarity = famed }
				add_scaled_artifact_modifier_majesty_effect = yes
			}
			
			# All thrones have a chance to get some extra Grandeur
			add_scaled_artifact_modifier_grandeur_big_effect = yes
			remove_artifact_modifier = artifact_placeholder_modifier
		}
	}
}


###############
# TAPESTRY

create_artifact_tapestry_effect = {
	# Get the character the artifact is being made for.
	$OWNER$ = { save_scope_as = owner }
	$WEAVER$ = { save_scope_as = weaver }

	hidden_effect_new_object = {
		# Get artifact quality, wealth, and materials
		get_artifact_quality_effect = yes
		get_artifact_wealth_effect = yes
		if = { #If the scene has been set in events we save it on the owner here so we can access it when choosing features
			limit = { exists = scope:tapestry_scene	}
			scope:owner = {
				set_variable = {
					name = artifact_tapestry_scene
					value = scope:tapestry_scene
					days = 1
				}
			}
		}
		# Fallback
		else = {
			random_list = {
				10 = {
					scope:owner = {
						set_variable = {
							name = artifact_tapestry_scene
							value = flag:geometric_patterns
							days = 1
						}
					}
				}
				10 = {
					scope:owner = {
						set_variable = {
							name = artifact_tapestry_scene
							value = flag:garden
							days = 1
						}
					}
				}
				10 = {
					scope:owner = {
						set_variable = {
							name = artifact_tapestry_scene
							value = flag:bucolic
							days = 1
						}
					}
				}
			}
		}
		# Create the artifact
		scope:owner = {
			if = {
				limit = {
					exists = scope:inspiration_owner
				}
				create_artifact = {	
					name = artifact_wall_tapestry_name
					description = placeholder # Will be regenerated in the post-creation effects
					creator = scope:weaver
					visuals = tapestry
					type = tapestry
					modifier = artifact_placeholder_modifier
					save_scope_as = newly_created_artifact
					wealth = scope:wealth
					quality = scope:quality
					#decaying = no
				}
			}
			else_if = {
				limit = {
					exists = scope:adventurer
				}
				create_artifact = {	
					name = artifact_wall_tapestry_name
					description = placeholder # Will be regenerated in the post-creation effects
					creator = scope:adventurer
					visuals = tapestry
					type = tapestry
					modifier = artifact_placeholder_modifier
					save_scope_as = newly_created_artifact
					wealth = scope:wealth
					quality = scope:quality
					#decaying = no
					history = {
						location = scope:location
						actor = scope:adventurer
						recipient = root
						type = discovered
					}
				}
			}
			else = {
				create_artifact = {	
					name = artifact_wall_tapestry_name
					description = placeholder # Will be regenerated in the post-creation effects
					creator = scope:weaver
					visuals = tapestry
					type = tapestry
					modifier = artifact_placeholder_modifier
					save_scope_as = newly_created_artifact
					wealth = scope:wealth
					quality = scope:quality
					#decaying = no
				}
			}
		}
		scope:newly_created_artifact = {
			set_artifact_description = artifact_wall_tapestry_description
			# Set grandeur
			add_scaled_artifact_modifier_grandeur_big_effect = yes
			
			if = {
				limit = {
					has_artifact_feature = tapestry_scene_religious
				}
				add_scaled_artifact_modifier_piety_effect = yes
			}
			else = {
				add_scaled_artifact_modifier_majesty_effect = yes
			}

			if = {
				limit = {
					OR = {
						rarity = famed
						rarity = illustrious
					}
				}
				add_scaled_artifact_modifier_dynasty_prestige_effect = yes
			}
			remove_artifact_modifier = artifact_placeholder_modifier
		}
	}
}


###############
# HIDE

#If the animal has been hunted we need to provide a location
get_animal_hunt_location_effect = {
	if = {
		limit = {
			NOT = { exists = scope:location }
		}
		if = {
			limit = {
				exists = scope:owner.involved_activity
				scope:owner.involved_activity = { has_activity_type = activity_hunt }
			}
			scope:owner.involved_activity.activity_location = { save_scope_as = location }
		}
		else = {
			scope:owner = {
				random_list = {
					30 = { #It's hunted in your own realm
						trigger = {
							any_sub_realm_county = {
								exists = this
							}
						}
						random_sub_realm_county = {
							random_county_province = { save_scope_as = location }
						}
					}
					30 = { #It's hunted in a neighbors realm
						trigger = {
							highest_held_title_tier >= tier_county
							any_neighboring_realm_same_rank_owner = {
								exists = capital_county
							}
						}
						random_neighboring_realm_same_rank_owner = {
							limit = { 
								exists = capital_county
							}
							capital_county = {
								random_county_province = { save_scope_as = location }
							}
						}
					}
					1 = { # It's hunted in our current location (as a fallback if we're unlanded or only a baron).
						trigger = {
							OR = {
								highest_held_title_tier < tier_county 
								is_landed = no
							}
						}
						location.county = {
							random_county_province = { save_scope_as = location }
						}
					}
				}
			}
		}
	}
	scope:owner = {
		if = {
			limit = {
				NOT = { has_variable = adventure_artifact_location }
			}
			set_variable = {
				name = adventure_artifact_location
				value = scope:location
				days = 1
			}
		}
		if = {
			limit = {
				NOT = { has_variable = adventure_artifact_hunter }
				exists = scope:creator
			}
			set_variable = {
				name = adventure_artifact_hunter
				value = scope:creator
				days = 1
			}
		}
		else_if = {
			limit = {
				NOT = { has_variable = adventure_artifact_hunter }
			}
			set_variable = {
				name = adventure_artifact_hunter
				value = scope:owner
				days = 1
			}
		}
	}
}

create_artifact_animal_hide_effect = {
	# Get the character the artifact is being made for.
	$OWNER$ = { save_scope_as = owner }
	$HUNTER$ = { save_scope_as = hunter }
	save_scope_value_as = { name = legendary value = $LEGENDARY$ }
	scope:owner = {
		set_variable = { name = animal_type value = $ANIMAL$ days = 5 }
		if = {
			limit = {
				OR = {
					NOT = { exists = var:animal_type }
					var:animal_type ?= flag:none
				}
			}
			random_list = {
				8 = {
					hunt_activity_standard_game_effect = { PROVINCE = scope:hunter.location HUNTER = scope:hunter }
				}
				2 = {
					hunt_activity_dangerous_game_effect = { PROVINCE = scope:hunter.location }
				}
			}
		}
	}
	if = {
		limit = { exists = scope:adventurer }
		scope:adventurer = { save_scope_as = creator }
	}
	else = {
		scope:hunter = { save_scope_as = creator }
	}
	hidden_effect_new_object = {
		# Get artifact quality, wealth, and materials
		animal_artifact_wealth_quality_effect = yes
		get_animal_hunt_location_effect = yes
		scope:location = { add_to_list = artifact_material_sources }
		if = {
			limit = {
				OR = {
					hunt_hide_big_trigger = { VARIABLE = scope:owner.var:animal_type }
					AND = {
						exists = scope:animal_hide_size
						scope:animal_hide_size = flag:big
					}
				}
			}		
			if = {
				limit = {
					NOT = { exists = scope:animal_hide_size }
				}
				save_scope_value_as = { name = animal_hide_size value = flag:big }
			}
			scope:owner = {
				create_artifact = {	
					name = artifact_animal_hide_big_name
					creator = scope:creator
					description = placeholder
					visuals = large_animal_hide
					type = animal_hide_big
					modifier = artifact_placeholder_modifier
					wealth = scope:wealth
					quality = scope:quality
					save_scope_as = newly_created_artifact
				}
				scope:newly_created_artifact = {
					# Set grandeur
					add_scaled_artifact_modifier_grandeur_big_effect = yes
					# Set prestige
					add_scaled_artifact_modifier_prestige_effect = yes
				}	
			}				
		}
		else = {
			if = {
				limit = {
					NOT = { exists = scope:animal_hide_size }
				}
				save_scope_value_as = { name = animal_hide_size value = flag:small }
			}
			scope:owner = {
				create_artifact = {
					name = artifact_small_hide_name
					creator = scope:creator
					description = placeholder
					visuals = small_animal_hide
					type = animal_hide
					modifier = artifact_placeholder_modifier
					wealth = scope:wealth
					quality = scope:quality
					save_scope_as = newly_created_artifact
				}
				scope:newly_created_artifact = {
					if = {
						limit = {
							has_artifact_feature = animal_hide_type_cat
							exists = scope:owner.var:story_cycle_cat_name
						}
						set_variable = {
							name = pet_name
							value = scope:owner.var:story_cycle_cat_name
						}
					}
					else_if = {
						limit = {
							has_artifact_feature = animal_hide_type_dog
							exists = scope:owner.var:story_cycle_dog_name
						}
						set_variable = {
							name = pet_name
							value = scope:owner.var:story_cycle_dog_name
						}
					}
					# Set grandeur
					add_scaled_artifact_modifier_grandeur_small_effect = yes
					# Set prestige
					add_scaled_artifact_modifier_minor_prestige_effect = yes
				}
			}
		}
		scope:newly_created_artifact = {
			set_max_durability = 60
			set_variable = {
				name = adventure_artifact_location
				value = scope:owner.var:adventure_artifact_location
			}
			set_variable = {
				name = adventure_artifact_hunter
				value = scope:owner.var:adventure_artifact_hunter
			}
			if = {
				limit = {
					OR = {
						rarity = famed
						rarity = illustrious
					}
				}
				add_scaled_artifact_modifier_dynasty_prestige_effect = yes
			}
			remove_artifact_modifier = artifact_placeholder_modifier
			set_variable = {
				name = animal_type
				value = scope:owner.var:animal_type
			}
			set_variable = {
				name = quality
				value = scope:quality
			}
			set_variable = {
				name = wealth
				value = scope:wealth
			}
			hunt_animal_artifact_modifier_selection_effect = yes
			if = {
				limit = { scope:legendary = yes }
				set_artifact_name = artifact_animal_hide_name_legendary
				set_variable = { name = legendary }
				add_scaled_artifact_modifier_majesty_effect = yes
				add_scaled_artifact_modifier_combat_effect = yes
			}
			else_if = {
				limit = { exists = scope:adventurer }
				set_artifact_name = artifact_animal_hide_name_adventurer
			}
			else_if = {
				limit = { exists = var:pet_name }
				if = {
					limit = { has_artifact_feature = animal_hide_type_cat }
					set_artifact_name = artifact_animal_hide_name_cat
				}
				else_if = {
					limit = { has_artifact_feature = animal_hide_type_dog }
					set_artifact_name = artifact_animal_hide_name_dog
				}
			}
			else_if = {
				limit = { artifact_type = animal_hide_big }
				set_artifact_name = artifact_animal_hide_big_name
			}
			else = { set_artifact_name = artifact_small_hide_name }
			set_artifact_description = artifact_small_hide_description
		}
		scope:owner = {
			remove_variable = adventure_artifact_location
			remove_variable = adventure_artifact_hunter
		}
	}
}

##################
# SKULL

create_artifact_wall_skull_effect = {
	$OWNER$ = { save_scope_as = owner }
	$HUNTER$ = { save_scope_as = hunter }
	save_scope_value_as = { name = legendary value = $LEGENDARY$ }
	scope:owner = {
		set_variable = { name = animal_type value = $ANIMAL$ days = 5 }
		if = {
			limit = {
				OR = {
					NOT = { exists = var:animal_type }
					var:animal_type ?= flag:none
				}
			}
			random_list = {
				8 = {
					hunt_activity_standard_game_effect = { PROVINCE = scope:hunter.location HUNTER = scope:hunter }
				}
				2 = {
					hunt_activity_dangerous_game_effect = { PROVINCE = scope:hunter.location }
				}
			}
		}
	}
	if = {
		limit = { exists = scope:adventurer }
		scope:adventurer = { save_scope_as = creator }
	}
	else = {
		scope:hunter = { save_scope_as = creator }
	}
	hidden_effect_new_object = {
		# Get artifact quality, location, and animal
		animal_artifact_wealth_quality_effect = yes
		get_animal_hunt_location_effect = yes
		scope:location = { add_to_list = artifact_material_sources }
		scope:owner = {
			create_artifact = {	
				name = artifact_wall_skull_name
				description = placeholder
				creator = scope:creator
				visuals = animal_trophy
				type = animal_skull
				modifier = artifact_placeholder_modifier
				wealth = scope:wealth
				quality = scope:quality
				save_scope_as = newly_created_artifact
			}
		}
		scope:newly_created_artifact = {
			set_max_durability = 60
			# Set grandeur
			add_scaled_artifact_modifier_grandeur_small_effect = yes
			# Set prestige
			add_scaled_artifact_modifier_minor_prestige_effect = yes
			if = {
				limit = {
					OR = {
						rarity = famed
						rarity = illustrious
					}
				}
				add_scaled_artifact_modifier_dynasty_prestige_effect = yes
			}
			remove_artifact_modifier = artifact_placeholder_modifier
			set_variable = {
				name = animal_type
				value = scope:owner.var:animal_type
			}
			set_variable = {
				name = quality
				value = scope:quality
			}
			set_variable = {
				name = wealth
				value = scope:wealth
			}
			hunt_animal_artifact_modifier_selection_effect = yes
			if = {
				limit = { scope:legendary = yes }
				set_artifact_name = artifact_wall_skull_name_legendary
				set_variable = { name = legendary }
				add_scaled_artifact_modifier_majesty_effect = yes
				add_scaled_artifact_modifier_combat_effect = yes
			}
			else_if = {
				limit = { exists = scope:adventurer }
				set_artifact_name = artifact_wall_skull_name_adventurer
			}
			else = { set_artifact_name = artifact_wall_skull_name }
			set_artifact_description = artifact_wall_skull_description
		}
		scope:owner = {
			remove_variable = adventure_artifact_location
			remove_variable = adventure_artifact_hunter
		}
	}
}

create_artifact_wall_narwhal_horn_effect = {
	$OWNER$ = { save_scope_as = owner }
	$HUNTER$ = { save_scope_as = hunter }

	hidden_effect_new_object = {
		# Get artifact quality and wealth
		get_artifact_quality_effect = yes
		get_artifact_wealth_effect = yes
		scope:owner = {
			set_variable = {
				name = animal_type
				value = flag:unicorn
				days = 1
			}
			if = {
				limit = { exists = scope:adventurer }
				scope:adventurer = { save_scope_as = creator }
			}
			else = { save_scope_as = creator }
		}
		scope:owner = {
			if = {
				limit = {
					exists = scope:adventurer
				}
				create_artifact = {	
					name = artifact_wall_narwhal_horn_name
					description = artifact_wall_narwhal_horn
					visuals = animal_trophy
					type = animal_skull
					modifier = artifact_monthly_prestige_3_modifier
					wealth = scope:wealth
					quality = scope:quality
					save_scope_as = newly_created_artifact
					history = {
						location = scope:location
						actor = scope:adventurer
						recipient = root
						type = discovered
					}
				}
			}
			else = {
				create_artifact = {	
					name = artifact_wall_narwhal_horn_name
					description = artifact_wall_narwhal_horn
					creator = scope:hunter
					visuals = animal_trophy
					type = animal_skull
					modifier = artifact_monthly_prestige_3_modifier
					wealth = scope:wealth
					quality = scope:quality
					#decaying = no
					save_scope_as = newly_created_artifact
				}
			}
		}
		scope:newly_created_artifact = {
			# Set grandeur
			add_scaled_artifact_modifier_grandeur_big_effect = yes
			# Set prestige
			add_scaled_artifact_modifier_prestige_effect = yes
			add_scaled_artifact_modifier_piety_effect = yes
			# Extra for really good stuff
			if = {
				limit = {
					OR = {
						rarity = illustrious
						rarity = famed
					}
				}
				add_scaled_artifact_modifier_majesty_effect = yes
				add_scaled_artifact_modifier_dynasty_prestige_effect = yes
			}
			remove_artifact_modifier = artifact_placeholder_modifier
			save_scope_as = epic
		}
	}
	scope:newly_created_artifact = {
		if = {
			limit = { scope:quality >= 66 }
			add_artifact_modifier = artifact_court_grandeur_baseline_add_2_modifier
		}
		else_if = {
			limit = { scope:quality >= 33 }
			add_artifact_modifier = artifact_court_grandeur_baseline_add_1_modifier
		}

		# Wealth determines prestige
		if = {
			limit = { scope:wealth >= 66 }
			add_artifact_modifier = artifact_monthly_prestige_2_modifier
		}
		else_if = {
			limit = { scope:wealth >= 33 }
			add_artifact_modifier = artifact_placeholder_modifier
		}
		save_scope_as = epic
	}
}

###############
# ANIMAL TRINKET

create_artifact_animal_trinket_effect = {
	# Get the character the artifact is being made for.
	$OWNER$ = { save_scope_as = owner }
	$HUNTER$ = { save_scope_as = hunter }
	save_scope_value_as = { name = legendary value = $LEGENDARY$ }
	scope:owner = {
		set_variable = { name = animal_type value = $ANIMAL$ days = 5 }
		if = {
			limit = {
				OR = {
					NOT = { exists = var:animal_type }
					var:animal_type ?= flag:none
				}
			}
			random_list = {
				8 = {
					hunt_activity_standard_game_effect = { PROVINCE = scope:hunter.location HUNTER = scope:hunter }
				}
				2 = {
					hunt_activity_dangerous_game_effect = { PROVINCE = scope:hunter.location }
				}
			}
		}
	}
	if = {
		limit = { exists = scope:adventurer }
		scope:adventurer = { save_scope_as = creator }
	}
	else = {
		scope:hunter = { save_scope_as = creator }
	}
	hidden_effect_new_object = {
		# Get artifact quality, wealth, materials, and decorations
		animal_artifact_wealth_quality_effect = yes
		get_animal_hunt_location_effect = yes
		scope:location = { add_to_list = artifact_material_sources }
		scope:owner = {
			if = {
				limit = {
					OR = {
						scope:owner.var:animal_type ?= flag:fox
						scope:owner.var:animal_type ?= flag:cat
					}
				}
				create_artifact = {	
					name = artifact_animal_trinket_name
					creator = scope:hunter
					description = placeholder
					visuals = fox_tail
					type = animal_trinket
					modifier = artifact_placeholder_modifier
					wealth = scope:wealth
					quality = scope:quality
					save_scope_as = newly_created_artifact
				}
			}
			else_if = {
				limit = {
					OR = {
						scope:owner.var:animal_type ?= flag:bear
						scope:owner.var:animal_type ?= flag:leopard
						scope:owner.var:animal_type ?= flag:lion
						scope:owner.var:animal_type ?= flag:tiger
						scope:owner.var:animal_type ?= flag:wolf
						scope:owner.var:animal_type ?= flag:lynx
						scope:owner.var:animal_type ?= flag:wolf
						scope:owner.var:animal_type ?= flag:dog
						scope:owner.var:animal_type ?= flag:hyena
					}
				}
				create_artifact = {	
					name = artifact_animal_trinket_name
					creator = scope:hunter
					description = placeholder
					visuals = bear_paw
					type = animal_trinket
					modifier = artifact_placeholder_modifier
					wealth = scope:wealth
					quality = scope:quality
					save_scope_as = newly_created_artifact
				}
			}
			else_if = {
				limit = {
					OR = {
						scope:owner.var:animal_type ?= flag:aurochs
						scope:owner.var:animal_type ?= flag:bison
						scope:owner.var:animal_type ?= flag:boar
					}
				}
				create_artifact = {	
					name = artifact_animal_trinket_name
					creator = scope:hunter
					description = placeholder
					visuals = tusk
					type = animal_trinket
					modifier = artifact_placeholder_modifier
					wealth = scope:wealth
					quality = scope:quality
					save_scope_as = newly_created_artifact
				}
			}
			else_if = {
				limit = {
					OR = {
						scope:owner.var:animal_type ?= flag:hare
						scope:owner.var:animal_type ?= flag:horse
						scope:owner.var:animal_type ?= flag:unicorn
					}
				}
				create_artifact = {	
					name = artifact_animal_trinket_name
					creator = scope:hunter
					description = placeholder
					visuals = pouch
					type = animal_trinket
					modifier = artifact_placeholder_modifier
					wealth = scope:wealth
					quality = scope:quality
					save_scope_as = newly_created_artifact
				}
			}
			else = {
				create_artifact = {	
					name = artifact_animal_trinket_name
					creator = scope:hunter
					description = placeholder
					visuals = animal_trinket
					type = animal_trinket
					modifier = artifact_placeholder_modifier
					wealth = scope:wealth
					quality = scope:quality
					save_scope_as = newly_created_artifact
				}
			}
		}
		scope:newly_created_artifact = {
			set_max_durability = 60
			# Set prestige
			add_scaled_artifact_modifier_minor_prestige_effect = yes
			# Set stress loss
			add_scaled_artifact_modifier_stress_gain_effect = yes
			remove_artifact_modifier = artifact_placeholder_modifier
			set_variable = {
				name = animal_type
				value = scope:owner.var:animal_type
			}
			set_variable = {
				name = quality
				value = scope:quality
			}
			set_variable = {
				name = wealth
				value = scope:wealth
			}
			hunt_animal_artifact_modifier_selection_effect = yes
			if = {
				limit = { scope:legendary = yes }
				set_variable = { name = legendary }
				add_scaled_artifact_modifier_majesty_effect = yes
				add_scaled_artifact_modifier_combat_effect = yes
			}
			set_artifact_description = artifact_animal_trinket_description
		}
		scope:owner = {
			remove_variable = adventure_artifact_location
			remove_variable = adventure_artifact_hunter
		}
	}
}

###############
# ANIMAL FEATHER

create_artifact_bird_feather_effect = {
	# Get the character the artifact is being made for.
	$OWNER$ = { save_scope_as = owner }
	$HUNTER$ = { save_scope_as = hunter }
	scope:owner = {
		set_variable = { name = animal_type value = $ANIMAL$ }
		if = {
			limit = {
				OR = {
					NOT = { exists = var:animal_type }
					var:animal_type ?= flag:none
				}
			}
			hunt_activity_falconry_game_effect = { PROVINCE = scope:hunter.location }
		}
	}
	if = {
		limit = { exists = scope:adventurer }
		scope:adventurer = { save_scope_as = creator }
	}
	else = {
		scope:hunter = { save_scope_as = creator }
	}
	hidden_effect_new_object = {
		# Get artifact quality, wealth, materials, and decorations
		animal_artifact_wealth_quality_effect = yes
		get_animal_hunt_location_effect = yes
		scope:location = { add_to_list = artifact_material_sources }
		scope:owner = {
			create_artifact = {	
				name = artifact_bird_feather_name
				creator = scope:hunter
				description = placeholder
				visuals = bird_feather
				type = bird_feather
				modifier = artifact_placeholder_modifier
				wealth = scope:wealth
				quality = scope:quality
				save_scope_as = newly_created_artifact
			}
		}
		scope:newly_created_artifact = {
			if = {
				limit = {
					scope:owner.var:animal_type ?= flag:eagle
					exists = scope:owner.var:story_cycle_eagle_name
				}
				set_variable = {
					name = pet_name
					value = scope:owner.var:story_cycle_eagle_name
				}
				set_artifact_name = artifact_animal_feather_name_eagle
				set_artifact_description = artifact_bird_feather_pet_description
			}
			else = {
				set_artifact_description = artifact_bird_feather_description
			}

			set_max_durability = 60

			# Set prestige
			add_scaled_artifact_modifier_minor_prestige_effect = yes
			# Set stress loss
			add_scaled_artifact_modifier_stress_gain_effect = yes
			remove_artifact_modifier = artifact_placeholder_modifier
			
			set_variable = {
				name = animal_type
				value = scope:owner.var:animal_type
			}
			set_variable = {
				name = quality
				value = scope:quality
			}
			set_variable = {
				name = wealth
				value = scope:wealth
			}
		}
		scope:owner = {
			remove_variable = adventure_artifact_location
			remove_variable = adventure_artifact_hunter
			remove_variable = animal_type
		}
	}
}

###############
# BOX

# Small box
create_artifact_box_small_effect = {
	# Get the character the artifact is being made for.
	$OWNER$ = { save_scope_as = owner }
	$CARPENTER$ = { save_scope_as = carpenter }
	hidden_effect_new_object = {
		# Get artifact quality, wealth, and materials
		get_artifact_quality_effect = yes
		get_artifact_wealth_effect = yes
		if = { #IF we have set the location we use it for the materials
			limit = { exists = scope:location }
			scope:location = { add_to_list = artifact_material_sources }
		}

		# Create the artifact
		scope:owner = {
			if = {
				limit = {
					exists = scope:adventurer
				}
				create_artifact = {	
					name = artifact_box_small_name
					creator = scope:adventurer
					description = placeholder
					visuals = small_box
					type = box
					modifier = artifact_placeholder_modifier
					save_scope_as = newly_created_artifact
					wealth = scope:wealth
					quality = scope:quality
					#decaying = no
					history = {
						location = scope:location
						actor = scope:adventurer
						recipient = root
						type = discovered
					}
				}
			}
			else = {
				create_artifact = {	
					name = artifact_box_small_name
					creator = scope:carpenter
					description = placeholder
					visuals = small_box
					type = box
					modifier = artifact_placeholder_modifier
					save_scope_as = newly_created_artifact
					wealth = scope:wealth
					quality = scope:quality
					#decaying = no
				}
			}
		}
		scope:newly_created_artifact = {
			get_artifact_feature_references_effect = yes
			set_artifact_description = artifact_box_small_description

			# Set grandeur
			add_scaled_artifact_modifier_grandeur_small_effect = yes
			add_scaled_artifact_modifier_piety_effect = yes
			if = {
				limit = {
					OR = {
						rarity = famed
						rarity = illustrious
					}
				}
				add_scaled_artifact_modifier_dynasty_prestige_effect = yes
			}
			remove_artifact_modifier = artifact_placeholder_modifier
		}
	}
}

# Medium box
create_artifact_box_medium_effect = {
	# Get the character the artifact is being made for.
	$OWNER$ = { save_scope_as = owner }
	$CARPENTER$ = { save_scope_as = carpenter }
	hidden_effect_new_object = {
		# Get artifact quality, wealth, and materials
		get_artifact_quality_effect = yes
		get_artifact_wealth_effect = yes
		if = { #IF we have set the location we use it for the materials
			limit = { exists = scope:location }
			scope:location = { add_to_list = artifact_material_sources }
		}

		# Create the artifact
		scope:owner = {
			if = {
				limit = {
					exists = scope:adventurer
				}
				create_artifact = {	
					name = artifact_box_medium_name
					creator = scope:adventurer
					description = placeholder
					visuals = medium_box
					type = box
					modifier = artifact_placeholder_modifier
					save_scope_as = newly_created_artifact
					wealth = scope:wealth
					quality = scope:quality
					#decaying = no
					history = {
						location = scope:location
						actor = scope:adventurer
						recipient = root
						type = discovered
					}
				}
			}
			else = {
				create_artifact = {	
					name = artifact_box_medium_name
					creator = scope:carpenter
					description = placeholder
					visuals = medium_box
					type = box
					modifier = artifact_placeholder_modifier
					save_scope_as = newly_created_artifact
					wealth = scope:wealth
					quality = scope:quality
					#decaying = no
				}
			}
		}
		scope:newly_created_artifact = {
			get_artifact_feature_references_effect = yes
			set_artifact_description = artifact_box_medium_description

			# Set grandeur
			add_scaled_artifact_modifier_grandeur_small_effect = yes
			add_scaled_artifact_modifier_piety_effect = yes
			if = {
				limit = {
					OR = {
						rarity = famed
						rarity = illustrious
					}
				}
				add_scaled_artifact_modifier_dynasty_prestige_effect = yes
			}
			remove_artifact_modifier = artifact_placeholder_modifier
		}
	}
}



###############
# GOBLET

create_artifact_goblet_effect = {
	# Get the character the artifact is being made for.
	$OWNER$ = { save_scope_as = owner }
	$SMITH$ = { save_scope_as = goldsmith }

	hidden_effect_new_object = {
		# Get artifact quality, wealth, and materials
		get_artifact_quality_effect = yes
		get_artifact_wealth_effect = yes
		if = { #Any existing dummy character gets turned into the goldsmith
			limit = {
				exists = scope:dummy_gender
				scope:goldsmith = scope:dummy_gender
			}
			clear_saved_scope = goldsmith
			clear_saved_scope = dummy_gender
		}
		# Create the artifact
		scope:owner = {
			if = {
				limit = { exists = scope:adventurer }
				create_artifact = {	
					name = artifact_goblet_name
					description = placeholder
					visuals = goblet
					type = goblet
					modifier = artifact_placeholder_modifier
					wealth = scope:wealth
					quality = scope:quality
					#decaying = no
					save_scope_as = newly_created_artifact
					history = {
						location = scope:location
						actor = scope:adventurer
						recipient = root
						type = discovered
					}
				}
			}
			else_if = {
				limit = {
					scope:host ?= $OWNER$
					scope:activity ?= { has_activity_type = activity_tournament }
				}
				create_artifact = {
					name = artifact_goblet_name
					creator = scope:host
					description = placeholder # Will be updated in the post-creation effects after decorations are assigned.
					visuals = goblet
					type = goblet
					modifier = artifact_placeholder_modifier
					wealth = scope:wealth
					quality = scope:quality
					history = {
						type = prize_created
						recipient = scope:host
					}
					save_scope_as = newly_created_artifact
				}
			}
			else_if = {
				limit = { exists = scope:goldsmith }
				create_artifact = {	
					name = artifact_goblet_name
					creator = scope:goldsmith
					description = placeholder
					visuals = goblet
					type = goblet
					wealth = scope:wealth
					quality = scope:quality
					#decaying = no
					modifier = artifact_placeholder_modifier
					save_scope_as = newly_created_artifact
				}
			}
			else = {
				create_artifact = {	
					name = artifact_goblet_name
					description = placeholder
					visuals = goblet
					type = goblet
					wealth = scope:wealth
					quality = scope:quality
					#decaying = no
					modifier = artifact_placeholder_modifier
					save_scope_as = newly_created_artifact
					history = { type = created_before_history }
				}
			}
		}
		scope:newly_created_artifact = {
			set_artifact_description = artifact_goblet_description

			# Set grandeur
			add_scaled_artifact_modifier_grandeur_small_effect = yes
			
			# Let's add another random effect to keep goblets interesting!
			random_list = {
				10 = {
					add_scaled_artifact_modifier_minor_prestige_effect = yes
				}
				10 = {
					add_scaled_artifact_modifier_majesty_effect = yes
				}
				30 = {
					trigger = { rarity = common }
					# Common goblets have a chance to not get any extra modifiers
				}
			}
			remove_artifact_modifier = artifact_placeholder_modifier
		}
	}
}

create_artifact_wall_banner_effect = {
	$OWNER$ = { save_scope_as = owner }
	$CREATOR$ = { save_scope_as = creator }
	$TARGET$ = { save_scope_as = target } #Can be a title, a house or a dynasty

	#This effect can be used to generate banners - either from battle or a character.
	#For battle banners the variables epic_battle_location and epic_loser must be set.
	#To generate a dynasty banner the variable banner_from_dynasty must be set
	#To generate a house banner the variable banner_from_house must be set
	#To generate a banner for a title no special variables need to be set
	
	hidden_effect_new_object = {
		if = {
			limit = { has_variable = epic_battle_location }
			var:epic_battle_location = { save_scope_as = epic_battle_location }
			remove_variable = epic_battle_location
		}
		if = {
			limit = { has_variable = epic_loser }
			var:epic_loser = { save_scope_as = epic_loser }
			remove_variable = epic_loser
		}
		# Dynasty banner rarity determined by Dynasty Splendor
		if = { 
			limit = {
				scope:owner = { has_variable = banner_from_dynasty }
			}
			if = {
				limit = { scope:owner.dynasty.dynasty_prestige_level = max_dynasty_prestige_level }
				set_artifact_rarity_illustrious = yes
			}
			else_if = {
				limit = { scope:owner.dynasty.dynasty_prestige_level >= high_dynasty_prestige_level }
				set_artifact_rarity_famed = yes
			}
			else_if = {
				limit = { scope:owner.dynasty.dynasty_prestige_level >= medium_dynasty_prestige_level }
				set_artifact_rarity_masterwork = yes
			}
			else = { set_artifact_rarity_common = yes }
		}
		# Other banners use default rarity script
		else = {
			get_artifact_quality_effect = yes
			get_artifact_wealth_effect = yes
		}

		scope:owner = {
			if = { #Dynasty Banner
				limit = { has_variable = banner_from_dynasty }
				if = { #Startup Banner
					limit = { has_variable = startup_banner }
					create_artifact = {
						name = artifact_wall_banner_dynasty_name
						description = artifact_wall_banner_dynasty_description
						visuals = banner
						visuals_source = scope:target
						template = dynasty_banner_template
						type = wall_big
						modifier = artifact_placeholder_modifier
						save_scope_as = newly_created_artifact
						wealth = scope:wealth
						quality = scope:quality
						history = {
							type = created
							recipient = scope:owner
							location = scope:owner.capital_province
						}
					}
					remove_variable = startup_banner
				}
				else = { #Created Banner
					create_artifact = {
						name = artifact_wall_banner_dynasty_name
						creator = scope:creator
						description = artifact_wall_banner_dynasty_description
						visuals = banner
						visuals_source = scope:target
						template = dynasty_banner_template
						type = wall_big
						modifier = artifact_placeholder_modifier
						save_scope_as = newly_created_artifact
						wealth = scope:wealth
						quality = scope:quality
					}
				}
				scope:newly_created_artifact = {
					set_variable = { # Tracks house
						name = banner_dynasty
						value = scope:target
					}
					set_variable = { # Tracks first owner
						name = banner_commissioner
						value = scope:owner
					}
					grant_banner_house_claim_effect = yes
					set_artifact_description = artifact_wall_banner_dynasty_description # For commissioner flavor
				}
				remove_variable = banner_from_dynasty
			}
			else_if = { #House Banner
				limit = { has_variable = banner_from_house }
				if = { #Startup Banner
					limit = { has_variable = startup_banner }
					create_artifact = {
						name = artifact_wall_banner_house_name
						description = artifact_wall_banner_house_description
						visuals = banner
						visuals_source = scope:target
						template = house_banner_template
						type = wall_big
						modifier = artifact_placeholder_modifier
						save_scope_as = newly_created_artifact
						wealth = scope:wealth
						quality = scope:quality
						history = {
							type = created
							recipient = scope:owner
							location = scope:owner.capital_province
						}
					}
					remove_variable = startup_banner
				}
				else = { #Created Banner
					create_artifact = {
						name = artifact_wall_banner_house_name
						creator = scope:creator
						description = artifact_wall_banner_house_description
						visuals = banner
						visuals_source = scope:target
						template = house_banner_template
						type = wall_big
						modifier = artifact_placeholder_modifier
						save_scope_as = newly_created_artifact
						wealth = scope:wealth
						quality = scope:quality
					}
				}
				scope:newly_created_artifact = {
					set_variable = { # Tracks house
						name = banner_house
						value = scope:target
					}
				}
				remove_variable = banner_from_house
			}
			else_if = { # For banners looted after a battle
				limit = {
					exists = scope:epic_battle_location
					exists = scope:epic_loser
				}
				create_artifact = {
					name = artifact_wall_banner_battle_name
					creator = scope:creator
					description = artifact_wall_banner_battle_description
					visuals = banner
					visuals_source = scope:target
					type = wall_big
					modifier = artifact_placeholder_modifier
					quality = conquered_banner_value
					wealth = conquered_banner_value
					decaying = no
					save_scope_as = newly_created_artifact
					history = {
						location = scope:epic_battle_location
						actor = scope:epic_loser
						recipient = scope:owner
						type = conquest
					}
				}
			}
			else = { #Royal Banner
				create_artifact = {
					name = artifact_wall_banner_royal_name
					creator = scope:creator
					description = artifact_wall_banner_royal_description
					visuals = banner
					visuals_source = scope:target
					type = wall_big
					modifier = artifact_placeholder_modifier
					save_scope_as = newly_created_artifact
					wealth = scope:wealth
					quality = scope:quality
				}
			}
		}
		
		# Modifiers are completely randomized - Possible modifiers are based on the battle
		scope:newly_created_artifact = {
			add_scaled_artifact_modifier_grandeur_small_effect = yes
			if = {
				limit = {
					exists = scope:epic_loser
				}
				random_list = {
					pick = 2
					unique = yes
					10 = { # Knight Limit
						random_list = {
							10 = {
								add_artifact_modifier = artifact_knight_limit_1_modifier
							}
							5 = {
								add_artifact_modifier = artifact_knight_limit_2_modifier
							}
						}
					}
					10 = { # Knight Effectiveness
						random_list = {
							15 = {
								add_artifact_modifier = artifact_knight_effectiveness_1_modifier
							}
							10 = {
								add_artifact_modifier = artifact_knight_effectiveness_2_modifier
							}
							5 = {
								add_artifact_modifier = artifact_knight_effectiveness_3_modifier
							}
						}
					}
					10 = { # Levy Reinforcement Rate
						random_list = {
							15 = {
								add_artifact_modifier = artifact_levy_reinforcement_rate_1_modifier
							}
							5 = {
								add_artifact_modifier = artifact_levy_reinforcement_rate_2_modifier
							}
						}
					}
					10 = { # Dread Gain
						random_list = {
							15 = {
								add_artifact_modifier = artifact_dread_gain_mult_1_modifier
							}
							5 = {
								add_artifact_modifier = artifact_dread_gain_mult_2_modifier
							}
						}
					}
					10 = { # Dread Baseline
						random_list = {
							20 = {
								add_artifact_modifier = artifact_dread_baseline_add_1_modifier
							}
							5 = {
								add_artifact_modifier = artifact_dread_baseline_add_2_modifier
							}
						}
					}
					10 = { # Prestige Bonus - You only get one, as we don't want these to stack too much
						random_list = {
							10 = { # Monthly Prestige
								random_list = {
									10 = {
										add_artifact_modifier = artifact_monthly_prestige_1_modifier
									}
									5 = {
										add_artifact_modifier = artifact_monthly_prestige_2_modifier
									}
								}
							}
							10 = { # Prestige per Knight
								random_list = {
									10 = {
										add_artifact_modifier = artifact_monthly_prestige_gain_per_knight_add_1_modifier
									}
									5 = {
										add_artifact_modifier = artifact_monthly_prestige_gain_per_knight_add_2_modifier
									}
								}
							}
							10 = { # Prestige per Dread
								random_list = {
									10 = {
										add_artifact_modifier = artifact_monthly_prestige_gain_per_dread_add_1_modifier
									}
									5 = {
										add_artifact_modifier = artifact_monthly_prestige_gain_per_dread_add_2_modifier
									}
								}
							}
						}
					}
					10 = { # Advantage vs other Faiths
						trigger = {
							exists = scope:epic_loser
							exists = scope:owner
							scope:epic_loser = {
								faith != scope:owner.faith
							}
						}
						random_list = {
							15 = {
								add_artifact_modifier = artifact_tolerance_advantage_mod_2_modifier
							}
							10 = {
								add_artifact_modifier = artifact_tolerance_advantage_mod_3_modifier
							}
							5 = {
								add_artifact_modifier = artifact_tolerance_advantage_mod_4_modifier
							}
						}
					}
					10 = { # Controlled Province Advantage
						trigger = {
							exists = scope:owner
							exists = scope:epic_loser
							exists = scope:epic_battle_location
							scope:owner = {
								any_character_war = {
									is_defender = scope:owner
									is_attacker = scope:epic_loser
								}
								any_realm_province = {
									this = scope:epic_battle_location
								}
							}
						}
						random_list = {
							15 = {
								add_artifact_modifier = artifact_controlled_province_advantage_1_modifier
							}
							10 = {
								add_artifact_modifier = artifact_controlled_province_advantage_2_modifier
							}
							5 = {
								add_artifact_modifier = artifact_controlled_province_advantage_3_modifier
							}
						}
					}
					# Chance to acquire an advantage bonus for the terrain the battle was fought in 
					10 = { # Plains Advantage
						trigger = {
							exists = scope:epic_battle_location
							scope:epic_battle_location = {
								terrain = plains
							}
						}
						random_list = {
							15 = {
								add_artifact_modifier = artifact_plains_advantage_1_modifier
							}
							10 = {
								add_artifact_modifier = artifact_plains_advantage_2_modifier
							}
							5 = {
								add_artifact_modifier = artifact_plains_advantage_3_modifier
							}
						}
					}
					10 = { # Farmlands Advantage
						trigger = {
							exists = scope:epic_battle_location
							scope:epic_battle_location = {
								terrain = farmlands
							}
						}
						random_list = {
							15 = {
								add_artifact_modifier = artifact_farmlands_advantage_1_modifier
							}
							10 = {
								add_artifact_modifier = artifact_farmlands_advantage_2_modifier
							}
							5 = {
								add_artifact_modifier = artifact_farmlands_advantage_3_modifier
							}
						}
					}
					10 = { # Hills Advantage
						trigger = {
							exists = scope:epic_battle_location
							scope:epic_battle_location = {
								terrain = hills
							}
						}
						random_list = {
							15 = {
								add_artifact_modifier = artifact_hills_advantage_1_modifier
							}
							10 = {
								add_artifact_modifier = artifact_hills_advantage_2_modifier
							}
							5 = {
								add_artifact_modifier = artifact_hills_advantage_3_modifier
							}
						}
					}
					10 = { # Mountains Advantage
						trigger = {
							exists = scope:epic_battle_location
							scope:epic_battle_location = {
								terrain = mountains
							}
						}
						random_list = {
							15 = {
								add_artifact_modifier = artifact_mountains_advantage_1_modifier
							}
							10 = {
								add_artifact_modifier = artifact_mountains_advantage_2_modifier
							}
							5 = {
								add_artifact_modifier = artifact_mountains_advantage_3_modifier
							}
						}
					}
					10 = { # Desert Advantage
						trigger = {
							exists = scope:epic_battle_location
							scope:epic_battle_location = {
								terrain = desert
							}
						}
						random_list = {
							15 = {
								add_artifact_modifier = artifact_desert_advantage_1_modifier
							}
							10 = {
								add_artifact_modifier = artifact_desert_advantage_2_modifier
							}
							5 = {
								add_artifact_modifier = artifact_desert_advantage_3_modifier
							}
						}
					}
					10 = { # Desert Mountains Advantage
						trigger = {
							exists = scope:epic_battle_location
							scope:epic_battle_location = {
								terrain = desert_mountains
							}
						}
						random_list = {
							15 = {
								add_artifact_modifier = artifact_desert_mountains_advantage_1_modifier
							}
							10 = {
								add_artifact_modifier = artifact_desert_mountains_advantage_2_modifier
							}
							5 = {
								add_artifact_modifier = artifact_desert_mountains_advantage_3_modifier
							}
						}
					}
					10 = { # Oasis Advantage
						trigger = {
							exists = scope:epic_battle_location
							scope:epic_battle_location = {
								terrain = oasis
							}
						}
						random_list = {
							15 = {
								add_artifact_modifier = artifact_oasis_advantage_1_modifier
							}
							10 = {
								add_artifact_modifier = artifact_oasis_advantage_2_modifier
							}
							5 = {
								add_artifact_modifier = artifact_oasis_advantage_3_modifier
							}
						}
					}
					10 = { # Jungle Advantage
						trigger = {
							exists = scope:epic_battle_location
							scope:epic_battle_location = {
								terrain = jungle
							}
						}
						random_list = {
							15 = {
								add_artifact_modifier = artifact_jungle_advantage_1_modifier
							}
							10 = {
								add_artifact_modifier = artifact_jungle_advantage_2_modifier
							}
							5 = {
								add_artifact_modifier = artifact_jungle_advantage_3_modifier
							}
						}
					}
					10 = { # Forest Advantage
						trigger = {
							exists = scope:epic_battle_location
							scope:epic_battle_location = {
								terrain = forest
							}
						}
						random_list = {
							15 = {
								add_artifact_modifier = artifact_forest_advantage_1_modifier
							}
							10 = {
								add_artifact_modifier = artifact_forest_advantage_2_modifier
							}
							5 = {
								add_artifact_modifier = artifact_forest_advantage_3_modifier
							}
						}
					}
					10 = { # Taiga Advantage
						trigger = {
							exists = scope:epic_battle_location
							scope:epic_battle_location = {
								terrain = taiga
							}
						}
						random_list = {
							15 = {
								add_artifact_modifier = artifact_taiga_advantage_1_modifier
							}
							10 = {
								add_artifact_modifier = artifact_taiga_advantage_2_modifier
							}
							5 = {
								add_artifact_modifier = artifact_taiga_advantage_3_modifier
							}
						}
					}
					10 = { # Wetlands Advantage
						trigger = {
							exists = scope:epic_battle_location
							scope:epic_battle_location = {
								terrain = wetlands
							}
						}
						random_list = {
							15 = {
								add_artifact_modifier = artifact_wetlands_advantage_1_modifier
							}
							10 = {
								add_artifact_modifier = artifact_wetlands_advantage_2_modifier
							}
							5 = {
								add_artifact_modifier = artifact_wetlands_advantage_3_modifier
							}
						}
					}
					10 = { # Steppe Advantage
						trigger = {
							exists = scope:epic_battle_location
							scope:epic_battle_location = {
								terrain = steppe
							}
						}
						random_list = {
							15 = {
								add_artifact_modifier = artifact_steppe_advantage_1_modifier
							}
							10 = {
								add_artifact_modifier = artifact_steppe_advantage_2_modifier
							}
							5 = {
								add_artifact_modifier = artifact_steppe_advantage_3_modifier
							}
						}
					}
					10 = { # Floodplains Advantage
						trigger = {
							exists = scope:epic_battle_location
							scope:epic_battle_location = {
								terrain = floodplains
							}
						}
						random_list = {
							15 = {
								add_artifact_modifier = artifact_floodplains_advantage_1_modifier
							}
							10 = {
								add_artifact_modifier = artifact_floodplains_advantage_2_modifier
							}
							5 = {
								add_artifact_modifier = artifact_floodplains_advantage_3_modifier
							}
						}
					}
					10 = { # Drylands Advantage
						trigger = {
							exists = scope:epic_battle_location
							scope:epic_battle_location = {
								terrain = drylands
							}
						}
						random_list = {
							15 = {
								add_artifact_modifier = artifact_drylands_advantage_1_modifier
							}
							10 = {
								add_artifact_modifier = artifact_drylands_advantage_2_modifier
							}
							5 = {
								add_artifact_modifier = artifact_drylands_advantage_3_modifier
							}
						}
					}
					# glory_hound_opinion
					10 = {
						if = {
							limit = { rarity = common }
							add_artifact_modifier = artifact_glory_hound_vassal_opinion_1_modifier
						}
						else_if = {
							limit = { rarity = masterwork }
							add_artifact_modifier = artifact_glory_hound_vassal_opinion_2_modifier
						}
						else_if = {
							limit = { rarity = famed }
							add_artifact_modifier = artifact_glory_hound_vassal_opinion_3_modifier
						}
						else_if = {
							limit = { rarity = illustrious }
							add_artifact_modifier = artifact_glory_hound_vassal_opinion_4_modifier
						}
					}
					# glory_hound_levy_mult
					10 = {
						if = {
							limit = { rarity = common }
							add_artifact_modifier = artifact_glory_hound_levy_contribution_mult_1_modifier
						}
						else_if = {
							limit = { rarity = masterwork }
							add_artifact_modifier = artifact_glory_hound_levy_contribution_mult_2_modifier
						}
						else_if = {
							limit = { rarity = famed }
							add_artifact_modifier = artifact_glory_hound_levy_contribution_mult_3_modifier
						}
						else_if = {
							limit = { rarity = illustrious }
							add_artifact_modifier = artifact_glory_hound_levy_contribution_mult_4_modifier
						}
					}
					# belligerent_opinion
					10 = {
						if = {
							limit = { rarity = common }
							add_artifact_modifier = artifact_belligerent_vassal_opinion_1_modifier
						}
						else_if = {
							limit = { rarity = masterwork }
							add_artifact_modifier = artifact_belligerent_vassal_opinion_2_modifier
						}
						else_if = {
							limit = { rarity = famed }
							add_artifact_modifier = artifact_belligerent_vassal_opinion_3_modifier
						}
						else_if = {
							limit = { rarity = illustrious }
							add_artifact_modifier = artifact_belligerent_vassal_opinion_4_modifier
						}
					}
					# belligerent_levy_mult
					10 = {
						if = {
							limit = { rarity = common }
							add_artifact_modifier = artifact_belligerent_levy_contribution_mult_1_modifier
						}
						else_if = {
							limit = { rarity = masterwork }
							add_artifact_modifier = artifact_belligerent_levy_contribution_mult_2_modifier
						}
						else_if = {
							limit = { rarity = famed }
							add_artifact_modifier = artifact_belligerent_levy_contribution_mult_3_modifier
						}
						else_if = {
							limit = { rarity = illustrious }
							add_artifact_modifier = artifact_belligerent_levy_contribution_mult_4_modifier
						}
					}
				}
			}
			else = {
				add_scaled_artifact_modifier_dynasty_prestige_effect = yes
				add_scaled_artifact_modifier_prestige_effect = yes
				add_scaled_artifact_modifier_rulership_effect = yes
			}
			remove_artifact_modifier = artifact_placeholder_modifier
		}
	}
}

create_artifact_wall_shield_effect = {
	$OWNER$ = { save_scope_as = owner }
	$TARGET$ = { save_scope_as = target }
	$CREATOR$ = { save_scope_as = smith }
	
	hidden_effect_new_object = {
		get_artifact_quality_effect = yes
		get_artifact_wealth_effect = yes
		
		if = {
			limit = {
				scope:smith = { artifact_use_mediterranean_building_visuals_trigger = yes }
			}
			scope:owner = {
				create_artifact = {
					name = artifact_wall_shield_name
					creator = scope:smith
					description = artifact_wall_shield_description
					visuals = wall_shield_medi
					visuals_source = scope:target
					type = wall_shield_special
					modifier = artifact_placeholder_modifier
					save_scope_as = newly_created_artifact
					wealth = scope:wealth
					quality = scope:quality
					#decaying = no
				}
			}
		}
		else = {
			scope:owner = {
				create_artifact = {
					name = artifact_wall_shield_name
					creator = scope:smith
					description = artifact_wall_shield_description
					visuals = wall_shield
					visuals_source = scope:target
					type = wall_shield
					modifier = artifact_placeholder_modifier
					save_scope_as = newly_created_artifact
					wealth = scope:wealth
					quality = scope:quality
					#decaying = no
				}
			}
		}
		scope:newly_created_artifact = {
			add_scaled_artifact_modifier_grandeur_small_effect = yes
			add_scaled_artifact_modifier_dynasty_prestige_effect = yes
			if = {
				limit = {
					OR = {
						rarity = famed
						rarity = illustrious
					}
				}
				add_scaled_artifact_modifier_minor_prestige_effect = yes
			}
			remove_artifact_modifier = artifact_placeholder_modifier
		}
	}
}


create_artifact_sculpture_effect = {
	$OWNER$ = { save_scope_as = owner }
	$SCULPTER$ = { save_scope_as = sculpter }
	hidden_effect_new_object = {
		get_artifact_quality_effect = yes
		get_artifact_wealth_effect = yes
		if = {
			limit = {
				scope:owner = { is_female = yes }
			}
			save_scope_value_as = {
				name = owner_fm
				value = flag:female
			}
		}
		else = {
			save_scope_value_as = {
				name = owner_fm
				value = flag:male
			}
		}

		if = {
			limit = {
				OR = {
					scope:sculpter = {	
						OR = {
							artifact_use_mena_building_visuals_trigger = yes
							artifact_use_iranian_building_visuals_trigger = yes
							artifact_use_steppe_building_visuals_trigger = yes
						}
					}
					scope:owner = {
						faith = {
							OR = {
								has_doctrine = tenet_aniconism
								religion = religion:islam_religion
							}
						}
					}
				}
			}
			scope:owner = {
				create_artifact = {	
					name = artifact_sculpture_name
					creator = scope:sculpter
					description = placeholder
					visuals = statue_mena
					type = sculpture
					modifier = artifact_placeholder_modifier
					save_scope_as = newly_created_artifact
					wealth = scope:wealth
					quality = scope:quality
					#decaying = no
				}
			}
		}
		else = {
			scope:owner = {
				create_artifact = {	
					name = artifact_sculpture_name
					creator = scope:sculpter
					description = placeholder
					visuals = statue
					type = sculpture
					modifier = artifact_placeholder_modifier
					save_scope_as = newly_created_artifact
					wealth = scope:wealth
					quality = scope:quality
					#decaying = no
				}
			}
		}
		scope:newly_created_artifact = {
			if = {
				limit = {
					has_artifact_feature = sculpture_material_wood
				}
				set_artifact_feature_group = generic_material_wood
			}
			#Description
			if = {
				limit = {
					OR = { 
						scope:sculpter = {
							OR = {
								artifact_use_mena_building_visuals_trigger = yes
								artifact_use_iranian_building_visuals_trigger = yes
								artifact_use_steppe_building_visuals_trigger = yes
							}
						}
						scope:owner = { #An owner who follows an aniconic faith will never want a statue that portrays a human
							faith = {
								OR = {
									has_doctrine = tenet_aniconism
									religion = religion:islam_religion
								}
							}
						}
					}
				}
				set_artifact_description = artifact_sculpture_animal_description #backup description if anti icons
			}
			else = {
				set_artifact_description = artifact_sculpture_description #default description of person
			}
			add_scaled_artifact_modifier_grandeur_small_effect = yes
			add_scaled_artifact_modifier_prestige_effect = yes
			add_scaled_artifact_modifier_majesty_effect = yes
			remove_artifact_modifier = artifact_placeholder_modifier
		}
	}
}

create_artifact_pedestal_rock_effect = {
	$OWNER$ = { save_scope_as = owner }

	get_artifact_quality_effect = yes
	get_artifact_wealth_effect = yes

	scope:owner = {
		create_artifact = {	
			name = artifact_pedestal_rock_name
			creator = scope:owner
			description = artifact_pedestal_rock_description
			visuals = rock
			type = pedestal
			modifier = artifact_monthly_piety_4_modifier
			save_scope_as = newly_created_artifact
			wealth = scope:wealth
			quality = scope:quality
			decaying = no
		}
	}
	scope:newly_created_artifact = {
		add_artifact_modifier = artifact_monthly_piety_gain_mult_2_modifier
		add_artifact_modifier = artifact_stress_gain_1_modifier
	}
}

create_artifact_pedestal_pouch_effect = {
	$OWNER$ = { save_scope_as = owner }

	get_artifact_quality_effect = yes
	get_artifact_wealth_effect = yes

	scope:owner = {
		create_artifact = {	
			name = artifact_pedestal_pouch_name
			creator = scope:owner
			description = artifact_pedestal_pouch_description
			visuals = pouch
			type = pedestal
			modifier = artifact_placeholder_modifier
			save_scope_as = newly_created_artifact
			wealth = scope:wealth
			quality = scope:quality
			#decaying = no
		}
	}
}

create_artifact_pedestal_scroll_effect = {
	$OWNER$ = { save_scope_as = owner }
	$WRITER$ = { save_scope_as = writer }

	get_artifact_quality_effect = yes
	get_artifact_wealth_effect = yes

	scope:owner = {
		create_artifact = {	
			name = artifact_pedestal_scroll_name
			creator = scope:writer
			description = artifact_pedestal_scroll_description
			visuals = scroll
			type = pedestal
			modifier = artifact_monthly_prestige_4_modifier
			save_scope_as = newly_created_artifact
			wealth = scope:wealth
			quality = scope:quality
			#decaying = no
		}
	}
	scope:newly_created_artifact = {
		add_artifact_modifier = artifact_stewardship_per_stress_level_2_modifier
		add_artifact_modifier = artifact_parochial_vassal_opinion_3_modifier
	}
}

create_artifact_pedestal_religious_head_letter_effect = {
	$OWNER$ = { save_scope_as = owner }

	get_artifact_quality_effect = yes
	get_artifact_wealth_effect = yes

	scope:owner = {
		create_artifact = {	
			name = artifact_pedestal_religious_head_letter_name
			creator = scope:owner
			description = artifact_pedestal_religious_head_letter_description
			visuals = scroll
			type = pedestal
			modifier = religious_head_letter_modifier
			save_scope_as = newly_created_artifact
			wealth = scope:wealth
			quality = scope:quality
			#decaying = no
		}
	}

	scope:newly_created_artifact = {
		add_scaled_artifact_modifier_grandeur_small_effect = yes
		add_scaled_artifact_modifier_piety_effect = yes
	}
}

#The crucifix should be preferred by non-aniconic Christian faiths
create_artifact_pedestal_crucifix_effect = {
	$OWNER$ = { save_scope_as = owner }

	get_artifact_quality_effect = yes
	get_artifact_wealth_effect = yes

	scope:owner = {
		create_artifact = {	
			name = artifact_pedestal_crucifix_name
			creator = scope:owner
			description = artifact_pedestal_crucifix_description
			visuals = cross
			type = pedestal
			template = cross_template
			modifier = artifact_placeholder_modifier
			save_scope_as = newly_created_artifact
			wealth = scope:wealth
			quality = scope:quality
			#decaying = no
		}
	}

	scope:newly_created_artifact = {
		add_scaled_artifact_modifier_devotion_effect = yes
		add_scaled_artifact_modifier_grandeur_small_effect = yes
		if = {
			limit = {
				OR = {
					rarity = famed
					rarity = illustrious
				}
			}
			add_scaled_artifact_modifier_piety_effect = yes
		}
		remove_artifact_modifier = artifact_placeholder_modifier
	}
}

#The cross is for aniconic Christian faiths
create_artifact_pedestal_cross_effect = {
	$OWNER$ = { save_scope_as = owner }

	get_artifact_quality_effect = yes
	get_artifact_wealth_effect = yes

	scope:owner = {
		create_artifact = {
			name = artifact_pedestal_cross_name
			description = artifact_pedestal_cross_description
			visuals = cross
			type = pedestal
			template = cross_template
			modifier = artifact_placeholder_modifier
			save_scope_as = newly_created_artifact
			wealth = scope:wealth
			quality = scope:quality
		}
	}

	scope:newly_created_artifact = {
		add_scaled_artifact_modifier_devotion_effect = yes
		add_scaled_artifact_modifier_grandeur_small_effect = yes
		if = {
			limit = {
				OR = {
					rarity = famed
					rarity = illustrious
				}
			}
			add_scaled_artifact_modifier_piety_effect = yes
		}
		remove_artifact_modifier = artifact_placeholder_modifier
	}
}

create_artifact_pedestal_human_skull_effect = {
	$OWNER$ = { save_scope_as = owner }
	
	$CREATOR$ = { save_scope_as = creator }
	
	$DESKULLED$ = { save_scope_as = killed }

	get_artifact_quality_effect = yes
	get_artifact_wealth_effect = yes

	scope:owner = {
		create_artifact = {
			name = artifact_pedestal_human_skull_name
			creator = scope:creator
			description = artifact_pedestal_human_skull_description
			visuals = human_skull
			type = pedestal
			modifier = artifact_dread_gain_mult_1_modifier
			save_scope_as = newly_created_artifact
			wealth = scope:wealth
			quality = scope:quality
			#decaying = no
		}
	}
	scope:newly_created_artifact = {
		add_scaled_artifact_modifier_grandeur_small_effect = yes
		add_scaled_artifact_modifier_minor_prestige_effect = yes
		if = {
			limit = {
				rarity = illustrious
			}
			add_artifact_modifier = artifact_dread_baseline_add_2_modifier
		}
		else_if = {
			limit = {
				rarity = famed
			}
			add_artifact_modifier = artifact_dread_baseline_add_1_modifier
		}
	}
}

create_artifact_pedestal_human_skull_specific_effect = {
	$OWNER$ = { save_scope_as = owner }

	$DESKULLED$ = { save_scope_as = killed }

	get_artifact_quality_effect = yes
	get_artifact_wealth_effect = yes

	scope:owner = {
		create_artifact = {	
			name = artifact_pedestal_human_skull_name
			creator = scope:owner
			description = artifact_pedestal_human_skull_specific_description
			visuals = human_skull
			type = miscellaneous
			modifier = artifact_dread_baseline_add_1_modifier
			save_scope_as = newly_created_artifact
			wealth = scope:wealth
			quality = scope:quality
		}
	}
}

create_artifact_pedestal_diamond_effect = {
	$OWNER$ = { save_scope_as = owner }

	get_artifact_quality_effect = yes
	get_artifact_wealth_effect = yes

	scope:owner = {
		create_artifact = {	
			name = artifact_pedestal_massive_diamond_name
			creator = scope:owner
			description = artifact_pedestal_massive_diamond
			visuals = diamond
			type = pedestal
			modifier = artifact_monthly_prestige_2_modifier
			save_scope_as = newly_created_artifact
			wealth = scope:wealth
			quality = scope:quality
			decaying = no
		}
	}
	scope:newly_created_artifact = {
		add_scaled_artifact_modifier_grandeur_big_effect = yes
		add_scaled_artifact_modifier_prestige_effect = yes
	}
}

create_artifact_pedestal_gold_effect = {
	$OWNER$ = { save_scope_as = owner }

	get_artifact_quality_effect = yes
	get_artifact_wealth_effect = yes

	scope:owner = {
		create_artifact = {	
			name = artifact_pedestal_gold_nugget_name
			description = artifact_pedestal_gold_nugget
			creator = scope:owner
			visuals = pouch
			type = pedestal
			#icon = pile of gold
			modifier = artifact_monthly_prestige_2_modifier
			save_scope_as = newly_created_artifact
			wealth = scope:wealth
			quality = scope:quality
			decaying = no
		}
	}

	scope:newly_created_artifact = {
		add_scaled_artifact_modifier_grandeur_small_effect = yes
		add_2_scaled_artifact_modifier_majesty_effect = yes
	}
}


##################
# Books

#Effect used to influence a book-artifact's content quality
change_artifact_book_content_quality_effect = {
	if = {
		limit = {
			$AMOUNT$ > 0
		}
		custom_tooltip = change_artifact_book_content_quality_effect_gain
	}
	else_if = {
		limit = {
			$AMOUNT$ < 0
		}
		custom_tooltip = change_artifact_book_content_quality_effect_loss
	}
	hidden_effect = {
		if = {
			limit = {
				NOT = {
					exists = var:book_content_quality
				}
			}
			set_variable = {
				name = book_content_quality
				value = $AMOUNT$
			}
		}
		else = {
			change_variable = {
				name = book_content_quality
				add = $AMOUNT$
			}
		}
	}
}

# Effect used when a character becomes inspired to write a book
set_book_subject_effect = {
	save_temporary_scope_value_as = {
		name = allow_no_subject_option
		value = $NO_SUBJECT$
	}
	hidden_effect = { #If they haven't specified what they're gonna write about we decide it here (might still leave it up to the sponsor if allow_no_subject_option = yes!)
		$BASE_SCOPE$ = {
			if = {
				limit = {
					NOT = { exists = var:book_subject }
				}
				random_list = { #What do they want to write about?
					1 = {
						modifier = {
							add = 60
							has_education_martial_trigger = yes
						}
						modifier = {
							add = 40
							book_subject_martial_trigger = yes
						}
						modifier = {
							add = { #If they're good you get +, if they're shit you get -
								value = average_skill_rating
								subtract = martial
								multiply = -5
							}
						}
						set_variable = {
							name = book_subject
							value = flag:martial
						}
					}
					1 = {
						modifier = {
							add = 60
							has_education_diplomacy_trigger = yes
						}
						modifier = {
							add = { #If they're good you get +, if they're shit you get -
								value = average_skill_rating
								subtract = diplomacy
								multiply = -5
							}
						}
						set_variable = {
							name = book_subject
							value = flag:diplomacy
						}
					}
					1 = {
						modifier = {
							add = 60
							has_education_stewardship_trigger = yes
						}
						modifier = {
							add = { #If they're good you get +, if they're shit you get -
								value = average_skill_rating
								subtract = stewardship
								multiply = -5
							}
						}
						set_variable = {
							name = book_subject
							value = flag:stewardship
						}
					}
					1 = {
						modifier = {
							add = 60
							has_education_intrigue_trigger = yes
						}
						modifier = {
							add = { #If they're good you get +, if they're shit you get -
								value = average_skill_rating
								subtract = intrigue
								multiply = -5
							}
						}
						set_variable = {
							name = book_subject
							value = flag:intrigue
						}
					}
					1 = {
						modifier = {
							add = 60
							has_education_learning_trigger = yes
						}
						modifier = {
							add = { #If they're good you get +, if they're shit you get -
								value = average_skill_rating
								subtract = learning
								multiply = -5
							}
						}
						set_variable = {
							name = book_subject
							value = flag:learning
						}
					}
					1 = {
						modifier = {
							add = 50
							book_subject_medicine_trigger = yes
						}
						modifier = {
							add = 20
							is_witch_trigger = yes
						}
						modifier = {
							add = {
								value = learning
								multiply = 2
							}
						}
						ai_value_modifier = {
							ai_rationality = 0.25
						}
						set_variable = {
							name = book_subject
							value = flag:medicine
						}
					}
					1 = {
						trigger = {
							is_witch_trigger = yes
						}
						modifier = {
							add = 20
							book_subject_witch_trigger = yes
						}
						ai_value_modifier = {
							ai_boldness = 0.75
						}
						set_variable = {
							name = book_subject
							value = flag:witch
						}
						set_variable = {
							name = book_subject_witch_scope
							value = this
						}
					}
					40 = {
						trigger = {
							has_trait = lifestyle_reveler
						}
						ai_value_modifier = {
							ai_compassion = 0.25
						}
						set_variable = {
							name = book_subject
							value = flag:reveler
						}
					}
					40 = {
						trigger = {
							has_trait = lifestyle_blademaster
						}
						modifier = {
							add = {
								value = martial
								multiply = 2
							}
						}
						set_variable = {
							name = book_subject
							value = flag:blademaster
						}
					}
					40 = {
						trigger = {
							has_trait = lifestyle_hunter
						}
						set_variable = {
							name = book_subject
							value = flag:hunter
						}
					}
					40 = {
						trigger = {
							has_trait = lifestyle_mystic
						}
						modifier = {
							add = {
								value = learning
								multiply = 2
							}
						}
						set_variable = {
							name = book_subject
							value = flag:mystic
						}
					}
					40 = {
						trigger = {
							has_trait = lifestyle_herbalist
						}
						modifier = {
							add = {
								value = learning
								multiply = 2
							}
						}
						set_variable = {
							name = book_subject
							value = flag:herbalist
						}
					}
					40 = {
						trigger = {
							has_trait = legend
						}
						modifier = {
							add = {
								value = martial
								multiply = 2
							}
						}
						set_variable = {
							name = book_subject
							value = flag:legend
						}
					}
					1 = {
						trigger = {
							is_cannibal_trigger = yes
						}
						modifier = {
							add = 30
							book_subject_cannibal_trigger = yes
						}
						ai_value_modifier = {
							ai_boldness = 0.75
						}
						set_variable = {
							name = book_subject
							value = flag:cannibal
						}
					}
					1 = {
						modifier = {
							add = 50
							book_subject_torturer_trigger = yes
						}
						compare_modifier = {
							value = intrigue
							multiplier = 0.5
						}
						set_variable = {
							name = book_subject
							value = flag:torturer
						}
					}
					1 = {
						trigger = {
							is_deviant_trigger = yes
						}
						modifier = {
							add = 30
							OR = {
								has_trait = arrogant
								has_trait = deviant
							}
						}
						ai_value_modifier = {
							ai_boldness = 0.75
						}
						set_variable = {
							name = book_subject
							value = flag:deviant
						}
					}
					50 = {
						trigger = {
							has_trait = lunatic
						}
						ai_value_modifier = {
							ai_boldness = 0.75
						}
						set_variable = {
							name = book_subject
							value = flag:lunatic
						}
					}
					400 = {
						trigger = { #Why are you sponsoring a kid to write??
							is_adult = no
						}
						set_variable = {
							name = book_subject
							value = flag:childhood
						}
						set_favorite_toy_effect = yes
					}
					50 = {
						trigger = {
							book_subject_animals_trigger = yes
						}
						modifier = { #If a kid has a pet they're gonna wanna to write about it
							add = 800
							is_adult = no
						}
						modifier = {
							add = 75
							has_trait = lunatic
						}
						modifier = {
							add = 50
							has_trait = intellect_bad
						}
						set_variable = {
							name = book_subject
							value = flag:animals
						}
					}
					50 = { #They don't care and you can decide!
						trigger = {
							scope:allow_no_subject_option = yes
						}
						modifier = {
							add = 30
							has_personality_submissive_trigger = yes
						}
						ai_value_modifier = {
							ai_boldness = -0.25
							ai_energy = -0.25
						}
					}
				}

				# FALLBACK: The previous list can return nothing if you're bad at all skills and have nothing special going on
				if = {
					limit = {
						NOT = { exists = var:book_subject }
						scope:allow_no_subject_option = no
					}
					random_list = {
						1 = {
							modifier = {
								add = 60
								has_education_martial_trigger = yes
							}
							modifier = {
								add = 40
								OR = {
									prowess >= high_skill_rating
									has_trait = faith_warrior
									has_trait = crusader_king
									has_trait = viking
									number_of_commander_traits >= 1
								}
							}
							modifier = {
								add = {
									value = martial
									multiply = 2
								}
							}
							set_variable = {
								name = book_subject
								value = flag:martial
							}
						}
						1 = {
							modifier = {
								add = 60
								has_education_diplomacy_trigger = yes
							}
							modifier = {
								add = {
									value = diplomacy
									multiply = 2
								}
							}
							set_variable = {
								name = book_subject
								value = flag:diplomacy
							}
						}
						1 = {
							modifier = {
								add = 60
								has_education_stewardship_trigger = yes
							}
							modifier = {
								add = {
									value = stewardship
									multiply = 2
								}
							}
							set_variable = {
								name = book_subject
								value = flag:stewardship
							}
						}
						1 = {
							modifier = {
								add = 60
								has_education_intrigue_trigger = yes
							}
							modifier = {
								add = {
									value = intrigue
									multiply = 2
								}
							}
							set_variable = {
								name = book_subject
								value = flag:intrigue
							}
						}
						1 = {
							modifier = {
								add = 60
								has_education_learning_trigger = yes
							}
							modifier = {
								add = {
									value = learning
									multiply = 2
								}
							}
							set_variable = {
								name = book_subject
								value = flag:learning
							}
						}
					}
				}
			}
		}
	}
}


# Get variables needed for the book
get_book_variables_effect = {

	scope:owner = {
		# If we have a subject we save it as a variable on the owner so that we can access it when setting the subject-feature
		if = {
			limit = {
				NOT = { scope:subject_is_set = flag:no }
			}
			set_variable = {
				name = book_artifact_subject
				value = scope:subject_is_set
				days = 1
			}
		}
		else_if = {
			limit = {
				exists = scope:author
				exists = scope:author.var:book_subject
			}
			set_variable = {
				name = book_artifact_subject
				value = scope:author.var:book_subject
				days = 1
			}
		}

		#If we have a topic we save it as a variable on the owner so that we can access it when setting the topic-feature
		if = {
			limit = {
				NOT = { scope:topic_is_set = flag:no }
			}
			set_variable = {
				name = book_artifact_topic
				value = scope:topic_is_set
				days = 1
			}
		}
		else_if = {
			limit = {
				exists = scope:author
				exists = scope:author.var:book_topic
			}
			set_variable = {
				name = book_artifact_topic
				value = scope:author.var:book_topic
				days = 1
			}
		}
		# If subject or topic is "no" we do nothing and let the feature system handle it

		# To save the topic category if it has been set in events
		if = {
			limit = {
				exists = scope:author
				exists = scope:author.var:book_topic_category
			}
			set_variable = {
				name = book_topic_category
				value = scope:author.var:book_topic_category
				days = 1
			}
		}

	    # Save toy for childhood book loc (if it's a kid writing it will be the author who is a kid)
		if = {
			limit = {
				exists = var:book_artifact_subject
				var:book_artifact_subject = flag:childhood
			}
			if = {
				limit = {
					NOT = { exists = scope:author.var:child_toy_variable }
				}
				scope:author = { set_favorite_toy_effect = yes }
			}
		}
		if = { #Is the book about a mystical animal you hunted? Then we need to save the animal as a variable so we can use the custom loc key in the loc
			limit = {
				exists = var:book_artifact_subject
				var:book_artifact_subject = flag:mystical_animal
			}
			set_variable = {
				name = animal_type
				value = scope:owner.var:hunted_mystical_animal
				days = 1
			}
		}
		# Witch
		if = {
			limit = {
				exists = var:book_artifact_subject
				var:book_artifact_subject = flag:witch
				exists = scope:author.var:book_subject_witch_scope
			}
			set_variable = {
				name = book_subject_witch_scope
				value = scope:author.var:book_subject_witch_scope
				days = 1
			}
		}
		# Soulmate
		if = {
			limit = {
				exists = var:book_artifact_topic
				var:book_artifact_topic = flag:soulmate #Check for relationship variable
			}
			if = {
				limit = {
					exists = scope:author
					exists = scope:author.var:book_topic_relationship
				}
				set_variable = {
					name = book_topic_relationship
					value = scope:author.var:book_topic_relationship
					days = 1
				}
			}
			else_if = {
				limit = {
					exists = var:book_topic_relationship
				}
				var:book_topic_relationship = {
					save_scope_as = soulmate # We still save the scope here for use in events
				}
			}
		}
		# Relationship
		if = {
			limit = {
				exists = var:book_artifact_topic
				var:book_artifact_topic = flag:nemesis #Check for relationship variable
			}
			if = {
				limit = {
					exists = scope:author
					exists = scope:author.var:book_topic_relationship
				}
				set_variable = {
					name = book_topic_relationship
					value = scope:author.var:book_topic_relationship
					days = 1
				}
				scope:author.var:book_topic_relationship = {
					save_scope_as = nemesis # We still save the scope here for use in events
				}
			}
			else_if = {
				limit = {
					exists = var:book_topic_relationship
				}
				set_variable = {
					name = book_topic_relationship
					value = scope:owner.var:book_topic_relationship
					days = 1
				}
				var:book_topic_relationship = {
					save_scope_as = nemesis # We still save the scope here for use in events
				}
			}
		}
		# Unification
		if = {
			limit = {
				exists = var:book_artifact_topic
				var:book_artifact_topic = flag:unification
			}
			#Check for title variable
			if = {
				limit = {
					exists = scope:author
					exists = scope:author.var:book_topic_united_title
				}
				set_variable = {
					name = relevant_title
					value = scope:author.var:book_topic_united_title
					days = 1
				}
			}
			else_if = {
				limit = {
					exists = var:book_topic_united_title
				}
				set_variable = {
					name = relevant_title
					value = scope:owner.var:book_topic_united_title
					days = 1
				}
				var:book_topic_united_title = {
					save_scope_as = relevant_title
				}
			}
		}
		# Creation
		if = {
			limit = {
				exists = var:book_artifact_topic
				var:book_artifact_topic = flag:creation
			}
			#Check for title variable
			if = {
				limit = {
					exists = scope:author
					exists = scope:author.var:book_topic_created_title
				}
				set_variable = {
					name = relevant_title
					value = scope:author.var:book_topic_created_title
					days = 1
				}
				scope:author.var:book_topic_created_title = {
					save_scope_as = relevant_title
				}
			}
			else_if = {
				limit = {
					exists = var:book_topic_created_title
				}
				set_variable = {
					name = relevant_title
					value = scope:owner.var:book_topic_created_title
					days = 1
				}
				var:book_topic_created_title = {
					save_scope_as = relevant_title
				}
			}
		}
		# Restoration
		if = {
			limit = {
				exists = var:book_artifact_topic
				var:book_artifact_topic = flag:restoration
			}
			#Check for title variable
			if = {
				limit = {
					exists = scope:author
					exists = scope:author.var:book_topic_restored_title
				}
				set_variable = {
					name = relevant_title
					value = scope:author.var:book_topic_restored_title
					days = 1
				}
				scope:author.var:book_topic_restored_title = {
					save_scope_as = relevant_title
				}
			}
			else_if = {
				limit = {
					exists = var:book_topic_restored_title
				}
				set_variable = {
					name = relevant_title
					value = scope:owner.var:book_topic_restored_title
					days = 1
				}
				var:book_topic_restored_title = {
					save_scope_as = relevant_title
				}
			}
		}
	}
}

# Here we save the content quality of the book; how well does the author understand/know the subject? This is separate from the artifact quality value since that's about the quality of the artifact itself, not the content of the text
get_book_content_quality_effect = {
	$SKILL_BASE$ = { save_scope_as = skill_base }
	save_scope_value_as = {
		name = book_content_quality
		value = {
			# Choices in events etc. will affect the quality of the artifact you get
			if = {
				limit = {
					exists = scope:skill_base.var:book_content_quality
				}
				add = {
					value = scope:skill_base.var:book_content_quality
					multiply = 10
				}
			}
			# Is it a lifestyle subject? Then it's good if the inspiration owner shares the lifestyle
			if = { # medicine
				limit = {
					has_artifact_feature = book_subject_medicine
				}
				if = {
					limit = {
						scope:skill_base = {
							has_trait = lifestyle_physician
						}
					}
					add = 30
				}
				if = {
					limit = {
						scope:skill_base = {
							has_trait = lifestyle_mystic
						}
					}
					add = 20
				}
				if = {
					limit = {
						scope:skill_base = {
							has_trait = lifestyle_herbalist
						}
					}
					add = 20
				}
				if = {
					limit = {
						scope:skill_base = {
							is_witch_trigger = yes
						}
					}
					add = 10
				}
			}
			if = { # reveler
				limit = {
					has_artifact_feature = book_subject_reveler
					scope:skill_base = {
						has_trait = lifestyle_reveler
					}
				}
				add = 30
			}
			if = { # blademaster
				limit = {
					has_artifact_feature = book_subject_blademaster
					scope:skill_base = {
						has_trait = lifestyle_blademaster
					}
				}
				add = 30
			}
			if = { # hunter
				limit = {
					has_artifact_feature = book_subject_hunter
					scope:skill_base = {
						has_trait = lifestyle_hunter
					}
				}
				add = 30
			}
			if = { # mystic
				limit = {
					has_artifact_feature = book_subject_mystic
					scope:skill_base = {
						has_trait = lifestyle_mystic
					}
				}
				add = 30
			}
			if = { # herbalist
				limit = {
					has_artifact_feature = book_subject_herbalist
					scope:skill_base = {
						has_trait = lifestyle_herbalist
					}
				}
				add = 30
			}
			if = { # cannibal
				limit = {
					has_artifact_feature = book_subject_cannibal
					scope:skill_base = {
						is_cannibal_trigger = yes
					}
				}
				add = 30
			}
			if = { # witch
				limit = {
					has_artifact_feature = book_subject_witch
					scope:skill_base = {
						is_witch_trigger = yes
					}
				}
				add = 30
			}
			if = { # deviant
				limit = {
					has_artifact_feature = book_subject_deviant
					scope:skill_base = {
						is_deviant_trigger = yes
					}
				}
				add = 30
			}
			if = { # lunatic
				limit = {
					has_artifact_feature = book_subject_lunatic
					scope:skill_base = {
						has_trait = lunatic
					}
				}
				add = 30
			}
			if = { # relationship - score based on the authors opinion of the subject
				limit = {
					has_artifact_feature = book_subject_relationship
					scope:skill_base = {
						save_temporary_opinion_value_as = {
							name = opinion_of_subject
							target = scope:owner.var:book_topic_relationship
						}
					}
				}
				add = {
					value = scope:opinion_of_subject
					min = 0
					max = 75
				}
			}
			if = { # relationship - boost if you're socially savvy
				limit = {
					has_artifact_feature = book_subject_relationship
					scope:skill_base = { has_trait = gregarious }
				}
				add = 10
			}
			# If it's about your actions related to unification/creation/restoration of a title then it's just naturally easier to make you look good
			if = {
				limit = {
					OR = {
						has_artifact_feature = book_subject_kingdom
						has_artifact_feature = book_subject_empire
					}
				}
				add = 50
			}
			# The owner and inspiration owner's skills in the relevant subject, and education trait, affects the outcome
			if = {
				limit = {
					has_artifact_feature = book_subject_martial
				}
				add = { #If they're good you get +, if they're shit you get -
					value = average_skill_rating
					subtract = scope:skill_base.martial
					multiply = -6
				}
				add = scope:owner.martial
				scope:skill_base = {
					if = {
						limit = {
							has_trait = education_martial_1
						}
						add = 20
					}
					else_if = {
						limit = {
							has_trait = education_martial_2
						}
						add = 40
					}
					else_if = {
						limit = {
							has_trait = education_martial_3
						}
						add = 60
					}
					else_if = {
						limit = {
							has_trait = education_martial_4
						}
						add = 80
					}
					else_if = {
						limit = {
							has_trait = education_martial_5
						}
						add = 100
					}
				}
			}
			else_if = {
				limit = {
					has_artifact_feature = book_subject_diplomacy
				}
				add = { #If they're good you get +, if they're shit you get -
					value = average_skill_rating
					subtract = scope:skill_base.diplomacy
					multiply = -6
				}
				add = scope:owner.diplomacy
				scope:skill_base = {
					if = {
						limit = {
							has_trait = education_diplomacy_1
						}
						add = 20
					}
					else_if = {
						limit = {
							has_trait = education_diplomacy_2
						}
						add = 40
					}
					else_if = {
						limit = {
							has_trait = education_diplomacy_3
						}
						add = 60
					}
					else_if = {
						limit = {
							has_trait = education_diplomacy_4
						}
						add = 80
					}
					else_if = {
						limit = {
							has_trait = education_diplomacy_5
						}
						add = 100
					}
				}
			}
			else_if = {
				limit = {
					has_artifact_feature = book_subject_stewardship
				}
				add = { #If they're good you get +, if they're shit you get -
					value = average_skill_rating
					subtract = scope:skill_base.stewardship
					multiply = -6
				}
				add = scope:owner.stewardship
				scope:skill_base = {
					if = {
						limit = {
							has_trait = education_stewardship_1
						}
						add = 20
					}
					else_if = {
						limit = {
							has_trait = education_stewardship_2
						}
						add = 40
					}
					else_if = {
						limit = {
							has_trait = education_stewardship_3
						}
						add = 60
					}
					else_if = {
						limit = {
							has_trait = education_stewardship_4
						}
						add = 80
					}
					else_if = {
						limit = {
							has_trait = education_stewardship_5
						}
						add = 100
					}
				}
			}
			else_if = {
				limit = {
					OR = {
						has_artifact_feature = book_subject_intrigue
						has_artifact_feature = book_subject_torturer
					}
				}
				add = { #If they're good you get +, if they're shit you get -
					value = average_skill_rating
					subtract = scope:skill_base.intrigue
					multiply = -6
				}
				add = scope:owner.intrigue
				scope:skill_base = {
					if = {
						limit = {
							has_trait = education_intrigue_1
						}
						add = 20
					}
					else_if = {
						limit = {
							has_trait = education_intrigue_2
						}
						add = 40
					}
					else_if = {
						limit = {
							has_trait = education_intrigue_3
						}
						add = 60
					}
					else_if = {
						limit = {
							has_trait = education_intrigue_4
						}
						add = 80
					}
					else_if = {
						limit = {
							has_trait = education_intrigue_5
						}
						add = 100
					}
				}
			}
			else_if = {
				limit = {
					has_artifact_feature = book_subject_learning
				}
				add = { #If they're good you get +, if they're shit you get -
					value = average_skill_rating
					subtract = scope:skill_base.learning
					multiply = -6
				}
				add = scope:owner.learning
				scope:skill_base = {
					if = {
						limit = {
							has_trait = education_learning_1
						}
						add = 20
					}
					else_if = {
						limit = {
							has_trait = education_learning_2
						}
						add = 40
					}
					else_if = {
						limit = {
							has_trait = education_learning_3
						}
						add = 60
					}
					else_if = {
						limit = {
							has_trait = education_learning_4
						}
						add = 80
					}
					else_if = {
						limit = {
							has_trait = education_learning_5
						}
						add = 100
					}
				}
			}
			# The overall quality has an impact as well
			add = {
				value = scope:quality
				multiply = 0.25
			}
		}
	}
}

# CREATE A BOOK

# -OWNER is always needed
# -CREATOR needs a scope, if you want no author specified you can use "random_dummy_gender_effect = yes" before the book effect and then scope:dummy_gender for author
# -SET_SUBJECT has to be a flag, and has to be one of the subjects defined as a "book_subject" feature. If you want no subject specified (it will then be set in the effect itself) use "flag:no"
# -SET_TOPIC has to be a flag, and has to be one of the topics defined as a "book_topic" feature. If you want no topic specified (it will then be set in the effect itself) use "flag:no". You have to also set the subject if you set the topic!

# Example:
#random_dummy_gender_effect = yes
#create_artifact_book_effect = {
#	OWNER = root
#	CREATOR = scope:dummy_gender
#	SET_SUBJECT = flag:intrigue
#	SET_TOPIC = flag:no
#}
# This will give you a book with no known author about intrigue with a random topic.

create_artifact_book_effect = {
	$OWNER$ = { save_scope_as = owner } #Will always exist!
	$CREATOR$ = { #Doesn't always exist
		save_scope_as = author
	}
	save_temporary_scope_value_as = {
		name = subject_is_set
		value = $SET_SUBJECT$
	}
	save_temporary_scope_value_as = {
		name = topic_is_set
		value = $SET_TOPIC$
	}
	if = {
		limit = {
			exists = scope:dummy_gender
			scope:author = scope:dummy_gender
		}
		clear_saved_scope = author
		clear_saved_scope = dummy_gender
	}
	else = { #If we have an author we save them as a variable on the owner so that we can access them later on when setting the subject etc.
		scope:owner = {
			set_variable = {
				name = book_artifact_author
				value = scope:author
				days = 1
			}
		}
	}
	hidden_effect_new_object = {
		# Get artifact quality and wealth
		get_artifact_quality_effect = yes
		get_artifact_wealth_effect = yes
		

		# To save the subject, topic, and other variables we'll need if it has been set in events or in the effect
		get_book_variables_effect = yes

		if = { #Should this be a court artifact?
			limit = {
				has_royal_court = yes
				has_dlc_feature = court_artifacts
				NOT = { exists = scope:should_be_trinket }
			}
			if = { #Do we have an author?
				limit = {
					exists = scope:author
				}
				if = { #Is this author using Palm Leaf (indian) books?
					limit = {
						scope:author = { artifacts_use_indian_books_trigger = yes }
					}
					scope:owner = {
						create_artifact = {	
							name = placeholder # Will be regenerated in the post-creation effects
							creator = scope:author
							description = placeholder # Will be regenerated in the post-creation effects
							visuals = indian_book
							type = book
							modifier = artifact_placeholder_modifier
							save_scope_as = newly_created_artifact
							wealth = scope:wealth
							quality = scope:quality
							#decaying = no
						}
					}
				}
				else = { #Codices/Non-Indian books
					scope:owner = {
						create_artifact = {	
							name = placeholder # Will be regenerated in the post-creation effects
							creator = scope:author
							description = placeholder # Will be regenerated in the post-creation effects
							visuals = book
							type = book
							modifier = artifact_placeholder_modifier
							save_scope_as = newly_created_artifact
							wealth = scope:wealth
							quality = scope:quality
							#decaying = no
						}
					}
				}
			}
			else = { #We don't have an author
				if = {
					limit = { #Is this a palm leaf/indian book?
						scope:owner = { artifacts_use_indian_books_trigger = yes }
					}
					scope:owner = {
						create_artifact = {	
							name = placeholder # Will be regenerated in the post-creation effects
							description = placeholder # Will be regenerated in the post-creation effects
							visuals = indian_book
							type = book
							modifier = artifact_placeholder_modifier
							save_scope_as = newly_created_artifact
							wealth = scope:wealth
							quality = scope:quality
							#decaying = no
						}
					}
				}
				else = { #This is a codex/non-indian book:
					scope:owner = {
						create_artifact = {	
							name = placeholder # Will be regenerated in the post-creation effects
							description = placeholder # Will be regenerated in the post-creation effects
							visuals = book
							type = book
							history = { type = created_before_history } # We don't know who wrote it
							modifier = artifact_placeholder_modifier
							save_scope_as = newly_created_artifact
							wealth = scope:wealth
							quality = scope:quality
							#decaying = no
						}
					}
				}
			}
		}
		else = { #This is a court artifact
			if = {
				limit = {
					exists = scope:author #We have an author
				}
				if = {
					limit = {
						scope:author = { artifacts_use_indian_books_trigger = yes }
					}
					scope:owner = {
						create_artifact = {	
							name = placeholder # Will be regenerated in the post-creation effects
							creator = scope:author
							description = placeholder # Will be regenerated in the post-creation effects
							visuals = indian_book
							type = journal
							modifier = artifact_placeholder_modifier
							save_scope_as = newly_created_artifact
							wealth = scope:wealth
							quality = scope:quality
						}
					}
					# Subject and cover material is set as a required feature for a book-type artifact, but for a miscellaneous-type it's an optional feature, so we need to set it here
					scope:newly_created_artifact = {
						set_artifact_feature_group = book_subject
						set_artifact_feature_group = book_cover_material
					}
				}
				else = { #This is a codex/non-indian book
					scope:owner = {
						create_artifact = {	
							name = placeholder # Will be regenerated in the post-creation effects
							creator = scope:author
							description = placeholder # Will be regenerated in the post-creation effects
							visuals = book
							type = journal
							modifier = artifact_placeholder_modifier
							save_scope_as = newly_created_artifact
							wealth = scope:wealth
							quality = scope:quality
							
						}
					}
					# Subject and cover material is set as a required feature for a book-type artifact, but for a miscellaneous-type it's an optional feature, so we need to set it here
					scope:newly_created_artifact = {
						set_artifact_feature_group = book_subject
						set_artifact_feature_group = book_cover_material
					}
				}
			}
			else = { #We don't have an author
				if = {
					limit = { #Is this a palm-leaf/indian book?
						scope:owner = { artifacts_use_indian_books_trigger = yes }
					}
					scope:owner = {
						create_artifact = {	
							name = placeholder # Will be regenerated in the post-creation effects
							description = placeholder # Will be regenerated in the post-creation effects
							visuals = indian_book
							type = journal
							modifier = artifact_placeholder_modifier
							save_scope_as = newly_created_artifact
							wealth = scope:wealth
							quality = scope:quality
						}
					}
					# Subject and cover material is set as a required feature for a book-type artifact, but for a miscellaneous-type it's an optional feature, so we need to set it here
					scope:newly_created_artifact = {
						set_artifact_feature_group = book_subject
						set_artifact_feature_group = book_cover_material
					}
				}
				else = { #This isn't a palm leaf/indian book
					scope:owner = {
						create_artifact = {	
							name = placeholder # Will be regenerated in the post-creation effects
							description = placeholder # Will be regenerated in the post-creation effects
							visuals = book
							type = journal
							history = { type = created_before_history } # We don't know who wrote it
							modifier = artifact_placeholder_modifier
							save_scope_as = newly_created_artifact
							wealth = scope:wealth
							quality = scope:quality
						}
					}
					# Subject and cover material is set as a required feature for a book-type artifact, but for a miscellaneous-type it's an optional feature, so we need to 	set it here
					scope:newly_created_artifact = {
						set_artifact_feature_group = book_subject
						set_artifact_feature_group = book_cover_material
					}
				}
			}
		}

		scope:newly_created_artifact = {
			set_artifact_feature_group = book_topic
			set_artifact_feature_group = book_title
			set_artifact_feature_group = book_decoration
			set_artifact_feature_group = decoration_pattern
			get_artifact_feature_references_effect = yes
			# Get quality of written content
			if = {
				limit = {
					NOT = { exists = scope:author }
				}
				get_book_content_quality_effect = { SKILL_BASE = scope:owner }
			}
			else = {
				get_book_content_quality_effect = { SKILL_BASE = scope:author }
			}
			# We save these values as variables on the owner so that we can access them deep in scopes in the desc-loc later on
			scope:owner = {
				set_variable = {
					name = quality
					value = scope:quality
				}
				set_variable = {
					name = wealth
					value = scope:wealth
				}
				set_variable = {
					name = book_content_quality
					value = scope:book_content_quality
				}
			}
			# Generate the updated - final description for the book
			set_artifact_description = artifact_book_description
			# Generate the updated title - final title for the book
			set_artifact_name = artifact_book_title
			# Is the subject a lifestyle?
			if = {
				limit = {
					has_artifact_feature = book_topic_stewardship_old_ledger
				}
				#add_artifact_modifier = artifact_monthly_stewardship_lifestyle_xp_1_modifier
				remove_artifact_modifier = artifact_placeholder_modifier
				flag_as_trash_artifact = yes
			}
			else_if = { 
				limit = { has_artifact_feature = book_subject_martial }
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_monthly_martial_lifestyle_xp_4_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_monthly_martial_lifestyle_xp_3_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_monthly_martial_lifestyle_xp_2_modifier
				}
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_monthly_martial_lifestyle_xp_1_modifier
				}
			}
			else_if = {
				limit = { has_artifact_feature = book_subject_diplomacy }
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_monthly_diplomacy_lifestyle_xp_4_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_monthly_diplomacy_lifestyle_xp_3_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_monthly_diplomacy_lifestyle_xp_2_modifier
				}
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_monthly_diplomacy_lifestyle_xp_1_modifier
				}
			}
			else_if = {
				limit = { has_artifact_feature = book_subject_stewardship }
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_monthly_stewardship_lifestyle_xp_4_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_monthly_stewardship_lifestyle_xp_3_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_monthly_stewardship_lifestyle_xp_2_modifier
				}
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_monthly_stewardship_lifestyle_xp_1_modifier
				}
			}
			else_if = {
				limit = { has_artifact_feature = book_subject_learning }
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_monthly_learning_lifestyle_xp_4_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_monthly_learning_lifestyle_xp_3_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_monthly_learning_lifestyle_xp_2_modifier
				}
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_monthly_learning_lifestyle_xp_1_modifier
				}
			}
			else_if = {
				limit = {
					OR = {
						has_artifact_feature = book_subject_intrigue
						has_artifact_feature = book_subject_torturer
					}
				}
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_monthly_intrigue_lifestyle_xp_4_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_monthly_intrigue_lifestyle_xp_3_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_monthly_intrigue_lifestyle_xp_2_modifier
				}
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_monthly_intrigue_lifestyle_xp_1_modifier
				}
			}
			else_if = {
				limit = { has_artifact_feature = book_subject_empire }
				add_scaled_artifact_modifier_dynasty_prestige_effect = yes
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_short_reign_duration_mult_7_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_short_reign_duration_mult_5_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_short_reign_duration_mult_3_modifier
				}
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_short_reign_duration_mult_1_modifier
				}
				add_artifact_modifier = artifact_dynasty_opinion_2_modifier
				add_artifact_modifier = artifact_court_grandeur_baseline_add_1_modifier
			}
			else_if = {
				limit = { has_artifact_feature = book_subject_kingdom }
				add_scaled_artifact_modifier_dynasty_prestige_effect = yes
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_short_reign_duration_mult_7_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_short_reign_duration_mult_5_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_short_reign_duration_mult_3_modifier
				}
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_short_reign_duration_mult_1_modifier
				}
				add_artifact_modifier = artifact_dynasty_opinion_2_modifier
				add_artifact_modifier = artifact_court_grandeur_baseline_add_1_modifier
			}
			else_if = {
				limit = {
					OR = {
						has_artifact_feature = book_subject_medicine
						has_artifact_feature = book_subject_herbalist
					}
				}
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_health_gain_4_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_health_gain_3_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_health_gain_2_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_health_gain_1_modifier
				}
			}
			else_if = {
				limit = { has_artifact_feature = book_subject_reveler }
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_courtly_vassal_opinion_4_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_courtly_vassal_opinion_3_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_courtly_vassal_opinion_2_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_courtly_vassal_opinion_2_modifier
				}
			}
			else_if = {
				limit = { has_artifact_feature = book_subject_blademaster }
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_prowess_5_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_prowess_4_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_prowess_3_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_prowess_2_modifier
				}
			}
			else_if = {
				limit = { has_artifact_feature = book_subject_hunter }
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_prowess_4_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_prowess_3_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_prowess_2_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_prowess_1_modifier
				}
				add_artifact_modifier = artifact_stress_gain_1_modifier
			}
			else_if = {
				limit = { has_artifact_feature = book_subject_mystic }
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_monthly_learning_lifestyle_xp_4_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_monthly_learning_lifestyle_xp_3_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_monthly_learning_lifestyle_xp_2_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_monthly_learning_lifestyle_xp_1_modifier
				}
				if = {
					limit = {
						NOT = { scope:owner.faith = { has_doctrine_parameter = witchcraft_accepted } }
					}
					add_artifact_modifier = artifact_clergy_opinion_penalty_2_modifier
				}
			}
			else_if = {
				limit = { has_artifact_feature = book_subject_lunatic }
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_stress_gain_4_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_stress_gain_3_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_stress_gain_2_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_stress_gain_1_modifier
				}
			}
			else_if = {
				limit = { has_artifact_feature = book_subject_relationship }
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_personal_scheme_phase_duration_add_10_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_personal_scheme_phase_duration_add_7_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_personal_scheme_phase_duration_add_5_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_personal_scheme_phase_duration_add_2_modifier
				}
			}
			else_if = {
				limit = { #Only for the controversial subjects if they're accepted
					OR = {
						AND = {
							has_artifact_feature = book_subject_cannibal
							NOT = {
								trait_is_criminal_in_faith_trigger = { TRAIT = trait:cannibal FAITH = scope:owner.faith GENDER_CHARACTER = scope:owner }
							}
						}
						AND = {
							has_artifact_feature = book_subject_witch
							NOT = {
								trait_is_criminal_in_faith_trigger = { TRAIT = trait:witch FAITH = scope:owner.faith GENDER_CHARACTER = scope:owner }
							}
						}
						AND = {
							has_artifact_feature = book_subject_deviant
							NOT = {
								trait_is_criminal_in_faith_trigger = { TRAIT = trait:deviant FAITH = scope:owner.faith GENDER_CHARACTER = scope:owner }
							}
						}

					}
				}
				add_scaled_artifact_modifier_prestige_effect = yes
			}
			if = {
				limit = {
					OR = {
						has_artifact_feature = book_subject_family_epic
						has_artifact_feature = book_subject_family_epic_great
					}
				}
				remove_artifact_modifier = artifact_placeholder_modifier
				add_artifact_modifier = artifact_monthly_prestige_add_2_modifier 
				if = {
					limit = {
						artifact_type = book
					}
					add_artifact_modifier = artifact_court_grandeur_baseline_add_1_modifier
				}
				else = {
					add_artifact_modifier = artifact_monthly_prestige_2_modifier
				}
				if = { # Vassal Opinion
					limit = {
						scope:story = { has_variable = opinion_artifact }
					}
					if = {
						limit = { rarity = illustrious }
						add_artifact_modifier = artifact_parochial_vassal_opinion_3_modifier
						add_artifact_modifier = artifact_courtly_vassal_opinion_4_modifier
					}
					else_if = {
						limit = { rarity = famed }
						add_artifact_modifier = artifact_parochial_vassal_opinion_3_modifier
						add_artifact_modifier = artifact_courtly_vassal_opinion_3_modifier
						add_artifact_modifier = artifact_parochial_vassal_opinion_3_modifier
					}
					else_if = {
						limit = { rarity = masterwork }
						add_artifact_modifier = artifact_courtly_vassal_opinion_3_modifier
						add_artifact_modifier = artifact_parochial_vassal_opinion_3_modifier
					} 
					else_if = {
						limit = { rarity = common }
						add_artifact_modifier = artifact_courtly_vassal_opinion_1_modifier
						add_artifact_modifier = artifact_parochial_vassal_opinion_1_modifier
						add_artifact_modifier = artifact_courtly_vassal_opinion_1_modifier
						add_artifact_modifier = artifact_parochial_vassal_opinion_1_modifier
					}
				}
				if = { # Scheme Resistance
					limit = {
						scope:story = { has_variable = scheme_artifact }
					}
					if = { # 8
						limit = { rarity = illustrious }
						add_artifact_modifier = artifact_scheme_resistance_add_2_modifier
						add_artifact_modifier = artifact_scheme_resistance_add_2_modifier
						add_artifact_modifier = artifact_scheme_resistance_add_2_modifier
						add_artifact_modifier = artifact_scheme_resistance_add_2_modifier
					}
					else_if = { # 6
						limit = { rarity = famed }
						add_artifact_modifier = artifact_scheme_resistance_add_2_modifier
						add_artifact_modifier = artifact_scheme_resistance_add_2_modifier
						add_artifact_modifier = artifact_scheme_resistance_add_2_modifier
					}
					else_if = { # 4
						limit = { rarity = masterwork }
						add_artifact_modifier = artifact_scheme_resistance_add_2_modifier
						add_artifact_modifier = artifact_scheme_resistance_add_2_modifier
					} 
					else_if = { # 2
						limit = { rarity = common }
						add_artifact_modifier = artifact_scheme_resistance_add_2_modifier
					}
				}
				if = { # Controlled Province Advantage
					limit = {
						scope:story = { has_variable = advantage_artifact }
					}
					if = { # 10
						limit = { rarity = illustrious }
						add_artifact_modifier = artifact_controlled_province_advantage_8_modifier
						add_artifact_modifier = artifact_controlled_province_advantage_2_modifier
					}
					else_if = { # 8
						limit = { rarity = famed }
						add_artifact_modifier = artifact_controlled_province_advantage_8_modifier
					}
					else_if = { # 6
						limit = { rarity = masterwork }
						add_artifact_modifier = artifact_controlled_province_advantage_6_modifier
					} 
					else_if = { # 4
						limit = { rarity = common }
						add_artifact_modifier = artifact_controlled_province_advantage_4_modifier
					}
				}
				if = { # Personal Scheme Success Chance
					limit = {
						scope:story = { has_variable = sway_artifact }
					}
					if = { # 10
						limit = { rarity = illustrious }
						add_artifact_modifier = artifact_owned_personal_scheme_success_chance_add_12_modifier # 20
						add_artifact_modifier = artifact_owned_personal_scheme_success_chance_add_8_modifier
					}
					else_if = {
						limit = { rarity = famed }
						add_artifact_modifier = artifact_owned_personal_scheme_success_chance_add_8_modifier # 16
						add_artifact_modifier = artifact_owned_personal_scheme_success_chance_add_8_modifier
					}
					else_if = {
						limit = { rarity = masterwork }
						add_artifact_modifier = artifact_owned_personal_scheme_success_chance_add_12_modifier # 12
					} 
					else_if = {
						limit = { rarity = common }
						add_artifact_modifier = artifact_owned_personal_scheme_success_chance_add_8_modifier # 8
					}
				}
				if = { # Monthly Piety + Same Faith Domain Tax
					limit = {
						scope:story = { has_variable = piety_artifact }
					}
					if = { # 0.4 + 1
						limit = { rarity = illustrious }
						add_artifact_modifier = artifact_monthly_piety_4_modifier # 0.4
						add_artifact_modifier = artifact_domain_tax_same_faith_mult_4_modifier # 1
						add_artifact_modifier = artifact_domain_tax_same_faith_mult_4_modifier
						add_artifact_modifier = artifact_domain_tax_same_faith_mult_2_modifier
					}
					else_if = { # 0.3 + 0.8
						limit = { rarity = famed }
						add_artifact_modifier = artifact_monthly_piety_3_modifier
						add_artifact_modifier = artifact_domain_tax_same_faith_mult_4_modifier
						add_artifact_modifier = artifact_domain_tax_same_faith_mult_4_modifier
					}
					else_if = { # 0.2 + 0.6
						limit = { rarity = masterwork }
						add_artifact_modifier = artifact_monthly_piety_2_modifier
						add_artifact_modifier = artifact_domain_tax_same_faith_mult_4_modifier
						add_artifact_modifier = artifact_domain_tax_same_faith_mult_2_modifier
					} 
					else_if = { # 0.1 + 0.4
						limit = { rarity = common }
						add_artifact_modifier = artifact_monthly_piety_1_modifier
						add_artifact_modifier = artifact_domain_tax_same_faith_mult_4_modifier
					}
				}
				if = {
					limit = { has_artifact_feature = book_subject_family_epic_great }
					add_artifact_modifier = artifact_monthly_prestige_add_2_modifier #This is renown, can be combined with the renown option during making and adds up with the base renown added to all chronicles
				}
				#Small boost from perspectives:
				
			}
			# Modifiers applied based on topic
			if = {
				limit = {
					has_artifact_feature = book_topic_stewardship_old_ledger
				}
				add_artifact_modifier = artifact_monthly_stewardship_lifestyle_xp_1_modifier
				remove_artifact_modifier = artifact_placeholder_modifier
			}
			if = {
				limit = {
					trigger_if = {
						limit = {
							exists = scope:topic
						}
						OR = {
							scope:topic = flag:curse_sorcery
							scope:topic = flag:poisons
						}
					}
					trigger_else = {
						OR = {
							has_artifact_feature = book_topic_witch_curse_sorcery
							has_artifact_feature = book_topic_intrigue_poisons
						}
					}
				}
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_monthly_intrigue_lifestyle_xp_4_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_monthly_intrigue_lifestyle_xp_3_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_monthly_intrigue_lifestyle_xp_2_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_monthly_intrigue_lifestyle_xp_1_modifier
				}
				add_artifact_modifier = artifact_owned_hostile_scheme_success_chance_add_2_modifier
				add_artifact_modifier = artifact_dread_gain_mult_1_modifier
			}
			else_if = {
				limit = {
					trigger_if = {
						limit = {
							exists = scope:topic
						}
						OR = {
							scope:topic = flag:love_sorcery
							scope:topic = flag:seduction
						}
					}
					trigger_else = {
						OR = {
							has_artifact_feature = book_topic_witch_love_sorcery
							has_artifact_feature = book_topic_intrigue_seduction
						}
					}
				}
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_monthly_intrigue_lifestyle_xp_4_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_monthly_intrigue_lifestyle_xp_3_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_monthly_intrigue_lifestyle_xp_2_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_monthly_intrigue_lifestyle_xp_1_modifier
				}
				add_artifact_modifier = artifact_scheme_resistance_add_2_modifier
			}
			else_if = {
				limit = {
					trigger_if = {
						limit = {
							exists = scope:topic
						}
						scope:topic = flag:fertility
					}
					trigger_else = {
						OR = {
							has_artifact_feature = book_topic_intrigue_fertility
							has_artifact_feature = book_topic_intrigue_the_art_of_love
						}
					}
				}
				
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_fertility_gain_4_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_fertility_gain_3_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_fertility_gain_2_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_fertility_gain_1_modifier
				}
				
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_monthly_intrigue_lifestyle_xp_4_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_monthly_intrigue_lifestyle_xp_3_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_monthly_intrigue_lifestyle_xp_2_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_monthly_intrigue_lifestyle_xp_1_modifier
				}
			}
			
			else_if = {
				limit = {
					trigger_if = {
						limit = {
							exists = scope:topic
						}
						scope:topic = flag:punishment
					}
					trigger_else = {
						OR = {
							has_artifact_feature = book_topic_intrigue_punishment
							has_artifact_feature = book_topic_intrigue_punishment_not_torturer
						}
					}
				}
				add_artifact_modifier = artifact_monthly_intrigue_lifestyle_xp_2_modifier
				add_artifact_modifier = artifact_stress_gain_2_modifier
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_dread_baseline_add_4_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_dread_baseline_add_3_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_dread_baseline_add_2_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_dread_baseline_add_1_modifier
				}
			}
			else_if = {
				limit = {
					trigger_if = {
						limit = {
							exists = scope:topic
						}
						OR = {
							scope:topic = flag:digest
							scope:topic = flag:admin
						}
					}
					trigger_else = {
						OR = {
							has_artifact_feature = book_topic_stewardship_digest
							has_artifact_feature = book_topic_stewardship_admin
						}
					}
				}
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_monthly_stewardship_lifestyle_xp_4_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_monthly_stewardship_lifestyle_xp_3_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_monthly_stewardship_lifestyle_xp_2_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_monthly_stewardship_lifestyle_xp_1_modifier
				}
			}
			else_if = {
				limit = {
					trigger_if = {
						limit = {
							exists = scope:topic
						}
						scope:topic = flag:architect
					}
					trigger_else = {
						has_artifact_feature = book_topic_stewardship_architect
					}
				}
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_build_time_4_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_build_time_3_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_build_time_2_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_build_time_1_modifier
				}
			}
			else_if = {
				limit = {
					trigger_if = {
						limit = {
							exists = scope:topic
						}
						OR = {
							scope:topic = flag:edda
							scope:topic = flag:orkneyinga
						}
					}
					trigger_else = {
						OR = {
							has_artifact_feature = book_topic_diplomacy_edda
							has_artifact_feature = book_topic_diplomacy_orkneyinga
						}
					}
				}
				add_artifact_modifier = artifact_monthly_martial_lifestyle_xp_1_modifier
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_raid_speed_8_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_raid_speed_6_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_raid_speed_4_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_raid_speed_2_modifier
				}
			}
			else_if = {
				limit = {
					trigger_if = {
						limit = {
							exists = scope:topic
						}
						scope:topic = flag:poetry
					}
					trigger_else = {
						has_artifact_feature = book_topic_diplomacy_poetry
					}
				}
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_monthly_diplomacy_lifestyle_xp_4_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_monthly_diplomacy_lifestyle_xp_3_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_monthly_diplomacy_lifestyle_xp_2_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_monthly_diplomacy_lifestyle_xp_1_modifier
				}
				
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_owned_personal_scheme_success_chance_add_8_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_owned_personal_scheme_success_chance_add_6_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_owned_personal_scheme_success_chance_add_4_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_owned_personal_scheme_success_chance_add_2_modifier
				}
			}
			else_if = {
				limit = {
					trigger_if = {
						limit = {
							exists = scope:topic
						}
						scope:topic = flag:jokes
					}
					trigger_else = {
						has_artifact_feature = book_topic_diplomacy_jokes
					}
				}
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_monthly_diplomacy_lifestyle_xp_4_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_monthly_diplomacy_lifestyle_xp_3_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_monthly_diplomacy_lifestyle_xp_2_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_monthly_diplomacy_lifestyle_xp_1_modifier
				}
				
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_courtier_and_guest_opinion_7_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_courtier_and_guest_opinion_5_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_courtier_and_guest_opinion_3_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_courtier_and_guest_opinion_1_modifier
				}
				add_artifact_modifier = artifact_monthly_tyranny_2_modifier
			}
			else_if = {
				limit = {
					trigger_if = {
						limit = {
							exists = scope:topic
						}
						OR = {
							scope:topic = flag:kalila
							scope:topic = flag:hitopadesa
							scope:topic = flag:speculum
						}
					}
					trigger_else = {
						OR = {
							has_artifact_feature = book_topic_diplomacy_kalila
							has_artifact_feature = book_topic_diplomacy_hitopadesa
							has_artifact_feature = book_topic_stewardship_speculum
						}
					}
				}
				add_artifact_modifier = artifact_monthly_stewardship_lifestyle_xp_1_modifier
				add_artifact_modifier = artifact_monthly_diplomacy_lifestyle_xp_1_modifier 
			}
			else_if = {
				limit = {
					trigger_if = {
						limit = {
							exists = scope:topic
						}
						scope:topic = flag:cicero
					}
					trigger_else = {
						has_artifact_feature = book_topic_diplomacy_cicero
					}
				}
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_monthly_diplomacy_lifestyle_xp_4_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_monthly_diplomacy_lifestyle_xp_3_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_monthly_diplomacy_lifestyle_xp_2_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_monthly_diplomacy_lifestyle_xp_1_modifier
				}
				add_artifact_modifier = artifact_diplomacy_1_modifier
			}
			else_if = {
				limit = {
					trigger_if = {
						limit = {
							exists = scope:topic
						}
						scope:topic = flag:dynasty
					}
					trigger_else = {
						OR = {
							has_artifact_feature = book_topic_diplomacy_dynasty
							has_artifact_feature = book_topic_diplomacy_dynasty_big
						}
					}
				}
				add_artifact_modifier = artifact_monthly_diplomacy_lifestyle_xp_1_modifier
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_dynasty_opinion_7_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_dynasty_opinion_5_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_dynasty_opinion_3_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_dynasty_opinion_1_modifier
				}
				
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_monthly_prestige_add_8_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_monthly_prestige_add_6_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_monthly_prestige_add_4_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_monthly_prestige_add_2_modifier
				}
			}
			else_if = {
				limit = {
					trigger_if = {
						limit = {
							exists = scope:topic
						}
						scope:topic = flag:duels
					}
					trigger_else = {
						has_artifact_feature = book_topic_martial_duels
					}
				}
				add_artifact_modifier = artifact_monthly_martial_lifestyle_xp_1_modifier
				
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_prowess_8_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_prowess_6_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_prowess_4_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_prowess_2_modifier
				}
			}
			else_if = {
				limit = {
					trigger_if = {
						limit = {
							exists = scope:topic
						}
						scope:topic = flag:chivalry
					}
					trigger_else = {
						has_artifact_feature = book_topic_martial_chivalry
					}
				}
				add_artifact_modifier = artifact_monthly_martial_lifestyle_xp_1_modifier
				
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_attraction_opinion_4_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_attraction_opinion_3_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_attraction_opinion_2_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_attraction_opinion_1_modifier
				}
			}
			else_if = {
				limit = {
					trigger_if = {
						limit = {
							exists = scope:topic
						}
						scope:topic = flag:military
					}
					trigger_else = {
						has_artifact_feature = book_topic_martial_military
					}
				}
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_controlled_province_advantage_7_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_controlled_province_advantage_5_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_controlled_province_advantage_3_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_controlled_province_advantage_1_modifier
				}
				
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_monthly_martial_lifestyle_xp_4_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_monthly_martial_lifestyle_xp_3_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_monthly_martial_lifestyle_xp_2_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_monthly_martial_lifestyle_xp_1_modifier
				}
			}
			else_if = {
				limit = {
					trigger_if = {
						limit = {
							exists = scope:topic
						}
						OR = {
							scope:topic = flag:science
							scope:topic = flag:aristotle
						}
					}
					trigger_else = {
						OR = {
							has_artifact_feature = book_topic_medicine_science
							has_artifact_feature = book_topic_medicine_science_big
							has_artifact_feature = book_topic_learning_aristotle
							has_artifact_feature = book_topic_learning_metaphysical_conundrums
							has_artifact_feature = book_topic_learning_tome_collections
						}
					}
				}
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_monthly_learning_lifestyle_xp_4_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_monthly_learning_lifestyle_xp_3_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_monthly_learning_lifestyle_xp_2_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_monthly_learning_lifestyle_xp_1_modifier
				}
				add_artifact_modifier = artifact_learning_1_modifier
			}
			else_if = {
				limit = {
					trigger_if = {
						limit = {
							exists = scope:topic
						}
						scope:topic = flag:artifact_book_topic_anatomy
					}
					trigger_else = {
						OR = {
							has_artifact_feature = book_topic_learning_anatomy
							has_artifact_feature = book_topic_medicine_medicine
							has_artifact_feature = book_topic_medicine_herbs
							has_artifact_feature = book_topic_medicine_galen
						}
					}
				}
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_health_gain_4_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_health_gain_3_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_health_gain_2_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_health_gain_1_modifier
				}
				add_artifact_modifier = artifact_learning_1_modifier
			}
			else_if = {
				limit = {
					trigger_if = {
						limit = {
							exists = scope:topic
						}
						OR = {
							scope:topic = flag:religious
							scope:topic = flag:prayers
							scope:topic = flag:golden_legend
							scope:topic = flag:hours
						}
					}
					trigger_else = {
						OR = {
							has_artifact_feature = book_topic_learning_religious
							has_artifact_feature = book_topic_learning_religious_big
							has_artifact_feature = book_topic_learning_prayers
							has_artifact_feature = book_topic_learning_hours
							has_artifact_feature = book_topic_learning_golden_legend
							has_artifact_feature = book_topic_learning_theological_treaties
						}
					}
				}
				add_scaled_artifact_modifier_devotion_effect = yes
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_monthly_piety_gain_mult_8_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_monthly_piety_gain_mult_6_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_monthly_piety_gain_mult_4_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_monthly_piety_gain_mult_2_modifier
				}
			}
			else_if = {
				limit = {
					trigger_if = {
						limit = {
							exists = scope:topic
						}
						OR = {
							scope:topic = flag:iliad
							scope:topic = flag:mahabharata
							scope:topic = flag:mufaddaliyat
						}
					}
					trigger_else = {
						OR = {
							has_artifact_feature = book_topic_learning_iliad
							has_artifact_feature = book_topic_learning_mahabharata
							has_artifact_feature = book_topic_learning_mufaddaliyat
						}
					}
				}
				add_artifact_modifier = artifact_monthly_learning_lifestyle_xp_1_modifier
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_monthly_tyranny_7_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_monthly_tyranny_5_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_monthly_tyranny_3_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_monthly_tyranny_1_modifier
				}
			}
			else_if = {
				limit = {
					trigger_if = {
						limit = {
							exists = scope:topic
						}
						scope:topic = flag:soulmate
					}
					trigger_else = {
						has_artifact_feature = book_topic_soulmate
					}
				}
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_attraction_opinion_4_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_attraction_opinion_3_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_attraction_opinion_2_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_attraction_opinion_1_modifier
				}
				add_artifact_modifier = artifact_stress_gain_1_modifier
			}
			else_if = {
				limit = {
					trigger_if = {
						limit = {
							exists = scope:topic
						}
						scope:topic = flag:nemesis
					}
					trigger_else = {
						has_artifact_feature = book_topic_nemesis
					}
				}
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_dread_gain_mult_4_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_dread_gain_mult_3_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_dread_gain_mult_2_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_dread_gain_mult_1_modifier
				}
				add_artifact_modifier = artifact_stress_gain_1_modifier
			}
			else_if = {
				limit = {
					trigger_if = {
						limit = {
							exists = scope:topic
						}
						OR = {
							scope:topic = flag:animals_your_cat
							scope:topic = flag:animals_your_dog
						}
					}
					trigger_else = {
						OR = {
							has_artifact_feature = book_topic_animals_your_cat
							has_artifact_feature = book_topic_animals_your_cat_no_name
							has_artifact_feature = book_topic_animals_your_dog
							has_artifact_feature = book_topic_animals_your_dog_no_name
							has_artifact_feature = book_topic_animals_animals
						}
					}
				}
				add_scaled_artifact_modifier_prestige_effect = yes
				add_artifact_modifier = artifact_stress_gain_1_modifier
			}
			else_if = {
				limit = {
					trigger_if = {
						limit = {
							exists = scope:topic
						}
						scope:topic = flag:childhood
					}
					trigger_else = {
						OR = {
							has_artifact_feature = book_topic_childhood_one
							has_artifact_feature = book_topic_childhood_two
						}
					}
				}
				add_artifact_modifier = artifact_stress_gain_1_modifier
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_courtier_and_guest_opinion_6_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_courtier_and_guest_opinion_5_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_courtier_and_guest_opinion_3_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_courtier_and_guest_opinion_1_modifier
				}
			}
			else_if = {
				limit = {
					trigger_if = {
						limit = {
							exists = scope:topic
						}
						scope:topic = flag:mercury
					}
					trigger_else = {
						has_artifact_feature = book_topic_alchemy_mercury
					}
				}
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_clergy_opinion_7_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_clergy_opinion_5_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_clergy_opinion_3_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_clergy_opinion_1_modifier
				}
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_monthly_learning_lifestyle_xp_4_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_monthly_learning_lifestyle_xp_3_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_monthly_learning_lifestyle_xp_2_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_monthly_learning_lifestyle_xp_1_modifier
				}
				add_artifact_modifier = artifact_monthly_prestige_2_modifier
			}
			else_if = {
				limit = {
					trigger_if = {
						limit = {
							exists = scope:topic
						}
						scope:topic = flag:arsenic
					}
					trigger_else = {
						has_artifact_feature = book_topic_alchemy_arsenic
					}
				}
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_owned_hostile_scheme_success_chance_add_7_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_owned_hostile_scheme_success_chance_add_5_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_owned_hostile_scheme_success_chance_add_3_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_owned_hostile_scheme_success_chance_add_1_modifier
				}
				
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_dread_gain_mult_4_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_dread_gain_mult_3_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_dread_gain_mult_2_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_dread_gain_mult_1_modifier
				}
				add_artifact_modifier = artifact_monthly_learning_lifestyle_xp_1_modifier
			}
			else_if = {
				limit = {
					trigger_if = {
						limit = {
							exists = scope:topic
						}
						scope:topic = flag:gold
					}
					trigger_else = {
						has_artifact_feature = book_topic_alchemy_gold
					}
				}
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_monthly_income_4_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_monthly_income_3_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_monthly_income_2_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_monthly_income_1_modifier
				}
				
				add_scaled_artifact_modifier_prestige_effect = yes
				
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_monthly_stewardship_lifestyle_xp_4_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_monthly_stewardship_lifestyle_xp_3_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_monthly_stewardship_lifestyle_xp_2_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_monthly_stewardship_lifestyle_xp_1_modifier
				}
			}
			else_if = {
				limit = {
					trigger_if = {
						limit = {
							exists = scope:topic
						}
						scope:topic = flag:silver
					}
					trigger_else = {
						has_artifact_feature = book_topic_alchemy_silver
					}
				}
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_monthly_income_4_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_monthly_income_3_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_monthly_income_2_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_monthly_income_1_modifier
				}
				
				add_scaled_artifact_modifier_prestige_effect = yes
				
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_monthly_stewardship_lifestyle_xp_4_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_monthly_stewardship_lifestyle_xp_3_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_monthly_stewardship_lifestyle_xp_2_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_monthly_stewardship_lifestyle_xp_1_modifier
				}
			}
			else_if = {
				limit = { 
					has_artifact_feature = book_subject_alchemy 
				}
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_monthly_learning_lifestyle_xp_4_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_monthly_learning_lifestyle_xp_3_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_monthly_learning_lifestyle_xp_2_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_monthly_learning_lifestyle_xp_1_modifier
				}
				add_scaled_artifact_modifier_prestige_effect = yes
				add_artifact_modifier = artifact_learning_1_modifier
			}
			else_if = {
				limit = {
					has_artifact_feature = book_subject_language_manual
				}
				add_artifact_modifier = artifact_learn_language_scheme_phase_duration_add_1_modifier
				remove_artifact_modifier = artifact_placeholder_modifier
			}
			else_if = {
				limit = {
					trigger_if = {
						limit = {
							exists = scope:topic
						}
						scope:topic = flag:martial_military_strategies
					}
					trigger_else = {
						has_artifact_feature = book_topic_martial_military_strategies
					}
				}

				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_hard_casualty_modifier_3_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_hard_casualty_modifier_2_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_hard_casualty_modifier_1_modifier
				}
				
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_monthly_martial_lifestyle_xp_4_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_monthly_martial_lifestyle_xp_3_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_monthly_martial_lifestyle_xp_2_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_monthly_martial_lifestyle_xp_1_modifier
				}

			}
			else_if = {
				limit = {
					trigger_if = {
						limit = {
							exists = scope:topic
						}
						scope:topic = flag:martial_troop_compositions
					}
					trigger_else = {
						has_artifact_feature = book_topic_martial_troop_compositions
					}
				}

				if = {
					limit = {
						rarity = illustrious
					}
					random_list = {
						50 = { add_artifact_modifier = artifact_heavy_cavalry_toughness_3_modifier }
						50 = { add_artifact_modifier = artifact_heavy_infantry_toughness_3_modifier }
					}
				}
				else_if = {
					limit = {
						rarity = famed
					}
					random_list = {
						50 = { add_artifact_modifier = artifact_heavy_cavalry_toughness_2_modifier }
						50 = { add_artifact_modifier = artifact_heavy_infantry_toughness_2_modifier }
					}
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					random_list = {
						50 = { add_artifact_modifier = artifact_heavy_cavalry_toughness_1_modifier }
						50 = { add_artifact_modifier = artifact_heavy_infantry_toughness_1_modifier }
					}
				}
				
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_monthly_martial_lifestyle_xp_4_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_monthly_martial_lifestyle_xp_3_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_monthly_martial_lifestyle_xp_2_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_monthly_martial_lifestyle_xp_1_modifier
				}
			}
			else_if = {
				limit = {
					trigger_if = {
						limit = {
							exists = scope:topic
						}
						scope:topic = flag:diplomacy_court_alliances
					}
					trigger_else = {
						has_artifact_feature = book_topic_diplomacy_court_alliances
					}
				}

				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_monthly_diplomacy_lifestyle_xp_4_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_monthly_diplomacy_lifestyle_xp_3_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_monthly_diplomacy_lifestyle_xp_2_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_monthly_diplomacy_lifestyle_xp_1_modifier
				}

				add_artifact_modifier = artifact_diplomacy_1_modifier

			}
			else_if = {
				limit = {
					trigger_if = {
						limit = {
							exists = scope:topic
						}
						scope:topic = flag:diplomacy_court_politics
					}
					trigger_else = {
						has_artifact_feature = book_topic_diplomacy_court_politics
					}
				}

				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_monthly_diplomacy_lifestyle_xp_4_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_monthly_diplomacy_lifestyle_xp_3_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_monthly_diplomacy_lifestyle_xp_2_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_monthly_diplomacy_lifestyle_xp_1_modifier
				}


				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_courtier_and_guest_opinion_3_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_courtier_and_guest_opinion_2_modifier
				}
				else_if = {
					limit = {
						OR = {
							rarity = common
							rarity = masterwork
						}
					}
					add_artifact_modifier = artifact_courtier_and_guest_opinion_1_modifier
				}
			}
			else_if = {
				limit = {
					trigger_if = {
						limit = {
							exists = scope:topic
						}
						scope:topic = flag:stewardship_trade_routes
					}
					trigger_else = {
						has_artifact_feature = book_topic_stewardship_trade_routes
					}
				}

				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_development_growth_3_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_development_growth_2_modifier
				}
				else_if = {
					limit = {
						OR = {
							rarity = common
							rarity = masterwork
						}
					}
					add_artifact_modifier = artifact_development_growth_1_modifier
				}

				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_monthly_stewardship_lifestyle_xp_4_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_monthly_stewardship_lifestyle_xp_3_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_monthly_stewardship_lifestyle_xp_2_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_monthly_stewardship_lifestyle_xp_1_modifier
				}
			}
			else_if = {
				limit = {
					trigger_if = {
						limit = {
							exists = scope:topic
						}
						scope:topic = flag:stewardship_best_practices_tax_collectors
					}
					trigger_else = {
						has_artifact_feature = book_topic_stewardship_best_practices_tax_collectors
					}
				}

				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_domain_tax_mult_3_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_domain_tax_mult_2_modifier
				}
			}
			else_if = {
				limit = {
					trigger_if = {
						limit = {
							exists = scope:topic
						}
						scope:topic = flag:diplomacy_art_of_feasting
					}
					trigger_else = {
						has_artifact_feature = book_topic_diplomacy_art_of_feasting
					}
				}
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_courtier_and_guest_opinion_7_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_courtier_and_guest_opinion_5_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_courtier_and_guest_opinion_3_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_courtier_and_guest_opinion_1_modifier
				}
			}
			else_if = {
				limit = {
					trigger_if = {
						limit = {
							exists = scope:topic
						}
						scope:topic = flag:stewardship_lawmaking
					}
					trigger_else = {
						has_artifact_feature = book_topic_stewardship_lawmaking
					}
				}

				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_vassal_limit_4_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_vassal_limit_3_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_vassal_limit_2_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_vassal_limit_1_modifier
				}
			}


			# Is the subject something weird? Then you'll get a penalty
			if = {
				limit = {
					has_artifact_feature = book_subject_cannibal
				}
				if = { #We give a bigger boost here if it's illegal since they get nothing else
					limit = {
						trait_is_criminal_in_faith_trigger = { TRAIT = trait:cannibal FAITH = root.faith GENDER_CHARACTER = root }
					}
					add_artifact_modifier = artifact_dread_baseline_add_2_modifier
					add_artifact_modifier = artifact_vassal_opinion_penalty_1_modifier
				}
				else = {
					add_artifact_modifier = artifact_dread_baseline_add_1_modifier
				}
				if = {
					limit = {
						trigger_if = {
							limit = {
								exists = scope:topic
							}
							scope:topic = flag:cannibal_recipes
						}
						trigger_else = {
							has_artifact_feature = book_topic_cannibal_recipes
						}
					}
					add_artifact_modifier = artifact_health_gain_1_modifier
				}
				else = {
					add_artifact_modifier = artifact_stress_gain_1_modifier
				}
			}
			if = {
				limit = {
					has_artifact_feature = book_subject_witch
				}
				if = { #We give a bigger boost here if it's illegal since they get nothing else
					limit = {
						trait_is_criminal_in_faith_trigger = { TRAIT = trait:witch FAITH = root.faith GENDER_CHARACTER = root }
					}
					add_artifact_modifier = artifact_dread_gain_mult_2_modifier
					add_artifact_modifier = artifact_monthly_learning_lifestyle_xp_2_modifier
					add_artifact_modifier = artifact_clergy_opinion_penalty_2_modifier
				}
				else = {
					add_artifact_modifier = artifact_monthly_learning_lifestyle_xp_1_modifier
				}
			}
			if = {
				limit = {
					has_artifact_feature = book_subject_deviant
				}
				if = { #We give a bigger boost here if it's illegal since they get nothing else
					limit = {
						trait_is_criminal_in_faith_trigger = { TRAIT = trait:deviant FAITH = root.faith GENDER_CHARACTER = root }
					}
					add_artifact_modifier = artifact_vassal_opinion_penalty_1_modifier
					add_artifact_modifier = artifact_stress_gain_2_modifier
					add_artifact_modifier = artifact_seduce_scheme_phase_duration_mult_1_modifier
				}
				else = {
					add_artifact_modifier = artifact_stress_gain_1_modifier
					add_artifact_modifier = artifact_seduce_scheme_phase_duration_mult_1_modifier
				}
			}
			set_variable = {
				name = quality
				value = scope:quality
			}
			set_variable = {
				name = wealth
				value = scope:wealth
			}
			set_variable = {
				name = book_content_quality
				value = scope:book_content_quality
			}
		}
	}

	#To clean out variables
	if = {
		limit = {
			exists = scope:author
		}
		scope:author = {
			if = {
				limit = {
					has_variable = book_subject
				}
				remove_variable = book_subject
			}
			if = {
				limit = {
					has_variable = book_topic
				}
				remove_variable = book_topic
			}
			if = {
				limit = {
					has_variable = book_topic_category
				}
				remove_variable = book_topic_category
			}
			if = {
				limit = {
					has_variable = book_content_quality
				}
				remove_variable = book_content_quality
			}
		}
	}
	scope:owner = {
		if = {
			limit = { has_variable = book_artifact_subject }
			remove_variable = book_artifact_subject
		}
		if = {
			limit = { has_variable = book_artifact_topic }
			remove_variable = book_artifact_topic
		}
		if = {
			limit = { has_variable = book_topic_category }
			remove_variable = book_topic_category
		}
		if = {
			limit = {
				has_variable = book_topic_category
			}
			remove_variable = book_topic_category
		}
		if = {
			limit = {
				has_variable = book_content_quality
			}
			remove_variable = book_content_quality
		}
	}

	if = {
		limit = {
			exists = scope:should_be_trinket 
		}
		clear_saved_scope = should_be_trinket 	
	}
}

create_artifact_pedestal_reliquary_christian_effect = {
	$OWNER$ = { save_scope_as = owner }

	random_list = {
		20 = {
			save_scope_value_as = {
				name = christian_relic_name
				value = flag:nail
			}
		}
		15 = {
			save_scope_value_as = {
				name = christian_relic_name
				value = flag:thorn
			}
		}
		5 = {
			save_scope_value_as = {
				name = christian_relic_name
				value = flag:sandals
			}
		}
		5 = {
			save_scope_value_as = {
				name = christian_relic_name
				value = flag:girdle
			}
		}
		10 = {
			save_scope_value_as = {
				name = christian_relic_name
				value = flag:skull
			}
		}
		10 = {
			save_scope_value_as = {
				name = christian_relic_name
				value = flag:arm
			}
		}
		5 = {
			save_scope_value_as = {
				name = christian_relic_name
				value = flag:loincloth
			}
		}
		20 = {
			save_scope_value_as = {
				name = christian_relic_name
				value = flag:cross
			}
		}
		5 = {
			save_scope_value_as = {
				name = christian_relic_name
				value = flag:crown
			}
		}
		5 = {
			save_scope_value_as = {
				name = christian_relic_name
				value = flag:veronica
			}
		}
	}

	get_artifact_quality_effect = yes
	get_artifact_wealth_effect = yes

	scope:owner = {
		create_artifact = {	
			name = artifact_pedestal_reliquary_christian_name
			creator = scope:owner
			description = artifact_pedestal_reliquary_christian_description
			visuals = reliquary
			type = pedestal
			template = christian_relic_template
			modifier = artifact_monthly_piety_3_modifier
			save_scope_as = newly_created_artifact
			wealth = scope:wealth
			quality = scope:quality
			#decaying = no
		}
	}

	scope:newly_created_artifact = {
		add_scaled_artifact_modifier_piety_effect = yes
		add_scaled_artifact_modifier_devotion_effect = yes
		add_scaled_artifact_modifier_grandeur_small_effect = yes
		set_variable = {
			name = relic
			value = flag:christian
		}
	}
}

create_artifact_pedestal_reliquary_islam_effect = {
	$OWNER$ = { save_scope_as = owner }

	random_list = {
		20 = {
			save_scope_value_as = {
				name = islam_relic_name
				value = flag:hair
			}
		}
		5 = {
			save_scope_value_as = {
				name = islam_relic_name
				value = flag:cloak
			}
		}
		10 = {
			save_scope_value_as = {
				name = islam_relic_name
				value = flag:hand
			}
		}
		5 = {
			save_scope_value_as = {
				name = islam_relic_name
				value = flag:keys
			}
		}
		15 = {
			save_scope_value_as = {
				name = islam_relic_name
				value = flag:tooth
			}
		}
		10 = {
			save_scope_value_as = {
				name = islam_relic_name
				value = flag:seal
			}
		}
		5 = {
			save_scope_value_as = {
				name = islam_relic_name
				value = flag:banner
			}
		}
	}

	get_artifact_quality_effect = yes
	get_artifact_wealth_effect = yes

	scope:owner = {
		create_artifact = {	
			name = artifact_pedestal_reliquary_islam_name
			creator = scope:owner
			description = artifact_pedestal_reliquary_islam_description
			visuals = reliquary
			type = pedestal
			template = islam_relic_template
			modifier = artifact_monthly_piety_3_modifier
			save_scope_as = newly_created_artifact
			wealth = scope:wealth
			quality = scope:quality
			#decaying = no
		}
	}

	scope:newly_created_artifact = {
		add_scaled_artifact_modifier_piety_effect = yes
		add_scaled_artifact_modifier_devotion_effect = yes
		add_scaled_artifact_modifier_grandeur_small_effect = yes
		set_variable = {
			name = relic
			value = flag:islamic
		}
	}
}

create_artifact_pedestal_reliquary_buddhism_effect = {
	$OWNER$ = { save_scope_as = owner }

	random_list = {
		15 = {
			save_scope_value_as = {
				name = buddhism_relic_name
				value = flag:tooth
			}
		}
		15 = {
			save_scope_value_as = {
				name = buddhism_relic_name
				value = flag:bone
			}
		}
		10 = {
			save_scope_value_as = {
				name = buddhism_relic_name
				value = flag:robe
			}
		}
		5 = {
			save_scope_value_as = {
				name = buddhism_relic_name
				value = flag:bowl
			}
		}
		5 = {
			save_scope_value_as = {
				name = buddhism_relic_name
				value = flag:tongue
			}
		}
		10 = {
			save_scope_value_as = {
				name = buddhism_relic_name
				value = flag:hair
			}
		}
		25 = {
			save_scope_value_as = {
				name = buddhism_relic_name
				value = flag:sarira
			}
		}
		15 = {
			save_scope_value_as = {
				name = buddhism_relic_name
				value = flag:bo
			}
		}
	}

	get_artifact_quality_effect = yes
	get_artifact_wealth_effect = yes

	scope:owner = {
		create_artifact = {	
			name = artifact_pedestal_reliquary_buddhism_name
			creator = scope:owner
			description = artifact_pedestal_reliquary_buddhism_description
			visuals = reliquary
			type = pedestal
			template = buddhism_relic_template
			modifier = artifact_monthly_piety_3_modifier
			save_scope_as = newly_created_artifact
			wealth = scope:wealth
			quality = scope:quality
			#decaying = no
		}
	}

	scope:newly_created_artifact = {
		add_scaled_artifact_modifier_piety_effect = yes
		add_scaled_artifact_modifier_devotion_effect = yes
		add_scaled_artifact_modifier_grandeur_small_effect = yes
		set_variable = {
			name = relic
			value = flag:buddhism
		}
	}
}

create_artifact_pedestal_reliquary_judaism_effect = {
	$OWNER$ = { save_scope_as = owner }

	random_list = {
		15 = {
			save_scope_value_as = {
				name = judaism_relic_name
				value = flag:menorah
			}
		}
	}

	get_artifact_quality_effect = yes
	get_artifact_wealth_effect = yes

	scope:owner = {
		create_artifact = {	
			name = artifact_pedestal_reliquary_judaism_name
			creator = scope:owner
			description = artifact_pedestal_reliquary_judaism_description
			visuals = reliquary
			type = pedestal
			template = judaism_relic_template
			modifier = artifact_monthly_piety_3_modifier
			save_scope_as = newly_created_artifact
			wealth = scope:wealth
			quality = scope:quality
			#decaying = no
		}
	}

	scope:newly_created_artifact = {
		add_scaled_artifact_modifier_piety_effect = yes
		add_scaled_artifact_modifier_devotion_effect = yes
		add_scaled_artifact_modifier_grandeur_small_effect = yes
		save_scope_as = epic
		set_variable = {
			name = relic
			value = flag:judaism
		}
	}
}

create_artifact_pedestal_reliquary_fracture_effect = {
	$OWNER$ = { save_scope_as = owner }

	random_list = {
		15 = {
			save_scope_value_as = {
				name = fracture_relic_name
				value = flag:amethyst
			}
		}
	}

	get_artifact_quality_effect = yes
	get_artifact_wealth_effect = yes

	scope:owner = {
		create_artifact = {	
			name = artifact_pedestal_reliquary_fracture_name
			creator = scope:owner
			description = artifact_pedestal_reliquary_fracture_description
			visuals = reliquary
			type = pedestal
			template = fracture_relic_template
			modifier = artifact_monthly_piety_3_modifier
			save_scope_as = newly_created_artifact
			wealth = scope:wealth
			quality = scope:quality
			#decaying = no
		}
	}

	scope:newly_created_artifact = {
		add_scaled_artifact_modifier_piety_effect = yes
		add_scaled_artifact_modifier_devotion_effect = yes
		add_scaled_artifact_modifier_grandeur_small_effect = yes
		save_scope_as = epic
		set_variable = {
			name = relic
			value = flag:fracture
		}
	}
}

create_artifact_sculpture_religious_effect = {
	$OWNER$ = { save_scope_as = owner }

	get_artifact_quality_effect = yes
	get_artifact_wealth_effect = yes

	scope:owner = {
		create_artifact = {
			name = artifact_sculpture_religious_name
			description = artifact_sculpture_religious_description
			creator = scope:owner
			visuals = statue
			type = sculpture
			template = religious_statue_template
			modifier = artifact_monthly_piety_3_modifier
			save_scope_as = newly_created_artifact
			wealth = scope:wealth
			quality = scope:quality
		}
	}

	scope:newly_created_artifact = {
		set_variable = { # required to track equipability in template (based on dynamic religion)
			name = statue_religion
			value = scope:owner.religion
		}
		add_scaled_artifact_modifier_piety_effect = yes
		add_scaled_artifact_modifier_devotion_effect = yes
		add_scaled_artifact_modifier_grandeur_small_effect = yes
	}
}

create_artifact_sculpture_religious_christian_effect = {
	$OWNER$ = { save_scope_as = owner }

	get_artifact_quality_effect = yes
	get_artifact_wealth_effect = yes

	scope:owner = {
		create_artifact = {
			name = artifact_sculpture_religious_christian_name
			description = artifact_sculpture_religious_christian_description
			visuals = statue
			creator = scope:owner
			type = sculpture
			template = christian_relic_template
			modifier = artifact_monthly_piety_3_modifier
			save_scope_as = newly_created_artifact
			wealth = scope:wealth
			quality = scope:quality
		}
	}

	scope:newly_created_artifact = {
		add_scaled_artifact_modifier_piety_effect = yes
		add_scaled_artifact_modifier_devotion_effect = yes
		add_scaled_artifact_modifier_grandeur_small_effect = yes
	}
}



# ALCHEMY

# Panacea
create_artifact_panacea_effect = {
	# Get the character the artifact is being made for.
	$OWNER$ = { save_scope_as = owner }
	$ALCHEMIST$ = { save_scope_as = alchemist }
	hidden_effect_new_object = {
		# Get artifact quality, wealth, and materials
		get_artifact_quality_effect = yes
		get_artifact_wealth_effect = yes
		if = { #If we have set the location we use it for the materials
			limit = { exists = scope:location }
			scope:location = { add_to_list = artifact_material_sources }
		}

		scope:owner = {
			# Create the artifact
			create_artifact = {
				name = artifact_panacea_name
				description = placeholder
				creator = scope:alchemist
				visuals = small_box
				type = panacea
				modifier = artifact_negate_health_penalty_add_1_modifier
				wealth = scope:wealth
				quality = scope:quality
				save_scope_as = newly_created_artifact
			}
		}

		scope:newly_created_artifact = {
			get_artifact_feature_references_effect = yes
			set_artifact_description = artifact_panacea_description

			if = {
				limit = {
					rarity = illustrious
				}
				add_artifact_modifier = artifact_negate_health_penalty_add_4_modifier
			}
			else_if = {
				limit = {
					rarity = famed
				}
				add_artifact_modifier = artifact_negate_health_penalty_add_3_modifier
			}
			else_if = {
				limit = {
					rarity = masterwork
				}
				add_artifact_modifier = artifact_negate_health_penalty_add_2_modifier
			} 
			else_if = {
				limit = {
					rarity = common
				}
				add_artifact_modifier = artifact_negate_health_penalty_add_1_modifier
			}
			add_scaled_artifact_modifier_prestige_effect = yes
		}
	}
}


# Elixir
create_artifact_elixir_effect = {
	# Get the character the artifact is being made for.
	$OWNER$ = { save_scope_as = owner }
	$ALCHEMIST$ = { save_scope_as = alchemist }
	hidden_effect_new_object = {
		# Get artifact quality, wealth, and materials
		get_artifact_quality_effect = yes
		get_artifact_wealth_effect = yes

		scope:owner = {
			create_artifact = {
				name = placeholder
				description = placeholder
				creator = scope:alchemist
				visuals = flask
				type = elixir
				modifier = artifact_monthly_learning_lifestyle_xp_1_modifier
				wealth = scope:wealth
				quality = scope:quality
				save_scope_as = newly_created_artifact
			}
		}

		scope:newly_created_artifact = {
			get_artifact_feature_references_effect = yes
			set_artifact_feature_group = elixir_type
			set_artifact_name = artifact_elixir_name
			set_artifact_description = artifact_elixir_description

			if = { # Strong health bonus for elixir of immortality
				limit = {
					has_artifact_feature = elixir_immortality
				}
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_health_gain_4_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_health_gain_3_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_health_gain_2_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_health_penalty_1_modifier
				}
			}
			else_if = { # Fertility bonus for elixir of youth
				limit = {
					has_artifact_feature = elixir_youth
				}
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_fertility_gain_4_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_fertility_gain_3_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_fertility_gain_2_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_fertility_negative_modifier
				}
			}
			else = { # Otherwise you get a small health boost
				if = {
					limit = {
						rarity = illustrious
					}
					add_artifact_modifier = artifact_health_gain_2_modifier
				}
				else_if = {
					limit = {
						rarity = famed
					}
					add_artifact_modifier = artifact_health_gain_2_modifier
				}
				else_if = {
					limit = {
						rarity = masterwork
					}
					add_artifact_modifier = artifact_health_gain_1_modifier
				} 
				else_if = {
					limit = {
						rarity = common
					}
					add_artifact_modifier = artifact_health_gain_1_modifier
				}
			}
			# Rarity determines prestige
			add_scaled_artifact_modifier_minor_prestige_effect = yes

			set_variable = {
				name = quality
				value = scope:quality
			}
			set_variable = {
				name = wealth
				value = scope:wealth
			}
		}
	}
}


# Philosopher's Stone
create_artifact_philosophers_stone_effect = {
	# Get the character the artifact is being made for.
	$OWNER$ = { save_scope_as = owner }
	hidden_effect_new_object = {
		# Get artifact quality, wealth, and materials
		get_artifact_quality_effect = yes
		get_artifact_wealth_effect = yes
		if = { #If we have set the location we use it for the materials
			limit = { exists = scope:location }
			scope:location = { add_to_list = artifact_material_sources }
		}

		scope:owner = {
			# Create the artifact
			create_artifact = {
				name = artifact_philosophers_stone_name
				creator = scope:owner
				description = placeholder
				visuals = small_box
				type = philosophers_stone
				modifier = artifact_health_gain_1_modifier
				wealth = scope:wealth
				quality = scope:quality
				save_scope_as = newly_created_artifact
			}
		}

		scope:newly_created_artifact = {
			get_artifact_feature_references_effect = yes
			set_artifact_description = artifact_philosophers_stone_description

			if = {
				limit = {
					rarity = illustrious
				}
				add_artifact_modifier = artifact_health_gain_4_modifier
			}
			else_if = {
				limit = {
					rarity = famed
				}
				add_artifact_modifier = artifact_health_gain_3_modifier
			}
			else_if = {
				limit = {
					rarity = masterwork
				}
				add_artifact_modifier = artifact_health_gain_2_modifier
			} 
			else_if = {
				limit = {
					rarity = common
				}
				add_artifact_modifier = artifact_health_gain_1_modifier
			}
			add_scaled_artifact_modifier_scholarship_effect = yes
			add_scaled_artifact_modifier_prestige_effect = yes
		}
	}
}

create_artifact_poetry_effect = {
	$OWNER$ = { save_scope_as = owner }

	hidden_effect_new_object = {
		get_artifact_quality_effect = yes
		get_artifact_wealth_effect = yes

		scope:owner = {
			create_artifact = {
				name = artifact_poetry_name
				creator = scope:owner
				description = artifact_poetry_description
				visuals = scroll
				type = miscellaneous
				modifier = artifact_monthly_minor_prestige_1_modifier
				save_scope_as = newly_created_artifact
				wealth = scope:wealth
				quality = scope:quality
			}
		}

		scope:newly_created_artifact = {
			add_scaled_artifact_modifier_minor_prestige_effect = yes
			add_scaled_artifact_modifier_majesty_effect = yes
		}
	}
}
