﻿at_can_interact_with_trigger = {
	NOT = { this = $PARTY$ }
	in_diplomatic_range = $PARTY$
	NOT = { is_at_war_with = $PARTY$ }
	is_imprisoned = no

	# Non-humans can't be targeted by interactions
	is_human = yes

	# The AGOT merchant can't be targeted by interactions
	trigger_if = {
		limit = {
			exists = scope:actor
			exists = global_var:agot_artifact_keeper
		}
		custom_description = {
			text = "at_agot_cant_interact_with_merchant_tt"
			NOT = { this = global_var:agot_artifact_keeper }
		}
	}

	# Wildlings can only interact with wildlings, and vice versa
	trigger_if = {
		limit = {
			culture = { agot_is_wildling_culture = yes }
		}
		custom_description = {
			text = "at_agot_wildlings_cant_interact_with_non_wildlings_tt"
			$PARTY$ = {
				culture = { agot_is_wildling_culture = yes }
			}
		}
	}
	trigger_else = {
		custom_description = {
			text = "at_agot_non_wildlings_cant_interact_with_wildlings_tt"
			$PARTY$ = {
				culture = { agot_is_wildling_culture = no }
			}
		}
	}
}

at_can_start_interaction_trigger = {
	is_imprisoned = no

	# Non-humans can't be initiate interactions
	is_human = yes

	# The AGOT merchant can't initiate interactions
	trigger_if = {
		limit = {
			exists = scope:actor
			exists = global_var:agot_artifact_keeper
		}
		NOT = { this = global_var:agot_artifact_keeper }
	}
}

at_can_own_artifacts_trigger = {
	is_human = yes
}

at_has_artifact_relic_flag_religion_trigger = {
	exists = $ARTIFACT$
	always = no
}

# TODO Move to AGOT
at_artifact_can_be_sold_trigger = {
	trigger_if = {
		limit = {
			artifact_owner = { is_ai = yes }
		}
		# AI sellers are not allowed to sell special AGOT artifacts
		NOR = {
			agot_is_unique_throne_artifact = yes
			agot_is_historical_unique_artifact = yes
			agot_is_valyrian_steel_artifact = yes
			agot_is_dragon_egg_artifact = yes
			agot_is_dragon_skull_artifact = yes
		}
	}
	trigger_else = {
		# Player sellers are not allowed to sell unique AGOT thrones
		NOR = {
			agot_is_unique_throne_artifact = yes
			has_variable = agot_artifact_cannot_gift
			trigger_if = {
				limit = {
					has_variable = dragon_egg
				}
				NOT = {
					has_variable = dud_egg
				}
			}
		}
	}
}

at_artifact_can_be_bought_by_trigger = {
	trigger_if = {
		limit = {
			exists = global_var:agot_artifact_keeper
			$BUYER$ = global_var:agot_artifact_keeper
		}
		# The merchant won't buy unwanted, cursed, and worthless artifacts
		# and also not banners
		NOR = {
			has_variable = unwanted_artifact
			has_variable = cursed_artifact
			at_is_worthless_artifact_trigger = yes
			has_variable = banner_dynasty
			has_variable = banner_house
		}
		trigger_if = {
			limit = {
				artifact_owner = { is_ai = yes }
			}
			# The merchant will only buy certain artifact types from AI sellers if under certain quantity
			trigger_if = {
				limit = {
					OR = {
						artifact_type = animal_hide
						artifact_type = animal_hide_big
						artifact_type = miscellaneous
					}
				}
				$BUYER$ = {
					any_character_artifact = {
						OR = {
							artifact_type = animal_hide
							artifact_type = animal_hide_big
							artifact_type = miscellaneous
						}
						count < 6
					}
				}
			}
			# The merchant will only buy common and masterwork artifacts from AI sellers if under certain quantity
			trigger_if = {
				limit = {
					OR = {
						rarity = common
						rarity = masterwork
					}
				}
				$BUYER$ = {
					any_character_artifact = {
						OR = {
							rarity = common
							rarity = masterwork
						}
						count < 9
					}
				}
			}
		}
	}
}

at_artifact_can_be_destroyed_trigger = {
	# Destroying special AGOT artifacts is not allowed
	NOR = {
		agot_is_unique_throne_artifact = yes
		agot_is_historical_unique_artifact = yes
		agot_is_valyrian_steel_artifact = yes
		agot_is_dragon_egg_artifact = yes
		has_variable = maesterwork
	}
}
