﻿
# Destroy Artifact
destroy_artifact_interaction = {
	interface_priority = 30
	common_interaction = yes
	icon = artifact
	category = interaction_category_friendly
	desc = destroy_artifact_interaction_desc
	icon = artifact

	target_type = artifact
	target_filter = actor_artifacts

	ai_targets = {
		ai_recipients = self
	}

	# You can only destroy your own artifacts
	is_shown = {
		scope:recipient = scope:actor
		scope:actor = {
			has_any_artifact = yes
		}
	}

	can_be_picked_artifact = {
	}

	has_valid_target_showing_failures_only = {
		trigger_if = {
			limit = {
				NOT = {
					scope:recipient.faith = { has_doctrine_parameter = destroying_artifacts_is_pious }
				}
			}
			custom_tooltip = {
				text = artifact_is_rarer_than_masterwork_tt
				OR = {
					scope:target = { rarity = common }
					scope:target = { rarity = masterwork }
				}
			}
		}
		trigger_if = {
			limit = {
				NOR = {
					scope:target = { rarity = common }
					scope:target = { rarity = masterwork }
				}
			}
			custom_tooltip = {
				text = destroying_artifacts_is_not_pious_tt
				scope:recipient.faith = { has_doctrine_parameter = destroying_artifacts_is_pious }
			}
		}
	}									   
	
	on_accept = {
		destroy_artifact_aniconist_effect = {
			ARTIFACT = scope:target
			DESTROYER = scope:actor
			GIVE_GOLD = yes
			PIETY_BY_DEFAULT = no
		}
	}

	ai_frequency = 24

	ai_potential = {
		OR = {
			faith = { # Aniconists will always want to destroy artifacts
				has_doctrine_parameter = destroying_artifacts_is_pious
			}
			gold <= minor_gold_value # Poor rulers will consider getting rid of their trash for gold
			AND = { # Economic boom personalities will bolster their treasury by getting rid of trash more often
				gold <= medium_gold_value
				ai_has_economical_boom_personality = yes
			}
			any_character_artifact = { # All rulers want to get rid of actively detrimental trash
				has_variable = unwanted_artifact
			}
		}
	}

	ai_will_do = {
		base = 0
		modifier = { # Rulers will always destroy unwanted artifacts
			add = 100
			scope:target = {
				has_variable = unwanted_artifact
			}
		}
		modifier = { # Rulers will consider destroying trash artifacts if they're poor
			add = 100
			scope:target = {
				has_variable = ai_to_ai_destroy_in_sieges
			}
		}
		modifier = { # AI rulers will destroy common unequipped artifacts if money is low
			add = 100
			OR = {
				gold <= minor_gold_value # Poor rulers will consider getting rid of their trash for gold
				AND = { # Economic boom personalities will bolster their treasury by getting rid of trash more often
					gold <= medium_gold_value
					ai_has_economical_boom_personality = yes
				}
			}
			scope:target = {
				rarity = common
				is_equipped = no
			}
		}
		modifier = { # AI rulers will destroy all unequipped artifacts to get out of debt
			add = 100
			gold <= 0
			scope:target = {
				is_equipped = no
			}
		}
		modifier = { # Common artifact trinkets on their last legs can be considered for destruction if money is low
			add = 100
			OR = {
				gold <= minor_gold_value # Poor rulers will consider getting rid of their trash for gold
				AND = { # Economic boom personalities will bolster their treasury by getting rid of trash more often
					gold <= medium_gold_value
					ai_has_economical_boom_personality = yes
				}
			}
			scope:target = {
				rarity = common
				artifact_slot_type = miscellaneous
				artifact_durability <= define:NInventory|ARTIFACT_LOW_DURABILITY
			}
		}
		modifier = { # Aniconists destroy most things
			add = 100
			faith = {
				has_doctrine_parameter = destroying_artifacts_is_pious
			}
			OR = { # This errors in the ai_potential so it's been moved here
				has_trait = zealous
				scope:target = { is_equipped = no }
				scope:target = { exists = var:relic }
			}
			# The logic below relies on the idea that they have the destroying_artifacts_is_pious doctrine parameter. If the restrictions are loosened, these triggers should be updated
			NOR = {
				has_trait = cynical
				AND = {
					has_trait = greedy
					NOT = { has_trait = zealous }
				}
			}
			OR = {
				has_trait = zealous # Destroy all the artifacts
				any_character_artifact = {
					is_equipped = no
				}
				any_character_artifact = {
					exists = var:relic
				}
			}
		}
		modifier = { # Don't let AI destroy fancy stuff
			add = -1000
			OR = {
				scope:target = { rarity = famed }
				scope:target = { rarity = illustrious }
			}
		}
	}
}
