### Commission Artifact ###
commission_artifact_decision = {
	picture = {
		trigger = { culture = { has_graphical_east_asia_culture_group_trigger = yes } }
		reference = "gfx/interface/illustrations/decisions/tgp_retire.dds"
	}
	picture = {
		trigger = { government_has_flag = government_is_nomadic }
		reference = "gfx/interface/illustrations/event_scenes/mpo_hunt_steppe.dds"
	}
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_smith.dds"
	}
	cooldown = { days = standard_commission_artifact_cooldown_time }
	sort_order = 100
	
	is_shown = {
		is_landed_or_landless_administrative = yes
		highest_held_title_tier >= tier_county
		exists = capital_province
	}
	
	is_valid_showing_failures_only = {
		# Only valid for characters with an antiquarian.
		employs_court_position = antiquarian_court_position
		trigger_if = {
			limit = {
				government_has_flag = government_is_nomadic
			}
			custom_tooltip = {
				text = commission_artifact_decision.nomad_requirements
				NOR = {
					has_character_modifier = mpo_artifact_material_modifier
					culture ?= {
						has_cultural_parameter = nomadic_metal_artifact_unlock
					}
				}			
			}
		}
	}

	minimum_cost = {
		# Matches the cost defined in 00_inspirations.txt
		gold = {
			value = basic_fund_inspiration_cost
			if = {
				limit = { # Estate discount bonus
					domicile ?= { has_domicile_parameter = estate_reduce_commission_artifact_cost }
				}
				multiply = estate_reduce_commission_artifact_cost_value
			}
			else_if = {
				limit = {
					scope:commission_weapon ?= yes
					domicile ?= { has_domicile_parameter = cheaper_commission_weapon_artifact_parameter_1 }
				}
				multiply = estate_reduce_commission_artifact_cost_value
			}
			else_if = {
				limit = {
					scope:commission_armor ?= yes
					domicile ?= { has_domicile_parameter = cheaper_commission_armor_artifact_parameter_1 }
				}
				multiply = estate_reduce_commission_artifact_cost_value
			}
			else_if = {
				limit = {
					scope:commission_furniture ?= yes
					domicile ?= { has_domicile_parameter = cheaper_commission_furniture_artifact_parameter_1 }
				}
				multiply = estate_reduce_commission_artifact_cost_value
			}
			if = {
				limit = {
					confederation ?= { has_cohesion_level_parameter = any_member_commission_and_inspiration_reduced }
				}
				multiply = {
					value = 0.9
					desc = CB_COHESION_PARAMETER_DISCOUNT
				}
			}
			if = {
				limit = {
					has_character_modifier = mpo_artifact_material_modifier
				}
				multiply = 0
			}
		}
	}

    widget = {
    	gui = "decision_view_widget_commission_artifact"
		controller = decision_option_list_controller
		decision_to_second_step_button = "COMMISSION_ARTIFACT_DECISION_NEXT_STEP_BUTTON" 

		# Commission a Kris
		item = {
			value = commission_kris
			current_description = {
				desc = commission_artifact_decision_option_kris_desc
			}
			localization  = {
				desc = commission_artifact_decision_option_kris
			}
			icon = "gfx/interface/icons/artifact/kris.dds"

			is_shown = {
				culture = {
					has_cultural_parameter = may_commission_kris
				}
			}

			ai_chance = {
				value = 0 
				if = {
					limit = {
						# Only make this choice if we don't already have an artifact of this type.
						NOT = {
							any_character_artifact = {
								has_variable = is_kris
							}
						}
					}
					add = 5000
				}
			}
		}

		# Personal Artifacts are always valid to commission
		item = {
			value = commission_weapon
			current_description = {
				desc = commission_artifact_decision_option_weapon_desc
			}
			localization  = {
				desc = commission_artifact_decision_option_weapon
			}
			icon = "gfx/interface/icons/artifact/artifact_sword.dds"

			ai_chance = {
				value = 0 
				if = {
					limit = {
						# Only make this choice if we don't already have an artifact of this type.
						NOT = {
							any_character_artifact = {
								artifact_slot_type = primary_armament
							}
						}
					}
					add = 100
				}
			}
		}

		item = {
			value = commission_armor
			current_description = {
				desc = commission_artifact_decision_option_armor_desc
			}
			localization = {
				desc = commission_artifact_decision_option_armor
			}
			icon = "gfx/interface/icons/artifact/artifact_armor.dds"

			ai_chance = {
				value = 0 
				if = {
					limit = {
						# Only make this choice if we don't already have an artifact of this type.
						NOT = {
							any_character_artifact = {
								artifact_slot_type = armor
							}
						}
					}
					add = 100
				}
			}
		}

		item = {
			value = commission_crown
			current_description = {
				desc = commission_artifact_decision_option_crown_desc
			}
			localization = {
				desc = commission_artifact_decision_option_crown
			}
			icon = "gfx/interface/icons/artifact/artifact_crown.dds"

			ai_chance = {
				value = 0 
				if = {
					limit = {
						# Only make this choice if we don't already have an artifact of this type.
						NOT = {
							any_character_artifact = {
								artifact_slot_type = helmet
							}
						}
					}
					add = 100
				}
			}
		}

		item = {
			value = commission_regalia
			current_description = {
				desc = commission_artifact_decision_option_regalia_desc
			}
			localization = {
				desc = commission_artifact_decision_option_regalia
			}
			icon = "gfx/interface/icons/artifact/artifact_regalia.dds"

			is_valid = {
				trigger_if = {
					limit = {
						government_has_flag = government_is_nomadic
					}
					custom_tooltip = {
						text = commission_artifact_decision.nomad_requirements
						NOT = {
							has_character_modifier = mpo_artifact_material_modifier
						}			
					}
				}
			}

			ai_chance = {
				value = 0 
				if = {
					limit = {
						# Only make this choice if we don't already have an artifact of this type.
						NOT = {
							any_character_artifact = {
								artifact_slot_type = regalia
							}
						}
					}
					add = 100
				}
			}
		}

		# Court Artifacts only appear if you have the Royal Court DLC, and are only valid if you have an active Royal Court
		
		item = {
			value = commission_tapestry
			is_shown = { has_dlc_feature = royal_court }
			is_valid = {
				has_royal_court = yes
				trigger_if = {
					limit = {
						government_has_flag = government_is_nomadic
					}
					custom_tooltip = {
						text = commission_artifact_decision.nomad_requirements
						NOT = {
							has_character_modifier = mpo_artifact_material_modifier
						}
					}			
				}
			}
			current_description = {
				desc = commission_artifact_decision_option_tapestry_desc
			}

			localization = {
				desc = commission_artifact_decision_option_tapestry
			}
			icon = "gfx/interface/icons/artifact/artifact_tapestry.dds"

			ai_chance = {
				value = 0 
				if = {
					limit = {
						has_royal_court = yes
						has_dlc_feature = court_artifacts
						# Only make this choice if we don't already have an artifact of this type.
						NOR = {
							any_character_artifact = {
								artifact_slot_type = wall_big
							}
							any_character_artifact = {
								artifact_slot_type = wall_small
							}
						}
					}
					add = 100
				}
			}
		}

		item = {
			value = commission_furniture
			is_shown = { has_dlc_feature = royal_court  }
			is_valid = {
				has_royal_court = yes
				trigger_if = {
					limit = {
						government_has_flag = government_is_nomadic
					}
					custom_tooltip = {
						text = commission_artifact_decision.nomad_requirements
						NOT = {
							has_character_modifier = mpo_artifact_material_modifier
						}			
					}
				}
			}
			current_description = {
				desc = commission_artifact_decision_option_furniture_desc
			}

			localization = {
				desc = commission_artifact_decision_option_furniture
			}
			icon = "gfx/interface/icons/artifact/artifact_cabinet.dds"

			ai_chance = {
				value = 0 
				if = {
					limit = {
						has_royal_court = yes
						has_dlc_feature = court_artifacts
						# Only make this choice if we don't already have an artifact of this type.
						NOT = {
							any_character_artifact = {
								artifact_slot_type = sculpture
							}
						}
					}
					add = 100
				}
			}
		}

		item = {
			value = commission_book
			is_shown = { has_dlc_feature = royal_court  }
			is_valid = {
				has_royal_court = yes
				trigger_if = {
					limit = {
						government_has_flag = government_is_nomadic
					}
					custom_tooltip = {
						text = commission_artifact_decision.nomad_requirements
						NOT = {
							has_character_modifier = mpo_artifact_material_modifier
						}			
					}
				}
			}
			current_description = {
				desc = commission_artifact_decision_option_book_desc
			}
			localization = {
				desc = commission_artifact_decision_option_book
			}
			icon = "gfx/interface/icons/artifact/artifact_book.dds"

			ai_chance = {
				value = 0 
				if = {
					limit = {
						has_royal_court = yes
						has_dlc_feature = court_artifacts
						# Only make this choice if we don't already have an artifact of this type.
						NOT = {
							any_character_artifact = {
								artifact_slot_type = book
							}
						}
					}
					add = 100
				}
			}
		}

		#Alchemy isn't included here since that inspiration is much more tied to the pursuit of knowledge initiated by the inspired person
	}

	effect = {
		if = {
			limit = {
				any_court_position_holder = {
					type = antiquarian_court_position
				}
			}
			random_court_position_holder = {
				type = antiquarian_court_position
				save_scope_as = antiquarian
			}
		}
		# Explanatory Tooltips
		custom_tooltip = commission_artifact_decision_effect
		if = {
			limit = { has_dlc_feature = royal_court }
			custom_description_no_bullet = {
				text = commission_artifact_decision_warning_effect
			}
		}

		if = {
			limit = {
				any_pool_character = {
					province = root.capital_province
					has_no_particular_noble_roots_trigger = yes
					is_available_healthy_ai_adult = yes
					NOR = {
						exists = inspiration
						has_trait = peasant_leader
					}
				}
			}
			random_pool_character = {
				province = root.capital_province
				limit = {
					has_no_particular_noble_roots_trigger = yes
					is_available_healthy_ai_adult = yes
					NOR = {
						exists = inspiration
						has_trait = peasant_leader
					}
				}
				save_scope_as = local_artisan
				hidden_effect = {
					add_character_modifier = local_artisan_modifier
				}
			}
		}
		else = {
			# Artisan Generation
			hidden_effect = {
				create_character = {
					template = local_artisan_template
					location = root.capital_province
					gender_female_chance = root_faith_dominant_gender_adjusted_female_chance
					save_scope_as = local_artisan
				}
				scope:local_artisan = {
					hidden_effect = {
						add_character_modifier = local_artisan_modifier
					}
				}
			}
		}

		hidden_effect = {
			if = {
				# Conditional exists to avoid false-positives during tooltip generation, but 'local_artisan' should always exist on execution!
				limit = { exists = scope:local_artisan }
				root = { add_courtier = scope:local_artisan	}
				scope:local_artisan = {
					add_character_flag = local_artisan
					switch = {
						trigger = yes
						scope:commission_kris = {
							set_variable = {
								name = artifact_weapon_type
								value = flag:artifact_weapon_type_dagger
							}
							set_variable = is_inspiration_for_kris_dagger
							create_inspiration = weapon_inspiration
						}
						scope:commission_weapon = { create_inspiration = weapon_inspiration }
						scope:commission_armor = {
							set_variable = {
								name = force_armor
								value = flag:force_armor_true
							}
							create_inspiration = armor_inspiration
						}
						scope:commission_crown = {
							set_variable = {
								name = artifact_smith_type
								value = flag:smith_type_crown
							}
							create_inspiration = smith_inspiration
						}
						scope:commission_regalia = {
							set_variable = {
								name = artifact_smith_type
								value = flag:smith_type_regalia
							}
							create_inspiration = smith_inspiration
						}
						scope:commission_tapestry = {
							root = { trigger_event = fund_inspiration.0044 }
						}
						scope:commission_furniture = { create_inspiration = artisan_inspiration }
						scope:commission_book = { create_inspiration = book_inspiration }
					}
					if = {
						limit = { exists = inspiration }
						inspiration = { save_scope_as = this_inspiration }
						root = { sponsor_inspiration = scope:this_inspiration }
					}
				}
			}
		}

		#Mandala Creation Aspect
		if = {
			limit = {
				government_has_flag = government_is_mandala
				house = { has_house_aspiration_parameter = aspect_of_creation }
				is_house_head = yes
			}
			increment_variable_effect = {
				VAR = num_commissioned_artifacts
				VAL = 1
			}
		}
	}

	ai_check_interval_by_tier = {
		barony = 0
		county = 36
		duchy = 36
		kingdom = 36
		empire = 36
		hegemony = 36
	}
	
	ai_potential = {
		is_at_war = no
		ai_greed < medium_positive_ai_value
		short_term_gold > ai_war_chest_desired_gold_value
		war_chest_gold >= halved_ai_war_chest_gold_maximum
		NOT = { has_variable = conqueror }
		ai_should_focus_on_building_in_their_capital = no
	}

	ai_will_do = {
		base = 100

		modifier = {
			factor = 0
			has_royal_court = yes
			any_character_artifact = {
				artifact_slot_type = primary_armament
			}
			any_character_artifact = {
				artifact_slot_type = armor
			}
			any_character_artifact = {
				artifact_slot_type = helmet
			}
			any_character_artifact = {
				artifact_slot_type = regalia
			}
			OR = {
				any_character_artifact = {
					artifact_slot_type = wall_big
				}
				any_character_artifact = {
					artifact_slot_type = wall_small
				}
			}
			any_character_artifact = {
				artifact_slot_type = sculpture
			}
			any_character_artifact = {
				artifact_slot_type = book
			}
		}

		modifier = {
			factor = 0
			has_royal_court = no
			any_character_artifact = {
				artifact_slot_type = primary_armament
			}
			any_character_artifact = {
				artifact_slot_type = armor
			}
			any_character_artifact = {
				artifact_slot_type = helmet
			}
			any_character_artifact = {
				artifact_slot_type = regalia
			}
		}
	}
}
