namespace = artifact_create

scripted_effect artifact_give_effect = {

	if = {
		limit = {
			var:artifact_type = 1
		}
		if = {
			limit = { var:artifact_level = 1 }
			random_list = {
				34 = {
					add_artifact = {ARTIFACT = artifact_4}
				}
				33 = {
					add_artifact = {ARTIFACT = artifact_16}
				}
				33 = {
					add_artifact = {ARTIFACT = artifact_20}
				}
			}
		}
		else_if = {
			limit = { var:artifact_level = 2 }
			random_list = {
				34 = {
					add_artifact = {ARTIFACT = artifact_5}
				}
				33 = {
					add_artifact = {ARTIFACT = artifact_17}
				}
				33 = {
					add_artifact = {ARTIFACT = artifact_21}
				}
			}
		}

		else_if = {
			limit = { var:artifact_level = 3 }
			random_list = {
				34 = {
					add_artifact = {ARTIFACT = artifact_6}
				}
				33 = {
					add_artifact = {ARTIFACT = artifact_18}
				}
				33 = {
					add_artifact = {ARTIFACT = artifact_22}
				}
			}
		}

		else_if = {
			limit = { var:artifact_level = 4 }
			random_list = {
				34 = {
					add_artifact = {ARTIFACT = artifact_7}
				}
				33 = {
					add_artifact = {ARTIFACT = artifact_19}
				}
				33 = {
					add_artifact = {ARTIFACT = artifact_23}
				}
			}
		}
	}
	else_if = {
		limit = {
			var:artifact_type = 2
		}
		if = {
			limit = { var:artifact_level = 1 }
			add_artifact = {ARTIFACT = artifact_28}
		}
		else_if = {
			limit = { var:artifact_level = 2 }
			add_artifact = {ARTIFACT = artifact_29}
		}

		else_if = {
			limit = { var:artifact_level = 3 }
			add_artifact = {ARTIFACT = artifact_30}
		}

		else_if = {
			limit = { var:artifact_level = 4 }
			add_artifact = {ARTIFACT = artifact_31}
		}
	}
	else_if = {
		limit = {
			var:artifact_type = 3
		}
		if = {
			limit = { var:artifact_level = 1 }
			add_artifact = {ARTIFACT = artifact_8}
			add_artifact = {ARTIFACT = artifact_12}
			add_artifact = {ARTIFACT = artifact_23}
		}
		else_if = {
			limit = { var:artifact_level = 2 }
			add_artifact = {ARTIFACT = artifact_9}
			add_artifact = {ARTIFACT = artifact_13}
			add_artifact = {ARTIFACT = artifact_24}
		}

		else_if = {
			limit = { var:artifact_level = 3 }
			add_artifact = {ARTIFACT = artifact_10}
			add_artifact = {ARTIFACT = artifact_14}
			add_artifact = {ARTIFACT = artifact_26}
		}

		else_if = {
			limit = { var:artifact_level = 4 }
			add_artifact = {ARTIFACT = artifact_11}
			add_artifact = {ARTIFACT = artifact_15}
			add_artifact = {ARTIFACT = artifact_27}
		}
	}
}

#Inital
artifact_create.0001 = {
	title = artifact_create.0001.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					var:artifact_type = 1
				}
				desc = artifact_create.0001.desc_weapon
			}
			triggered_desc = {
				trigger = {
					var:artifact_type = 2
				}
				desc = artifact_create.0001.desc_crown
			}
			triggered_desc = {
				trigger = {
					var:artifact_type = 3
				}
				desc = artifact_create.0001.desc_jewelry
			}
		}
	}
	theme = stewardship
	type = character_event
	left_portrait = root

	immediate = {
		add_character_flag = making_artifact
	}

	option = {
		#Level 1 artifact
		name = artifact_create.0001.a
		custom_tooltip = artifact_create.0001.a.tt
		remove_short_term_gold = medium_gold_value
		set_variable = {
			name = artifact_target_level
			value = 1
		}
		set_variable = {
			name = artifact_level
			value = 1
		}
		hidden_effect = {
			random_list = {
				2 = {
					trigger_event = {
						id = artifact_create.0002
						months = 12
					}
				}
				2 = {
					trigger_event = {
						id = artifact_create.0003
						months = 12
					}
				}
				3 = {
					trigger_event = {
						id = artifact_create.0004
						months = 12
					}
				}
				3 = {
					trigger_event = {
						id = artifact_create.0005
						months = 12
					}

				}
				30 = {
					trigger_event = {
						id = artifact_create.0006
						months = 12
					}
				}
			}
		}
		
	}

	option = {
		#Level 2 artifact
		name = artifact_create.0001.b
		custom_tooltip = artifact_create.0001.b.tt
		remove_short_term_gold = major_gold_value
		set_variable = {
			name = artifact_target_level
			value = 2
		}
		set_variable = {
			name = artifact_level
			value = 2
		}
		hidden_effect = {
			random_list = {
				2 = {
					trigger_event = {
						id = artifact_create.0002
						months = 12
					}
				}
				2 = {
					trigger_event = {
						id = artifact_create.0003
						months = 12
					}
				}
				3 = {
					trigger_event = {
						id = artifact_create.0004
						months = 12
					}
				}
				3 = {
					trigger_event = {
						id = artifact_create.0005
						months = 12
					}

				}
				30 = {
					trigger_event = {
						id = artifact_create.0006
						months = 12
					}
				}
			}
		}

	}

	option = {
		#Level 3 artifact
		name = artifact_create.0001.c
		custom_tooltip = artifact_create.0001.c.tt
		remove_short_term_gold = massive_gold_value
		set_variable = {
			name = artifact_target_level
			value = 3
		}
		set_variable = {
			name = artifact_level
			value = 3
		}
		hidden_effect = {
			random_list = {
				2 = {
					trigger_event = {
						id = artifact_create.0002
						months = 12
					}
				}
				2 = {
					trigger_event = {
						id = artifact_create.0003
						months = 12
					}
				}
				3 = {
					trigger_event = {
						id = artifact_create.0004
						months = 12
					}
				}
				3 = {
					trigger_event = {
						id = artifact_create.0005
						months = 12
					}

				}
				30 = {
					trigger_event = {
						id = artifact_create.0006
						months = 12
					}
				}
			}
		}
	}
	option = {
		name = artifact_create.0001.d
		remove_character_flag = making_artifact
		add_gold = 100
	}
}

#Creation success event 1 
artifact_create.0002 = {
	title = artifact_create.0002.t
	desc = artifact_create.0002.desc
	theme = stewardship
	type = character_event
	left_portrait = root

	#Continue working
	option = {
		name = artifact_create.0002.a
		remove_short_term_gold = 10
		duel = {
			skill = stewardship
			value =  10
			#Improves artifact level by 1
			10 = {
				trigger = {
					NOT = {
						var:artifact_target_level = 3
					}
				}
				compare_modifier = {
					value = scope:duel_value
				}
				desc =  artifact_create.0002.a.success
				custom_tooltip = artifact_create.improvement.tt
				send_interface_message = {
					type = event_steward_task_good
					title = artifact_create.improvement.t
					desc = artifact_create.improvement.desc
					left_icon =  root
					
				}
				change_variable = {
						name = artifact_level
						add = 1
				}
				trigger_event = {
					id = artifact_create.0006
					months = 12
				}
			}
			#Failure
			10 = {
				desc = artifact_create.0002.a.failure
				trigger_event = {
					id = artifact_create.0006
					months = 12
				}
			}
			#Gives option to go to tier 4
			5 = {
				desc = artifact_create.0002.a.greatsuccess
				trigger = {
					var:artifact_target_level = 3
				}
				compare_modifier = {
					value = scope:duel_value
				}
				trigger_event = {
					id = artifact_create.0007
					months = 12
				}
			}
		}
	}
	#Stop we are fine
	option = {
		name = artifact_create.0002.b
		trigger_event = {
			id = artifact_create.0006
			months = 12
		}

	}
}

#artifact success event 2
artifact_create.0003 = {
	title = artifact_create.0003.t
	desc = artifact_create.0003.desc
	type = character_event
	theme = realm
	left_portrait = root

	#prowess challenge
	option = {
		name = artifact_create.0003.a
		remove_short_term_gold = 10
		duel = {
			skill = prowess
			value = 12

			10 = {
				trigger = {NOT = { var:artifact_target_level = 3} }
				compare_modifier = {
					value = scope:duel_value
				}
				desc = artifact_create.0003.a.success
				custom_tooltip = artifact_create.improvement.tt
				send_interface_message = {
					type = event_steward_task_good
					title = artifact_create.improvement.t
					desc = artifact_create.improvement.desc
					left_icon =  root

				}
				change_variable = {
					name = artifact_level
					add = 1
				}
				trigger_event = {
					id = artifact_create.0006
					months = 12
				}
			}

			10 = {
				desc = artifact_create.0003.a.failure
				trigger_event = {
					id = artifact_create.0006
					months = 12
				}
			}

			#To go even further beyond
			#Rare chance to set target artifact level to 4
			5 = {
				trigger = { var:artifact_target_level = 3 }
				compare_modifier = {
					value = scope:duel_value
				}
				desc = artifact_create.0003.a.greatsuccess
				trigger_event = {
					id = artifact_create.0007
					months = 12
				}
			}
		}
	}

	#Lets not
	option = {
		name = artifact_create.0003.b
		trigger_event = {
			id = artifact_create.0006
			months = 12
		}
	}
}

#Creation failure event 1
artifact_create.0004 = {
	title = artifact_create.0004.t
	desc = artifact_create.0004.desc
	theme = stewardship
	type = character_event
	left_portrait = root

	option = {
		name = artifact_create.0004.a
		remove_short_term_gold = medium_gold_value
		duel = {
			skill = stewardship
			value = 10

			10 = {
				compare_modifier = {
					value = scope:duel_value
				}
				desc = artifact_create.0004.a.success
				trigger_event = {
					id = artifact_create.0006
					months = 12

				}
			}

			10 = {
				desc = artifact_create.0004.a.failure
				custom_tooltip = artifact_create.degrade.tt
				send_interface_message = {
					title = artifact_create.degrade.t
					type = event_steward_task_bad
					desc = artifact_create.degrade.desc

					left_icon = root
				}
				change_variable = {
					name = artifact_level
					add = -1
				}
				trigger_event = {
					
					id = artifact_create.0006
					months = 12

				}
				
			}
		}	
	}
	option = {#i'd rather not try and salvage this
		name = artifact_create.0004.b
		#cleanup
		remove_character_flag = making_artifact
		remove_variable = artifact_target_level
		remove_variable = artifact_level
	}
}

#Failure event 2 raw chance
artifact_create.0005 = {
	title = artifact_create.0005.t
	type = character_event
	theme = stewardship
	desc = artifact_create.0005.desc
	left_portrait = root

	option = {
		name = artifact_create.0005.a
		remove_short_term_gold = medium_gold_value
		random_list = {

			20 = {
				desc = artifact_create.0005.a.success
				trigger_event = {
					id = artifact_create.0006
					months = 12
				}
			}

			10 = {
				desc = artifact_create.0005.a.failure
				custom_tooltip = artifact_create.degrade.tt
				send_interface_message = {
					title = artifact_create.degrade.t
					type = event_steward_task_bad
					desc = artifact_create.degrade.desc
					
					left_icon = root
				}
				change_variable = {
					name = artifact_level
					add = -1
				}
				trigger_event = {
					id = artifact_create.0006
					months = 12
				}
				
			}
		}
	}

	option = {#i'd rather not try and salvage this
		name = artifact_create.0005.b
		#cleanup
		remove_character_flag = making_artifact
		remove_variable = artifact_target_level
		remove_variable = artifact_level
	}
}

#Sees if you improved, moves on to finish event
artifact_create.0006 = {
	title = artifact_create.0006.t
	type = character_event
	theme = stewardship
	left_portrait = root

	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					var:artifact_level = { compare_value > var:artifact_target_level }
				}
				desc = artifact_create.0006.improve.desc
			}
			triggered_desc = {
				trigger = {
					var:artifact_level = { compare_value < var:artifact_target_level }
				}
				desc = artifact_create.0006.degrade.desc
			}
			#Didnt improve or degrade
			desc = artifact_create.0006.fallback.desc
		}
	}


	#move on to finish option for standard
	option = {
		trigger = { var:artifact_level = { compare_value >= var:artifact_target_level } }
		name = artifact_create.0006.a
		trigger_event = {
			id = artifact_create.0009
			months = 12
		}
	}
	#move on to finish, text for degraded
	option = {
		name = artifact_create.0006.b
		trigger = { var:artifact_level = { compare_value < var:artifact_target_level } }
		trigger_event = {
			id = artifact_create.0009
			months = 12
		}
	}
}

#Chance to improve past tier 3
artifact_create.0007 = {
	title = artifact_create.0007.t
	type = character_event
	desc = artifact_create.0007.desc
	theme = stewardship
	left_portrait = root

	#Goes forward to tier 4 
	option = {
		name = artifact_create.0007.a
		custom_tooltip = artifact_create.0007.a.tt
		send_interface_message = {
			type = event_steward_task_good
			title = artifact_create.improvement.t
			desc = artifact_create.improvement.desc
			left_icon = root
		}
		remove_short_term_gold = 100
		change_variable = {
			name = artifact_level
			add = 1

		}
		trigger_event = {
			id = artifact_create.0006
			months = 12
		}

	}
	#Decides to stay at tier 3		
	option = {
		name = artifact_create.0007.b
		trigger_event = {
			id = artifact_create.0006
			months = 12
		}
		
	}
}

#Checks what kind of artifact you want
artifact_create.0008 = {
	title = artifact_create.0008.t
	desc = artifact_create.0008.desc
	theme = stewardship
	type = character_event
	left_portrait = root

	immediate = {
		set_variable = {
			name = artifact_type
			value = 0
		}
	}

	option = {
		# Weapon
		name = artifact_create.0008.a
		custom_tooltip = artifact_create.0008.a.tt
		set_variable = {
			name = artifact_type
			value = 1
		}
		trigger_event = {
			id = artifact_create.0001
			days = 2
		}
	}

	option = {
		# Armor
		name = artifact_create.0008.b
		custom_tooltip = artifact_create.0008.b.tt
		set_variable = {
			name = artifact_type
			value = 2
		}
		trigger_event = {
			id = artifact_create.0001
			days = 2
		}
	}

	option = {
		# Jewelry
		name = artifact_create.0008.c
		custom_tooltip = artifact_create.0008.c.tt
		set_variable = {
			name = artifact_type
			value = 3
		}
		trigger_event = {
			id = artifact_create.0001
			days = 2
		}
	}
	
	option = {
		# I'll pass
		name = artifact_create.0008.d
		remove_character_flag = making_artifact
		remove_variable = artifact_target_level
		remove_variable = artifact_level
	}

}

#Finish event
artifact_create.0009 = {
	title = artifact_create.0009.t
	type = character_event
	theme = stewardship
	left_portrait = root
	desc = artifact_create.0009.desc


	#Artifact done, here you go
	option = {
		trigger = { var:artifact_level = { compare_value >= var:artifact_target_level } }
		name = artifact_create.0009.a
		custom_tooltip = artifact_create.0009.a.tt
		hidden_effect = {
			artifact_give_effect = yes
			add_character_flag = {
				flag = made_artifact
				months = 60
			}
		}
		#cleanup
		remove_character_flag = making_artifact
		remove_variable = artifact_target_level
		remove_variable = artifact_level
	}

	#Artifact worse then you expected
	option = {
		trigger = { var:artifact_level = { compare_value < var:artifact_target_level } }
		name = artifact_create.0009.b
		custom_tooltip = artifact_create.0009.a.tt
		hidden_effect = {
			artifact_give_effect = yes
			add_character_flag = {
				flag = made_artifact
				months = 60
			}
		}
		#cleanup
		remove_character_flag = making_artifact
		remove_variable = artifact_target_level
		remove_variable = artifact_level

	}
	#No artifact, degraded to 0
	option = {
		trigger = { var:artifact_level = 0 }
		name = artifact_create.0009.c
		#cleanup
		remove_character_flag = making_artifact
		remove_variable = artifact_target_level
		remove_variable = artifact_level

	}
}
