# Give away an artifact to improve relations
gift_artifact_interaction = {
	category = interaction_category_friendly
	common_interaction = yes
	interface_priority = 60
	desc = gift_artifact_interaction_desc
	icon = artisan_inspiration

	target_type = artifact
	target_filter = actor_artifacts

	greeting = positive
	notification_text = GIFT_ARTIFACT_PROPOSAL

	answer_accept_key = GIFT_ARTIFACT_ACCEPT
	answer_reject_key = GIFT_ARTIFACT_REJECT
	
	ai_targets = {
		ai_recipients = scripted_relations
		ai_recipients = liege
		ai_recipients = spouses
		ai_recipients = vassals
	}
	ai_targets = {
		ai_recipients = neighboring_rulers
		ai_recipients = peer_vassals
		max = 10
	}
	ai_targets = {
		ai_recipients = family
		ai_recipients = children
		ai_recipients = dynasty
		max = 20
	}
	ai_target_quick_trigger = {
		adult = yes
	}
	ai_frequency = 84

	can_be_picked_artifact = {
		trigger_if = {
			limit = {
				scope:actor = {
					is_ai = no
				}
			}
			scope:target = {
				is_equipped = no
			}
		}
		scope:actor = {
			any_character_artifact = {
				this = scope:target
			}
		}
		#Artifacts locked from being giftable by a variable
		scope:target = {
			NOR = {
				has_variable = 1025_treasure_map
				has_variable = ungiftable
			}
		}
	}


	#You can't give yourself a gift, even if it should count as self-care
	is_shown = {
		NOT = {
			scope:recipient = scope:actor
		}
		scope:actor = {
			has_any_artifact = yes
		}
	}

	is_valid_showing_failures_only = {
		# needs to have an artifact to give away
		scope:recipient = { is_busy_in_events_localised = yes }
		scope:actor = {
			NOT = {
				is_at_war_with = scope:recipient
			}
			is_imprisoned = no
			trigger_if = {
				limit = {
					is_ai = no
				}
				custom_description = {
					text = "any_unequipped_artifact_tt"
					any_character_artifact = {
						is_equipped = no
					}
				}
			}
		}
		trigger_if = {
			limit = {
				exists = scope:target.var:banner_dynasty
				exists = scope:recipient.dynasty
			}
			custom_description = {
				text = "gift_artifact_dynasty_banner_head_tt"
				scope:recipient = scope:target.var:banner_dynasty.dynast
			}
		}
	}

	on_accept = {
		# Warning for multiple gifts
		if = {
			limit = {
				scope:recipient = {
					has_opinion_modifier = {
						target = scope:actor
						modifier = gift_artifact_opinion
					}
				}
			}
			custom_tooltip = ALREADY_SENT_GIFT_WARNING
		}
		# Struggle Catalyst
		if = { # Struggle Catalyst
			limit = {
				scope:actor = {
					any_character_struggle = {
						involvement = involved
						activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
							CATALYST = catalyst_gift_independent_ruler
							CHAR = scope:recipient
						}
					}
				}
			}
			hidden_effect = {
				scope:actor = {
					every_character_struggle = {
						involvement = involved
						activate_struggle_catalyst = {
							catalyst = catalyst_gift_independent_ruler
							character = scope:actor
						}
					}
				}
			}
		}
		else_if = {
			limit = {
				fp3_struggle_involves_one_supporter_and_one_detractor = {
					FIRST = scope:actor
					SECOND = scope:recipient
				}
				scope:actor = {
					any_character_struggle = {
						#involvement = involved
						activate_struggle_catalyst_secondary_character_involvement_either_trigger = {
							CATALYST = catalyst_gift_supporter_detractor_ruler
							CHAR = scope:recipient
						}
					}
				}
			}
			hidden_effect = {
				scope:actor = {
					every_character_struggle = {
						#involvement = involved
						limit = {
							activate_struggle_catalyst_secondary_character_involvement_either_trigger = {
								CATALYST = catalyst_gift_supporter_detractor_ruler
								CHAR = scope:recipient
							}
						}
						activate_struggle_catalyst = {
							catalyst = catalyst_gift_supporter_detractor_ruler
							character = scope:actor
						}
						log_debug_variable_for_persian_struggle_effect = { VAR = concession_catalyst_gift_supporter_detractor_ruler }
					}
				}
			}
		}

		scope:target = {
			set_variable = {
				name = suppress_artifact_notifications
				value = yes
				days = 1
			}
			set_variable = { name = gifted_artifact value = yes days = 9125 }
		}
		scope:recipient = {
			# Verify that they could become friend
			if = {
				limit = {
					NAND = {
						has_relation_friend = scope:actor
						has_relation_lover = scope:actor
						has_relation_soulmate = scope:actor
						has_relation_best_friend = scope:actor
					}
				}
				gifting_leads_towards_friendship_effect = yes
			}
		}
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = gift_artifact_interaction_notification
				left_icon = scope:recipient
				right_icon = scope:target
				scope:recipient = {
					if = {
						limit = { scope:target = { can_be_claimed_by = scope:recipient } }
						if = {
							limit = { any_personal_claimed_artifact = { this = scope:target } }
							show_as_tooltip = { remove_personal_artifact_claim = scope:target }
						}
						else = { show_as_tooltip = { house = { remove_house_artifact_claim = scope:target } } }
					}
				}
				
				scope:target = { set_owner = scope:recipient }

				
				if = {
					limit = {
						scope:target = { is_unique = yes }
					}
					add_clan_unity_interaction_effect = {
						CHARACTER = scope:actor
						TARGET = scope:recipient
						VALUE = medium_unity_gain
						DESC = clan_unity_given_artifact.desc
						REVERSE_NON_HOUSE_TARGET = no
					}
					stress_impact = {
						greedy = major_stress_impact_gain
						generous = major_stress_impact_loss
					}
				}
				else_if = {# Unity goes here, too!
					limit = { scope:target = { rarity = masterwork } }
					add_clan_unity_interaction_effect = {
						CHARACTER = scope:actor
						TARGET = scope:recipient
						VALUE = minor_unity_gain
						DESC = clan_unity_given_artifact.desc
						REVERSE_NON_HOUSE_TARGET = no
					}
					stress_impact = {
						greedy = minor_stress_impact_gain
						generous = minor_stress_impact_loss
					}
				}
				else_if = {
					limit = { scope:target = { rarity = famed } }
					add_clan_unity_interaction_effect = {
						CHARACTER = scope:actor
						TARGET = scope:recipient
						VALUE = minor_unity_gain
						DESC = clan_unity_given_artifact.desc
						REVERSE_NON_HOUSE_TARGET = no
					}
					stress_impact = {
						greedy = medium_stress_impact_gain
						generous = medium_stress_impact_loss
					}
				}
				else_if = {
					limit = { scope:target = { rarity = illustrious } }
					add_clan_unity_interaction_effect = {
						CHARACTER = scope:actor
						TARGET = scope:recipient
						VALUE = minor_unity_gain
						DESC = clan_unity_given_artifact.desc
						REVERSE_NON_HOUSE_TARGET = no
					}
					stress_impact = {
						greedy = major_stress_impact_gain
						generous = major_stress_impact_loss
					}
				}
				if = {
					limit = { scope:recipient = { is_ai = yes } }
					reverse_add_opinion = {
						target = scope:recipient
						modifier = gift_artifact_opinion
						opinion = gift_artifact_opinion
					}
				}
				#FP3 Tenet Communal Possessions Perk - piety gain for gift giving. 
				if = { 
					limit = {
						scope:actor = {
								faith = {
					 			has_doctrine_parameter = piety_from_gifts_active
					 		}
					 	}
					}
					scope:actor = {
						if = {
							limit = { #the better the artifact, the more piety you gain
								scope:target = { rarity = illustrious }
							}
							add_piety = massive_piety_gain 
						}
						else_if = {
							limit = {
								scope:target = { rarity = famed }
							}
							add_piety = major_piety_gain 
						}
						else_if = {
							limit = {
								scope:target = { rarity = masterwork }
							}
							add_piety = medium_piety_gain 
						}
						else = {
							add_piety = minor_piety_gain
						}				 
					}		
				}
			}

			# Warning for low opinion gain
			if = {
				limit = {
					scope:target = { artifact_durability <= define:NInventory|ARTIFACT_LOW_DURABILITY }
				}
				custom_tooltip = artifact_gift_low_durability_tt
			}
			if = {
				limit = {
					scope:target = { artifact_durability <= define:NInventory|ARTIFACT_VERY_LOW_DURABILITY }
				}
				custom_tooltip = artifact_gift_very_low_durability_tt
			}
			if = {
				limit = {
					scope:target = { 
						OR = {
							AND = {
								has_variable = banner_house
								NOT = { var:banner_house = scope:recipient.house }
							}
							AND = {
								has_variable = banner_dynasty
								NOT = { var:banner_dynasty = scope:recipient.dynasty }
							}
						}
					}
				}
				custom_tooltip = artifact_gift_useless_banner_tt
			}
			else_if = {
				limit = {
					scope:recipient = {
						NOR = {
							can_equip_artifact = scope:target
							can_benefit_from_artifact = scope:target
						}
					}
				}
				custom_tooltip = artifact_gift_useless_tt
			}
			else_if = {
				limit = {
					scope:recipient = {
						NOT = { can_equip_artifact = scope:target }
					}
				}
				custom_tooltip = artifact_gift_equip_tt
			}
			else_if = {
				limit = {
					scope:recipient = {
						NOT = { can_benefit_from_artifact = scope:target }
					}
				}
				custom_tooltip = artifact_gift_benefit_tt
			}
			if = {
				limit = { scope:recipient.liege = scope:actor }
				custom_tooltip = artifact_gift_vassal_tt
			}
			if = {
				limit = { scope:recipient = scope:actor.faith.religious_head }
				custom_tooltip = artifact_gift_religious_head_tt
			}
		}
		scope:recipient = {
			hidden_effect = {
				send_interface_toast = {
					type = event_toast_effect_neutral
					title = gift_artifact_interaction_notification
					left_icon = scope:actor
					right_icon = scope:target

					show_as_tooltip = {
						scope:target = { set_owner = scope:recipient }
						if = {
							limit = { is_ai = yes }
							add_opinion = {
								target = scope:actor
								modifier = gift_artifact_opinion
								opinion = gift_artifact_opinion
							}
						}

						# Unity stuff, scales with tier # If we're a clan this interaction affects unity
						if = { # In a better world, this would be a switch
							limit = { scope:target = { rarity = Masterwork } } # todo_cd_polish, make the UI show this before you gift
							add_clan_unity_interaction_effect = {
								CHARACTER = scope:actor
								TARGET = scope:recipient
								VALUE = minor_unity_gain
								DESC = clan_unity_given_artifact.desc
								REVERSE_NON_HOUSE_TARGET = no
							}
						}
						else_if = {
							limit = { scope:target = { rarity = Famed } }
							add_clan_unity_interaction_effect = {
								CHARACTER = scope:actor
								TARGET = scope:recipient
								VALUE = medium_unity_gain
								DESC = clan_unity_given_artifact.desc
								REVERSE_NON_HOUSE_TARGET = no
							}
						}
						else_if = {
							limit = { scope:target = { rarity = Illustrious } }
							add_clan_unity_interaction_effect = {
								CHARACTER = scope:actor
								TARGET = scope:recipient
								VALUE = major_unity_gain
								DESC = clan_unity_given_artifact.desc
								REVERSE_NON_HOUSE_TARGET = no
							}
						}
					}
				}
				if = {
					limit = {
						is_ruler = no
						trigger_if = {
							limit = {
								scope:target = {
									artifact_slot_type = primary_armament
								}
							}
							OR = {
								NOT = {
									any_equipped_character_artifact = {
										artifact_slot_type = primary_armament
									}
								}
								AND = {
									scope:target = {
										rarity = illustrious
									}
									any_equipped_character_artifact = {
										artifact_slot_type = primary_armament
										NOT = {
											rarity = illustrious
										}
									}
								}
								AND = {
									scope:target = {
										rarity = famed
									}
									any_equipped_character_artifact = {
										artifact_slot_type = primary_armament
										NOR = {
											rarity = illustrious
											rarity = famed
										}
									}
								}
								AND = {
									scope:target = {
										rarity = masterwork
									}
									any_equipped_character_artifact = {
										artifact_slot_type = primary_armament
										NOR = {
											rarity = illustrious
											rarity = famed
											rarity = masterwork
										}
									}
								}
								AND = {
									scope:target = {
										rarity = common
									}
									any_equipped_character_artifact = {
										artifact_slot_type = primary_armament
										NOR = {
											rarity = illustrious
											rarity = famed
											rarity = masterwork
											rarity = common
										}
									}
								}
							}
						}
						trigger_if = {
							limit = {
								scope:target = {
									artifact_slot_type = armor
								}
							}
							OR = {
								NOT = {
									any_equipped_character_artifact = {
										artifact_slot_type = armor
									}
								}
								AND = {
									scope:target = {
										rarity = illustrious
									}
									any_equipped_character_artifact = {
										artifact_slot_type = armor
										NOT = {
											rarity = illustrious
										}
									}
								}
								AND = {
									scope:target = {
										rarity = famed
									}
									any_equipped_character_artifact = {
										artifact_slot_type = armor
										NOR = {
											rarity = illustrious
											rarity = famed
										}
									}
								}
								AND = {
									scope:target = {
										rarity = masterwork
									}
									any_equipped_character_artifact = {
										artifact_slot_type = armor
										NOR = {
											rarity = illustrious
											rarity = famed
											rarity = masterwork
										}
									}
								}
								AND = {
									scope:target = {
										rarity = common
									}
									any_equipped_character_artifact = {
										artifact_slot_type = armor
										NOR = {
											rarity = illustrious
											rarity = famed
											rarity = masterwork
											rarity = common
										}
									}
								}
							}
						}
						trigger_if = {
							limit = {
								scope:target = {
									artifact_slot_type = regalia
								}
							}
							OR = {
								NOT = {
									any_equipped_character_artifact = {
										artifact_slot_type = regalia
									}
								}
								AND = {
									scope:target = {
										rarity = illustrious
									}
									any_equipped_character_artifact = {
										artifact_slot_type = regalia
										NOT = {
											rarity = illustrious
										}
									}
								}
								AND = {
									scope:target = {
										rarity = famed
									}
									any_equipped_character_artifact = {
										artifact_slot_type = regalia
										NOR = {
											rarity = illustrious
											rarity = famed
										}
									}
								}
								AND = {
									scope:target = {
										rarity = masterwork
									}
									any_equipped_character_artifact = {
										artifact_slot_type = regalia
										NOR = {
											rarity = illustrious
											rarity = famed
											rarity = masterwork
										}
									}
								}
								AND = {
									scope:target = {
										rarity = common
									}
									any_equipped_character_artifact = {
										artifact_slot_type = regalia
										NOR = {
											rarity = illustrious
											rarity = famed
											rarity = masterwork
											rarity = common
										}
									}
								}
							}
						}
						trigger_if = {
							limit = {
								scope:target = {
									artifact_slot_type = helmet
								}
							}
							OR = {
								NOT = {
									any_equipped_character_artifact = {
										artifact_slot_type = helmet
									}
								}
								AND = {
									scope:target = {
										rarity = illustrious
									}
									any_equipped_character_artifact = {
										artifact_slot_type = helmet
										NOT = {
											rarity = illustrious
										}
									}
								}
								AND = {
									scope:target = {
										rarity = famed
									}
									any_equipped_character_artifact = {
										artifact_slot_type = helmet
										NOR = {
											rarity = illustrious
											rarity = famed
										}
									}
								}
								AND = {
									scope:target = {
										rarity = masterwork
									}
									any_equipped_character_artifact = {
										artifact_slot_type = helmet
										NOR = {
											rarity = illustrious
											rarity = famed
											rarity = masterwork
										}
									}
								}
								AND = {
									scope:target = {
										rarity = common
									}
									any_equipped_character_artifact = {
										artifact_slot_type = helmet
										NOR = {
											rarity = illustrious
											rarity = famed
											rarity = masterwork
											rarity = common
										}
									}
								}
							}
						}
					}
					scope:target = {
						equip_artifact_to_owner_replace = yes
					}
				}
			}
		}
	}

	auto_accept = no
	
	ai_accept = {
		base = 0
		modifier = {
			add = 100
			desc = ARTIFACT_REASON
		}
		modifier = {
			add = -80
			NOT = {
				can_equip_artifact = scope:target
			}
			desc = ARTIFACT_NOT_EQUIPPABLE_REASON
		}
		modifier = {
			add = -40
			NOT = {
				can_benefit_from_artifact = scope:target
			}
			desc = ARTIFACT_NOT_BENEFIT_REASON
		}
		modifier = {
			add = -500
			scope:target = {
				has_variable = unwanted_artifact
			}
			#No harm in reusing the wording
			desc = ARTIFACT_CURSED_REASON
		}
		modifier = {
			add = -1000
			scope:target = {
				has_variable = cursed_artifact
			}
			desc = ARTIFACT_CURSED_REASON
		}
		modifier = {
			add = 100
			exists = scope:target.var:banner_dynasty
			exists = scope:recipient.dynasty
			scope:recipient = scope:target.var:banner_dynasty.dynast
			desc = ARTIFACT_DYNASTY_BANNER_REASON
		}
		modifier = {
			add = -200
			OR = {
				exists = scope:target.var:banner_dynasty
				exists = scope:target.var:banner_house
			}
			exists = scope:recipient.house
			trigger_if = {
				limit = { exists = scope:target.var:banner_dynasty }
				NOT = { scope:target.var:banner_dynasty = scope:recipient.dynasty }
			}
			trigger_else = {
				NOT = { scope:target.var:banner_house = scope:recipient.house }
			}
			desc = ARTIFACT_USELESS_BANNER_REASON
		}
		# Struggle motive
		modifier = {
			desc = AI_STRUGGLE_INTENT
			scope:recipient = {
				is_independent_ruler = yes
				any_character_struggle = {
					involvement = involved
				}
			}
			add = {
				value = 0
				if = {
					limit = {
						scope:recipient = {
							any_character_struggle = {
								phase_has_catalyst = catalyst_gift_independent_ruler
							}
							has_character_flag = agenda_towards_escalation
						}
					}
					add = -100
				}
				else_if = {
					limit = {
						scope:recipient = {
							any_character_struggle = {
								phase_has_catalyst = catalyst_gift_independent_ruler
							}
						}
					}
					add = 200
				}
			}
		}
		# Unity modifiers
		evaluate_action_increasing_house_unity = {
			VALUE = 100
		}
	}
	
	ai_potential = {
		has_any_artifact = yes
		trigger_if = {
			limit = {
				exists = scope:target.var:banner_dynasty
				exists = scope:recipient.dynasty
				scope:recipient = scope:target.var:banner_dynasty.dynast
			}
			NOT = {
				scope:actor = {
					has_any_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
				}
			}
		}
		trigger_else = {
			is_adult = yes
			ai_greed <= high_positive_ai_value
			# the AI shouldn't give away equipped artifacts
			has_any_unequipped_artifact = yes
		
			NOT = {
				has_trait = greedy
			}
		}
	}
	
	ai_min_reply_days = 0
	ai_max_reply_days = 0
	
	ai_will_do = {
		base = 0
		
		modifier = {
			add = 100
			scope:recipient = {
				OR = {
					has_relation_friend = scope:actor
					has_relation_lover = scope:actor
					is_close_or_extended_family_of = scope:actor
					AND = {
						exists = dynasty
						exists = scope:actor.dynasty
						dynasty = scope:actor.dynasty
					}
					
					AND = {
						ai_greed <= low_negative_ai_value
						OR = { # Lieges/vassals, within realm
							is_vassal_of = scope:actor
							target_is_vassal_or_below = scope:actor
						}
						opinion = {
							target = scope:recipient
							value >= medium_positive_opinion
						}
					}
				}
			}
			
			scope:target = {
				is_equipped = no
			}
			
			scope:recipient = {
				OR = {
					AND = { # Players like nice gifts
						scope:target = {
							OR = {
								rarity = famed
								rarity = illustrious
							}
						}
						is_ai = no	
					}
					AND = { # Might as well give Court Artifacts to their liege if they cant use them themselves
						has_royal_court = yes
						has_dlc_feature = court_artifacts
						target_is_vassal_or_below = scope:actor
						scope:actor = {
							has_royal_court = no
						}
						scope:target = {
							OR = {
								artifact_slot_type = throne
								artifact_slot_type = wall_big
								artifact_slot_type = wall_small
								artifact_slot_type = sculpture
								artifact_slot_type = book
								artifact_slot_type = pedestal
							}
						}
					}
					AND = {
						scope:target = {
							artifact_slot_type = primary_armament
						}
						scope:actor = {
							any_equipped_character_artifact = {
								artifact_slot_type = primary_armament
							}
						}
						NOT = {
							any_equipped_character_artifact = {
								artifact_slot_type = primary_armament
							}
						}	
					}
					AND = {
						scope:target = {
							artifact_slot_type = regalia
						}
						scope:actor = {
							any_equipped_character_artifact = {
								artifact_slot_type = regalia
							}
						}
						NOT = {
							any_equipped_character_artifact = {
								artifact_slot_type = regalia
							}
						}	
					}
					AND = {
						scope:target = {
							artifact_slot_type = helmet
						}
						scope:actor = {
							any_equipped_character_artifact = {
								artifact_slot_type = helmet
							}
						}
						NOT = {
							any_equipped_character_artifact = {
								artifact_slot_type = helmet
							}
						}	
					}
					AND = {
						scope:target = {
							artifact_slot_type = armor
						}
						scope:actor = {
							any_equipped_character_artifact = {
								artifact_slot_type = armor
							}
						}
						NOT = {
							any_equipped_character_artifact = {
								artifact_slot_type = armor
							}
						}	
					}
					AND = {
						can_equip_artifact = scope:target # To avoid gifting old children's toys to adults...
						can_benefit_from_artifact = scope:target
						scope:target = {
							artifact_slot_type = miscellaneous
						}
						scope:actor = {
							any_equipped_character_artifact = {
								count >= 4
								artifact_slot_type = miscellaneous
							}
						}
						any_equipped_character_artifact = {
							count < 4
							artifact_slot_type = miscellaneous
						}
					}
					AND = {
						has_royal_court = yes
						scope:target = {
							artifact_slot_type = throne
						}
						scope:actor = {
							OR = {
								has_royal_court = no
								any_equipped_character_artifact = {
									artifact_slot_type = throne
								}
							}
						}
						NOT = {
							any_equipped_character_artifact = {
								artifact_slot_type = throne
							}
						}	
					}
					AND = {
						has_royal_court = yes
						scope:target = {
							artifact_slot_type = wall_big
						}
						scope:actor = {
							OR = {
								has_royal_court = no
								any_equipped_character_artifact = {
									count >= 3
									artifact_slot_type = wall_big
								}
							}
						}
						any_equipped_character_artifact = {
							count < 3
							artifact_slot_type = wall_big
						}
					}
					AND = {
						has_royal_court = yes
						scope:target = {
							artifact_slot_type = wall_small
						}
						scope:actor = {
							OR = {
								has_royal_court = no
								any_equipped_character_artifact = {
									count >= 3
									artifact_slot_type = wall_small
								}
							}
						}
						any_equipped_character_artifact = {
							count < 3
							artifact_slot_type = wall_small
						}
					}
					AND = {
						has_royal_court = yes
						scope:target = {
							artifact_slot_type = sculpture
						}
						scope:actor = {
							OR = {
								has_royal_court = no
								any_equipped_character_artifact = {
									count >= 2
									artifact_slot_type = sculpture
								}
							}
						}
						any_equipped_character_artifact = {
							count < 2
							artifact_slot_type = sculpture
						}
					}
					AND = {
						has_royal_court = yes
						scope:target = {
							artifact_slot_type = book
						}
						scope:actor = {
							OR = {
								has_royal_court = no
								any_equipped_character_artifact = {
									count >= 2
									artifact_slot_type = book
								}
							}
						}
						any_equipped_character_artifact = {
							count < 2
							artifact_slot_type = book
						}
					}
					AND = {
						has_royal_court = yes
						scope:target = {
							artifact_slot_type = pedestal
						}
						scope:actor = {
							OR = {
								has_royal_court = no
								any_equipped_character_artifact = {
									count >= 4
									artifact_slot_type = pedestal
								}
							}
						}
						any_equipped_character_artifact = {
							count < 4
							artifact_slot_type = pedestal
						}
					}
				}
			}
		}

		# Struggle
		modifier = {
			scope:recipient = {
				is_independent_ruler = yes
			}
			scope:actor = {
				any_character_struggle = {
					involvement = involved
				}
			}
			add = {
				value = 0
				if = {
					limit = {
						scope:actor = {
							any_character_struggle = {
								phase_has_catalyst = catalyst_gift_independent_ruler
							}
							has_character_flag = agenda_towards_escalation
						}
					}
					add = -100
				}
				else_if = {
					limit = {
						scope:actor = {
							any_character_struggle = {
								phase_has_catalyst = catalyst_gift_independent_ruler
							}
						}
					}
					add = 200
				}
			}
		}

		# Unity modifiers
		evaluate_action_increasing_house_unity = {
			VALUE = 100
		}
		
		modifier = {
			factor = 2
			scope:recipient = {
				is_ai = no
			}
		}
		
		modifier = {
			factor = 0.25
			scope:recipient = {
				highest_held_title_tier = tier_barony
			}
		}
		
		modifier = { # Unlanded characters do not equip artifacts, no point in giving them artifacts
			factor = 0
			scope:recipient = {
				is_ruler = no
			}
		}
		
		modifier = {
			factor = 0
			scope:recipient = {
				has_relation_rival = scope:actor
			}
		}
		
		modifier = {
			factor = 0
			scope:target = {
				has_variable = cursed_artifact
			}
		}
		
		modifier = {
			factor = 0
			scope:target = {
				is_equipped = yes
			}
		}
		
		modifier = {
			factor = 0
			scope:target = {
				has_variable = gifted_artifact
			}
		}
		
		modifier = { # So that the AI doesn't give player toys
			factor = 0
			scope:recipient = {
				is_ai = no
				NOT = {
					can_equip_artifact = scope:target
				}
			}
		}

		modifier = {
			factor = 0
			scope:target = { exists = var:relic_religion}
			scope:actor = {
				has_religion = scope:target.var:relic_religion
			}
		}

		modifier = {
			factor = 0
			OR = {
				exists = scope:target.var:banner_house
				exists = scope:target.var:banner_dynasty
			}
			scope:recipient = {
				NOT = {
					can_benefit_from_artifact = scope:target
				}
			}
		}

		modifier = {
			add = 100
			exists = scope:target.var:banner_dynasty
			exists = scope:recipient.dynasty
			scope:recipient = scope:target.var:banner_dynasty.dynast
			NOT = {
				scope:actor = {
					has_any_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
				}
			}
		}
	}
}

# Demand an artifact you have a claim on
demand_artifact_interaction = {
	category = interaction_category_diplomacy
	common_interaction = yes
	interface_priority = 60
	use_diplomatic_range = yes
	desc = demand_artifact_interaction_desc
	icon = artisan_inspiration

	target_type = artifact
	target_filter = recipient_artifacts_claimable

	greeting = negative
	notification_text = DEMAND_ARTIFACT_PROPOSAL

	answer_accept_key = DEMAND_ARTIFACT_ACCEPT
	answer_reject_key = DEMAND_ARTIFACT_REJECT

	ai_targets = {
		ai_recipients = scripted_relations
	}
	ai_targets = {
		ai_recipients = liege
	}
	ai_targets = {
		ai_recipients = neighboring_rulers
		ai_recipients = peer_vassals
		ai_recipients = nearby_domicile_owners
		max = 10
	}
	ai_targets = {
		ai_recipients = vassals
		max = 10
	}
	ai_targets = {
		ai_recipients = family
		max = 10
	}
	ai_target_quick_trigger = {
		adult = yes
	}
	ai_frequency = 60

	is_shown = {
		NOT = {
			scope:recipient = scope:actor
		}

		custom_description = {
			text = "demand_artifact_interaction_valid_tt_1"
			scope:recipient = {
				# needs to have an artifact we can claim
				any_character_artifact = {
					can_be_claimed_by = scope:actor
				}
			}
		}
	}
	
	is_highlighted = {
		always = yes
	}

	is_valid_showing_failures_only = {

		scope:recipient = { is_busy_in_events_localised = yes }
		
		scope:actor = {
			NOT = {
				is_at_war_with = scope:recipient
			}
		}
		
		trigger_if = {
			limit = {
				scope:actor = {
					has_variable = demanded_this_artifact_interaction_recently
				}
			}
			custom_description = {
				text = "demand_artifact_interaction_is_valid_tt_2"
				exists = scope:demanded_artifact
				scope:actor = {
					has_variable = demanded_this_artifact_interaction_recently
					var:demanded_this_artifact_interaction_recently = scope:demanded_artifact
				}
			}
		}
		scope:actor = { is_imprisoned = no }
	}

	on_accept = {
		scope:target = {
			save_scope_as = demanded_artifact
		}
		if = {
			limit = {
				exists = scope:demanded_artifact
			}
			scope:actor = {
				set_variable = {
					name = demanded_this_artifact_interaction_recently
					value = scope:demanded_artifact
					years = 5
				}
			}
		}
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = demand_artifact_interaction_notification
				left_icon = scope:recipient
				right_icon = scope:target
				scope:target = {
					set_owner = scope:actor
				}

				scope:recipient = {
					add_opinion = {
						target = scope:actor
						modifier = insult_opinion
						opinion = -10
					}
				}
				if = {
					limit = {
						scope:recipient = {
							can_set_relation_potential_rival_trigger = { CHARACTER = scope:actor }
						}
					}
					scope:recipient = {
						set_relation_potential_rival = scope:actor
					}
				}
			}
		}
		if = {
			limit = {
				scope:actor = {
					is_ai = yes
				}
			}
			scope:actor = {
				add_opinion = {
					target = scope:recipient
					modifier = pleased_opinion
					opinion = 30
				}
			}
		}

		add_clan_unity_interaction_effect = {
			CHARACTER = scope:actor
			TARGET = scope:recipient
			VALUE = minor_unity_loss
			DESC = clan_unity_demanded_artifact.desc
			REVERSE_NON_HOUSE_TARGET = no
		}
	}

	auto_accept = {
		custom_description = {
			text = "spending_hook"
			subject = scope:actor
			object = scope:recipient
			scope:hook = yes
			scope:actor = { has_strong_hook = scope:recipient }
		}
	}
	
	send_option = {
		is_shown = {
			NOT = { scope:actor = scope:recipient }
		}
		is_valid = {
			scope:actor = {
				has_usable_hook = scope:recipient
			}
		}
		flag = hook
		localization = GENERIC_SPEND_A_HOOK
	}
	should_use_extra_icon = {
		scope:actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	send_options_exclusive = no
	
	ai_accept = {
		base = 0
		modifier = {
			add = -50
			desc = ARTIFACT_REASON
		}
		modifier = {
			add = 70
			scope:actor.max_military_strength > scope:recipient.max_military_strength
			desc = ARTIFACT_MILITARY_STRONGER_REASON
		}
		modifier = {
			add = -70
			scope:actor.max_military_strength < scope:recipient.max_military_strength
			desc = ARTIFACT_MILITARY_WEAKER_REASON
		}
		modifier = {
			add = -50
			scope:target = { can_be_claimed_by = scope:recipient }
			desc = ARTIFACT_CLAIM_REASON
		}
		modifier = {
			add = {
				value = ai_boldness
				multiply = -1
				divide = 2
			}
			NOT = { ai_boldness = 0 }
			desc = ARTIFACT_BOLDNESS_REASON
		}
		modifier = {
			add = -50
			scope:actor = {
				has_relation_rival = scope:recipient
			}
			desc = ARTIFACT_RIVAL_REASON
		}
		modifier = {
			add = -80
			scope:actor = {
				has_relation_nemesis = scope:recipient
			}
			desc = ARTIFACT_NEMESIS_REASON
		}
		modifier = {
			add = 50
			scope:recipient = {
				target_is_liege_or_above = scope:actor
			}
			desc = ARTIFACT_LIEGE_REASON
		}
		modifier = {
			scope:hook = yes
			add = 100
			desc = SCHEME_WEAK_HOOK_USED
		}

		# Unity modifiers
		evaluate_action_decreasing_house_unity = { VALUE = 100 }
	}
	
	ai_potential = {
		is_adult = yes
		is_at_war = no
		ai_greed >= low_negative_ai_value
		has_outstanding_artifact_claims = yes
	}

	on_decline = {
		scope:target = {
			save_scope_as = demanded_artifact
		}
		if = {
			limit = {
				exists = scope:demanded_artifact
			}
			scope:actor = {
				set_variable = {
					name = demanded_this_artifact_interaction_recently
					value = scope:demanded_artifact
					years = 5
				}
			}
		}
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_bad
				title = demand_artifact_interaction_notification
				left_icon = scope:recipient
				right_icon = scope:target
				custom_tooltip = demand_artifact_interaction_notification_refused

				scope:recipient = {
					add_opinion = {
						target = scope:actor
						modifier = insult_opinion
						opinion = -10
					}
				}
			}
		}
		if = {
			limit = {
				scope:actor = {
					is_ai = yes
				}
			}
			scope:actor = {
				add_opinion = {
					target = scope:recipient
					modifier = refusal_opinion
					opinion = -10
				}
			}
		}
	}
	
	ai_min_reply_days = 7
	ai_max_reply_days = 14
	
	ai_will_do = {
		base = 100
		
		modifier = { # The AI will only use a Hook if they couldn't otherwise do this
			scope:hook = yes
			add = -1
		}
		
		modifier = {
			add = 50
			has_relation_rival = scope:recipient
		}
		modifier = {
			add = 80
			has_relation_nemesis = scope:recipient
		}
		modifier = {
			add = -50
			target_is_liege_or_above = scope:recipient
		}
		# Recipient is flaunting their artifacts and needs to be taken down a peg - from hold_court.3080
		modifier = {
			scope:recipient = {
				OR = {
					has_character_modifier = petition_event_artifact_exhibition_for_prestige
					has_character_modifier = petition_event_artifact_exhibition_for_gold
				}
			}
			add = 35
		}
		modifier = { # An Intimidated character is very unlikely to raise their hand
			add = -25
			scope:actor = {
				has_dread_level_towards = {
					target = scope:recipient
					level = 1
				}
			}
		}

		# Unity modifiers
		evaluate_action_decreasing_house_unity = {
				VALUE = 100
			}

		modifier = { # A Cowed character will never take this interaction
			factor = 0
			scope:actor = {
				has_dread_level_towards = {
					target = scope:recipient
					level = 2
				}
			}
		}
		modifier = { # The AI doesn't demand from players they like
			factor = 0
			scope:recipient = {
				is_ai = no
			}
			scope:actor = {
				OR = {
					has_relation_friend = scope:recipient
					has_relation_lover = scope:recipient
					opinion = {
						target = scope:recipient
						value >= high_positive_opinion
					}
				}
			}
		}
		modifier = { # The AI doesn't demand from players that have refused already
			factor = 0
			scope:recipient = {
				is_ai = no
			}
			scope:actor = {
				has_opinion_modifier = {
					target = scope:recipient
					modifier = refusal_opinion
				}
			}
		}
		modifier = { # Only the House Head will demand house claimed artifacts from existing House members
			factor = 0
			exists = scope:actor.house.house_head
			exists = scope:recipient.house
			scope:actor.house.house_head = scope:actor
			scope:actor.house = scope:recipient.house
			
			NOT = {
				any_personal_claimed_artifact = {
					this = scope:target
				}
			}
		}
		modifier = {
			scope:actor = {
				opinion = {
					target = scope:recipient
					value >= medium_positive_opinion
				}
				ai_greed <= high_positive_ai_value
			}
			factor = 0
		}
		modifier = {
			scope:recipient = {
				OR = {
					has_relation_friend = scope:actor
					has_relation_lover = scope:actor
				}
			}
			factor = 0
		}
		modifier = {
			scope:actor = {
				has_royal_court = no
			}
			scope:target = {
				OR = {
					artifact_slot_type = throne
					artifact_slot_type = wall_big
					artifact_slot_type = wall_small
					artifact_slot_type = sculpture
					artifact_slot_type = book
					artifact_slot_type = pedestal
				}
			}
			factor = 0
		}
		modifier = {
			scope:recipient = {
				OR = {
					AND = {
						scope:target = {
							artifact_slot_type = primary_armament
						}
						OR = {
							any_equipped_character_artifact = {
								artifact_slot_type = primary_armament
								rarity = illustrious
							}
							AND = {
								any_equipped_character_artifact = {
									artifact_slot_type = primary_armament
									rarity = famed
								}
								scope:target = {
									OR = {
										rarity = famed
										rarity = masterwork
										rarity = common
									}
								}
							}
							AND = {
								any_equipped_character_artifact = {
									artifact_slot_type = primary_armament
									rarity = masterwork
								}
								scope:target = {
									OR = {
										rarity = masterwork
										rarity = common
									}
								}
							}
							AND = {
								any_equipped_character_artifact = {
									artifact_slot_type = primary_armament
									rarity = common
								}
								scope:target = {
									rarity = common
								}
							}
						}
					}
					AND = {
						scope:target = {
							artifact_slot_type = regalia
						}
						OR = {
							any_equipped_character_artifact = {
								artifact_slot_type = regalia
								rarity = illustrious
							}
							AND = {
								any_equipped_character_artifact = {
									artifact_slot_type = regalia
									rarity = famed
								}
								scope:target = {
									OR = {
										rarity = famed
										rarity = masterwork
										rarity = common
									}
								}
							}
							AND = {
								any_equipped_character_artifact = {
									artifact_slot_type = regalia
									rarity = masterwork
								}
								scope:target = {
									OR = {
										rarity = masterwork
										rarity = common
									}
								}
							}
							AND = {
								any_equipped_character_artifact = {
									artifact_slot_type = regalia
									rarity = common
								}
								scope:target = {
									rarity = common
								}
							}
						}	
					}
					AND = {
						scope:target = {
							artifact_slot_type = helmet
						}
						OR = {
							any_equipped_character_artifact = {
								artifact_slot_type = helmet
								rarity = illustrious
							}
							AND = {
								any_equipped_character_artifact = {
									artifact_slot_type = helmet
									rarity = famed
								}
								scope:target = {
									OR = {
										rarity = famed
										rarity = masterwork
										rarity = common
									}
								}
							}
							AND = {
								any_equipped_character_artifact = {
									artifact_slot_type = helmet
									rarity = masterwork
								}
								scope:target = {
									OR = {
										rarity = masterwork
										rarity = common
									}
								}
							}
							AND = {
								any_equipped_character_artifact = {
									artifact_slot_type = helmet
									rarity = common
								}
								scope:target = {
									rarity = common
								}
							}
						}	
					}
					AND = {
						scope:target = {
							artifact_slot_type = armor
						}
						OR = {
							any_equipped_character_artifact = {
								artifact_slot_type = armor
								rarity = illustrious
							}
							AND = {
								any_equipped_character_artifact = {
									artifact_slot_type = armor
									rarity = famed
								}
								scope:target = {
									OR = {
										rarity = famed
										rarity = masterwork
										rarity = common
									}
								}
							}
							AND = {
								any_equipped_character_artifact = {
									artifact_slot_type = armor
									rarity = masterwork
								}
								scope:target = {
									OR = {
										rarity = masterwork
										rarity = common
									}
								}
							}
							AND = {
								any_equipped_character_artifact = {
									artifact_slot_type = armor
									rarity = common
								}
								scope:target = {
									rarity = common
								}
							}
						}
					}
					AND = {
						scope:target = {
							artifact_slot_type = miscellaneous
							rarity = common
						}
						any_equipped_character_artifact = {
							count >= 4
							artifact_slot_type = miscellaneous
						}
					}
					AND = {
						scope:target = {
							artifact_slot_type = throne
						}
						OR = {
							any_equipped_character_artifact = {
								artifact_slot_type = throne
								rarity = illustrious
							}
							AND = {
								any_equipped_character_artifact = {
									artifact_slot_type = throne
									rarity = famed
								}
								scope:target = {
									OR = {
										rarity = famed
										rarity = masterwork
										rarity = common
									}
								}
							}
							AND = {
								any_equipped_character_artifact = {
									artifact_slot_type = throne
									rarity = masterwork
								}
								scope:target = {
									OR = {
										rarity = masterwork
										rarity = common
									}
								}
							}
							AND = {
								any_equipped_character_artifact = {
									artifact_slot_type = throne
									rarity = common
								}
								scope:target = {
									rarity = common
								}
							}
						}
					}
					AND = {
						scope:target = {
							artifact_slot_type = wall_big
							rarity = common
						}
						any_equipped_character_artifact = {
							count >= 3
							artifact_slot_type = wall_big
						}
					}
					AND = {
						scope:target = {
							artifact_slot_type = wall_small
							rarity = common
						}
						any_equipped_character_artifact = {
							count >= 3
							artifact_slot_type = wall_small
						}
					}
					AND = {
						scope:target = {
							artifact_slot_type = sculpture
							rarity = common
						}
						any_equipped_character_artifact = {
							count >= 2
							artifact_slot_type = sculpture
						}
					}
					AND = {
						scope:target = {
							artifact_slot_type = book
							rarity = common
						}
						any_equipped_character_artifact = {
							count >= 2
							artifact_slot_type = book
						}
					}
					AND = {
						scope:target = {
							artifact_slot_type = pedestal
							rarity = common
						}
						any_equipped_character_artifact = {
							count >= 4
							artifact_slot_type = pedestal
						}
					}
				}
			}
			factor = 0
		}
	}
}

# Challenge someone to a non-lethal duel for an artifact you have a claim on
challenge_for_artifact_interaction = {
	icon = icon_combat
	interface_priority = 30
	common_interaction = yes
	category = interaction_category_hostile
	ai_maybe = yes
	ai_max_reply_days = 0
	popup_on_receive = yes
	pause_on_receive = yes
	use_diplomatic_range = yes
	can_send_despite_rejection = yes
	desc = challenge_for_artifact_interaction_desc

	target_type = artifact
	target_filter = recipient_artifacts_claimable

	greeting = negative
	notification_text = REQUEST_ARTIFACT_COMBAT_TEXT

	answer_accept_key = REQUEST_ARTIFACT_COMBAT_ACCEPT
	answer_reject_key = REQUEST_ARTIFACT_COMBAT_REJECT

	is_shown = {
		# Can't duel yourself.
		NOT = { scope:actor = scope:recipient }
		custom_description = {
			text = "challenge_for_artifact_interaction_valid_tt_1"
			scope:recipient = {
				# needs to have an artifact we can claim
				any_character_artifact = {
					can_be_claimed_by = scope:actor
				}
			}
		}
	}

	is_valid_showing_failures_only = {
		rival_single_combat_shown_and_not_invalid_trigger = yes
		scope:recipient = { can_start_single_combat_trigger = yes }
		scope:recipient = {
			custom_description = {
				text = fp1_tbc_recipient_banned_from_combat
				can_start_single_combat_banned_checks_trigger = no
			}
		}
		scope:recipient = { is_imprisoned = no }
		scope:actor = { is_imprisoned = no }
	}

	can_send = {
		scope:actor = {
			custom_description = {
				text = "character_interactions_hostile_actions_disabled_delay"
				NOT = { has_character_flag = flag_hostile_actions_disabled_delay }
			}
		}
	}
	
	is_highlighted = {
		rival_single_combat_shown_and_not_invalid_trigger = yes
		# Scope:recipient must be able to fight personally.
		scope:recipient = { can_start_single_combat_trigger = yes }
		# Scope:recipient must not be banned from single combat.
		scope:recipient = { can_start_single_combat_banned_checks_trigger = no }
		scope:recipient = { is_imprisoned = no }
		scope:actor = { is_imprisoned = no }
	}
	
	cost = { prestige = challenge_for_artifact_prestige_cost_value }
	cooldown = { years = 2 }
	cooldown_against_recipient = { years = 5 } 

	on_send = {
		scope:actor = {
			add_character_flag = {
				flag = flag_hostile_actions_disabled_delay
				days = 10
			}
		}
	}

	on_accept = {
		scope:actor = {
			remove_character_flag = flag_hostile_actions_disabled_delay
		}
		# Set up the bout immediately.
		## First inform.
		scope:actor = {
			custom_tooltip = challenge_to_single_combat_interaction.enter_non_lethal_bout.tt
			custom_tooltip = challenge_to_artifact_combat_interaction_victor_gets.tt
			custom_tooltip = challenge_to_artifact_combat_interaction_loser_gets.tt
		}
		## Finally, begin.
		configure_start_single_combat_effect = {
			SC_INITIATOR = scope:actor
			SC_ATTACKER = scope:actor
			SC_DEFENDER = scope:recipient
			FATALITY = no
			FIXED = no
			LOCALE = terrain_scope
			OUTPUT_EVENT = artifact.2001
			INVALIDATION_EVENT = fp1_tbc.0021
		}

		add_clan_unity_interaction_effect = {
			CHARACTER = scope:actor
			TARGET = scope:recipient
			VALUE = major_unity_loss
			DESC = clan_unity_challenge_artifact.desc
			REVERSE_NON_HOUSE_TARGET = no
		}
	}

	on_decline = {
		add_clan_unity_interaction_effect = {
			CHARACTER = scope:actor
			TARGET = scope:recipient
			VALUE = minor_unity_gain
			DESC = clan_unity_challenge_artifact_refusal.desc
			REVERSE_NON_HOUSE_TARGET = no
		}

		# Scope:recipient declines processing.
		scope:actor = {
			# Inform them of the decline & scope:recipient loses some prestige.
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = challenge_to_single_combat_interaction.challenge_rejected.t
				left_icon = scope:recipient
				right_icon = scope:actor
				scope:recipient = {
					add_prestige = {
						value = 0
						subtract = challenge_for_artifact_prestige_cost_value
					}
				}
				show_as_tooltip = {
					add_prestige = challenge_for_artifact_prestige_cost_value
				}
			}
			hidden_effect = {
				add_prestige_no_experience = challenge_for_artifact_prestige_cost_value
				# Cooldown is removed.
				remove_interaction_cooldown = challenge_for_artifact_interaction
			}
			# Clear up hostile actions flag.
			if = {
				limit = {
					has_character_flag = flag_hostile_actions_disabled_delay
				}
				remove_character_flag = flag_hostile_actions_disabled_delay
			}
		}
	}

	auto_accept = no

	ai_accept = {
		base = 50 # Try to make it 0 for most interactions

		# Relative fighting ability.
		modifier = {
			desc = CTSC_RELATIVE_PROWESS
			scope:actor.prowess < scope:recipient.prowess
			add = {
				value = scope:recipient.prowess
				subtract = scope:actor.prowess
				multiply = 2
			}
		}
		modifier = {
			desc = CTSC_RELATIVE_PROWESS
			scope:recipient.prowess < scope:actor.prowess
			add = {
				value = scope:actor.prowess
				subtract = scope:recipient.prowess
				multiply = -2
			}
		}
		# Weight up for personality values.
		ai_value_modifier = {
			who = scope:recipient
			ai_boldness = 1
			ai_vengefulness = 0.75
			ai_honor = 0.5
			ai_rationality = -0.25
			ai_greed = -0.5
		}
		# Apply tier differences.
		## King -> Baron.
		modifier = {
			desc = AI_REFUSAL_RANK_DIFFERENCE
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value >= 4
				}
			}
			add = 15
		}
		## Duke -> Baron.
		modifier = {
			desc = AI_REFUSAL_RANK_DIFFERENCE
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = 3
				}
			}
			add = 10
		}
		## Count -> Baron.
		modifier = {
			desc = AI_REFUSAL_RANK_DIFFERENCE
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = 2
				}
			}
			add = 5
		}
		## King <- Baron.
		modifier = {
			desc = AI_REFUSAL_RANK_DIFFERENCE
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = -2
				}
			}
			add = -20
		}
		## Duke <- Baron.
		modifier = {
			desc = AI_REFUSAL_RANK_DIFFERENCE
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = -3
				}
			}
			add = -30
		}
		## Count <- Baron.
		modifier = {
			desc = AI_REFUSAL_RANK_DIFFERENCE
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value <= -4
				}
			}
			add = -40
		}
		# Rival modifier 
		modifier = {
			desc = offer_vassalization_interaction_aibehavior_rival_tt
			trigger = {
				scope:recipient = {
					has_relation_rival = scope:actor
				}
			}
			add = 30
		}
		# Nemesis modifier
		modifier = {
			desc = offer_vassalization_interaction_aibehavior_nemesis_tt
			trigger = {
				scope:recipient = {
					has_relation_nemesis = scope:actor
				}
			}
			add = 50
		}
		# Prestige too low to decline
		modifier = {
			desc = cannot_afford_prestige_loss_tt
			trigger = { scope:recipient.prestige < challenge_for_artifact_prestige_limit_value } # 1/3rd of potential loss
			add = 30
		}

		# Unity modifiers
		evaluate_action_decreasing_house_unity = {
				VALUE = 100
			}
	}

	# AI
	ai_potential = {
		NOT = { has_trait = craven }
		is_imprisoned = no
		can_start_single_combat_trigger = yes
		ai_greed >= low_negative_ai_value
		has_outstanding_artifact_claims = yes
	}
	
	ai_target_quick_trigger = {
		adult = yes
	}
	ai_targets = {
		ai_recipients = scripted_relations
	}

	ai_targets = {
		ai_recipients = liege
	}
	ai_targets = {
		ai_recipients = neighboring_rulers
		ai_recipients = peer_vassals
		ai_recipients = nearby_domicile_owners
		max = 10
	}
	ai_targets = {
		ai_recipients = family
		max = 10
	}
	ai_targets = {
		ai_recipients = vassals
		max = 10
	}

	ai_frequency = 60

	ai_will_do = {
		base = -50
		
		# Factor for personality (excluding realism).
		modifier = {
			add = ai_boldness
		}
		modifier = {
			ai_vengefulness > 0
			add = ai_vengefulness
		}
		modifier = {
			add = {
				value = ai_compassion
				multiply = -0.25
			}
		}
		# Don't challenge your spouse, unless they're your nemesis.
		modifier = {
			scope:recipient = {
				is_spouse_of = scope:actor
				NOT = { has_relation_nemesis = scope:actor }
			}
			add = -1000
		}
		# Don't challenge people hopelessly out of your league unless you're really, really not seeing things clearly.
		modifier = {
			scope:actor = {
				prowess_diff = {
					target = scope:recipient
					value <= -15
				}
				ai_rationality >= high_negative_ai_value
			}
			add = -1000
		}
		# Don't challenge your liege - it's really bad form - unless you are REALLY motivated
		modifier = {
			scope:actor = {
				is_vassal_of = scope:recipient
			}
			add = -100
		}
		# Challenge them if they are your rival
		modifier = {
			scope:actor = {
				has_relation_rival = scope:recipient
			}
			add = 30
		}
		# Totally challenge them if they are your nemesis!
		modifier = {
			scope:actor = {
				has_relation_nemesis = scope:recipient
			}
			add = 50
		}
		# Recipient is flaunting their artifacts and needs to be taken down a peg - from hold_court.3080
		modifier = {
			scope:recipient = {
				OR = {
					has_character_modifier = petition_event_artifact_exhibition_for_prestige
					has_character_modifier = petition_event_artifact_exhibition_for_gold
				}
			}
			add = 35
		}
		modifier = { # An Intimidated character is very unlikely to raise their hand
			add = -25
			scope:actor = {
				has_dread_level_towards = {
					target = scope:recipient
					level = 1
				}
			}
		}

		# Unity modifiers
		evaluate_action_decreasing_house_unity = {
			VALUE = 100
		}


		modifier = { # A Cowed character will never take this interaction
			factor = 0
			scope:actor = {
				has_dread_level_towards = {
					target = scope:recipient
					level = 2
				}
			}
		}
		modifier = {
			scope:actor = {
				opinion = {
					target = scope:recipient
					value >= medium_positive_opinion
				}
				ai_greed <= high_positive_ai_value
			}
			factor = 0
		}
		modifier = {
			scope:recipient = {
				OR = {
					has_relation_friend = scope:actor
					has_relation_lover = scope:actor
				}
			}
			factor = 0
		}
		modifier = {
			scope:actor = {
				has_royal_court = no
			}
			scope:target = {
				OR = {
					artifact_slot_type = throne
					artifact_slot_type = wall_big
					artifact_slot_type = wall_small
					artifact_slot_type = sculpture
					artifact_slot_type = book
					artifact_slot_type = pedestal
				}
			}
			factor = 0
		}
		modifier = {
			scope:recipient = {
				OR = {
					AND = {
						scope:target = {
							artifact_slot_type = primary_armament
						}
						OR = {
							any_equipped_character_artifact = {
								artifact_slot_type = primary_armament
								rarity = illustrious
							}
							AND = {
								any_equipped_character_artifact = {
									artifact_slot_type = primary_armament
									rarity = famed
								}
								scope:target = {
									OR = {
										rarity = famed
										rarity = masterwork
										rarity = common
									}
								}
							}
							AND = {
								any_equipped_character_artifact = {
									artifact_slot_type = primary_armament
									rarity = masterwork
								}
								scope:target = {
									OR = {
										rarity = masterwork
										rarity = common
									}
								}
							}
							AND = {
								any_equipped_character_artifact = {
									artifact_slot_type = primary_armament
									rarity = common
								}
								scope:target = {
									rarity = common
								}
							}
						}
					}
					AND = {
						scope:target = {
							artifact_slot_type = regalia
						}
						OR = {
							any_equipped_character_artifact = {
								artifact_slot_type = regalia
								rarity = illustrious
							}
							AND = {
								any_equipped_character_artifact = {
									artifact_slot_type = regalia
									rarity = famed
								}
								scope:target = {
									OR = {
										rarity = famed
										rarity = masterwork
										rarity = common
									}
								}
							}
							AND = {
								any_equipped_character_artifact = {
									artifact_slot_type = regalia
									rarity = masterwork
								}
								scope:target = {
									OR = {
										rarity = masterwork
										rarity = common
									}
								}
							}
							AND = {
								any_equipped_character_artifact = {
									artifact_slot_type = regalia
									rarity = common
								}
								scope:target = {
									rarity = common
								}
							}
						}	
					}
					AND = {
						scope:target = {
							artifact_slot_type = helmet
						}
						OR = {
							any_equipped_character_artifact = {
								artifact_slot_type = helmet
								rarity = illustrious
							}
							AND = {
								any_equipped_character_artifact = {
									artifact_slot_type = helmet
									rarity = famed
								}
								scope:target = {
									OR = {
										rarity = famed
										rarity = masterwork
										rarity = common
									}
								}
							}
							AND = {
								any_equipped_character_artifact = {
									artifact_slot_type = helmet
									rarity = masterwork
								}
								scope:target = {
									OR = {
										rarity = masterwork
										rarity = common
									}
								}
							}
							AND = {
								any_equipped_character_artifact = {
									artifact_slot_type = helmet
									rarity = common
								}
								scope:target = {
									rarity = common
								}
							}
						}	
					}
					AND = {
						scope:target = {
							artifact_slot_type = armor
						}
						OR = {
							any_equipped_character_artifact = {
								artifact_slot_type = armor
								rarity = illustrious
							}
							AND = {
								any_equipped_character_artifact = {
									artifact_slot_type = armor
									rarity = famed
								}
								scope:target = {
									OR = {
										rarity = famed
										rarity = masterwork
										rarity = common
									}
								}
							}
							AND = {
								any_equipped_character_artifact = {
									artifact_slot_type = armor
									rarity = masterwork
								}
								scope:target = {
									OR = {
										rarity = masterwork
										rarity = common
									}
								}
							}
							AND = {
								any_equipped_character_artifact = {
									artifact_slot_type = armor
									rarity = common
								}
								scope:target = {
									rarity = common
								}
							}
						}
					}
					AND = {
						scope:target = {
							artifact_slot_type = miscellaneous
							rarity = common
						}
						any_equipped_character_artifact = {
							count >= 4
							artifact_slot_type = miscellaneous
						}
					}
					AND = {
						scope:target = {
							artifact_slot_type = throne
						}
						OR = {
							any_equipped_character_artifact = {
								artifact_slot_type = throne
								rarity = illustrious
							}
							AND = {
								any_equipped_character_artifact = {
									artifact_slot_type = throne
									rarity = famed
								}
								scope:target = {
									OR = {
										rarity = famed
										rarity = masterwork
										rarity = common
									}
								}
							}
							AND = {
								any_equipped_character_artifact = {
									artifact_slot_type = throne
									rarity = masterwork
								}
								scope:target = {
									OR = {
										rarity = masterwork
										rarity = common
									}
								}
							}
							AND = {
								any_equipped_character_artifact = {
									artifact_slot_type = throne
									rarity = common
								}
								scope:target = {
									rarity = common
								}
							}
						}
					}
					AND = {
						scope:target = {
							artifact_slot_type = wall_big
							rarity = common
						}
						any_equipped_character_artifact = {
							count >= 3
							artifact_slot_type = wall_big
						}
					}
					AND = {
						scope:target = {
							artifact_slot_type = wall_small
							rarity = common
						}
						any_equipped_character_artifact = {
							count >= 3
							artifact_slot_type = wall_small
						}
					}
					AND = {
						scope:target = {
							artifact_slot_type = sculpture
							rarity = common
						}
						any_equipped_character_artifact = {
							count >= 2
							artifact_slot_type = sculpture
						}
					}
					AND = {
						scope:target = {
							artifact_slot_type = book
							rarity = common
						}
						any_equipped_character_artifact = {
							count >= 2
							artifact_slot_type = book
						}
					}
					AND = {
						scope:target = {
							artifact_slot_type = pedestal
							rarity = common
						}
						any_equipped_character_artifact = {
							count >= 4
							artifact_slot_type = pedestal
						}
					}
				}
			}
			factor = 0
		}
	}
}

#Steal an artifact that you have a claim on 
start_stealing_back_artifact = {
	icon = icon_scheme_steal_back_artifact
	interface_priority = 70
	category = interaction_category_hostile
	common_interaction = yes

	send_name = START_SCHEME

	scheme = steal_back_artifact
	ignores_pending_interaction_block = yes

	target_type = artifact
	target_filter = recipient_artifacts
	
	is_shown = {
		NOR = {
			scope:recipient = scope:actor
			scope:recipient = { is_imprisoned_by = scope:actor }
		}
		OR = {
			scope:recipient = {
				# needs to have an artifact we can claim
				any_character_artifact = {
					can_be_claimed_by = scope:actor
				}
			}
			scope:actor = {
				OR = {
					employs_court_position = master_thief_camp_officer
					any_character_active_contract = {
						has_task_contract_type = laamp_steal_artifact_contract
						var:task_contract_target ?= scope:recipient
					}
				}
			}
		}
	}
	
	is_highlighted = {
		always = yes
	}

	is_valid_showing_failures_only = {
		trigger_if = {
		   limit = {
				scope:actor = {
					any_character_artifact = {
						scope:actor = { has_artifact_claim = prev }
					}
				}
			}
		
			custom_description = {
				text = steal_back_artifact_can_start_scheme
				subject = scope:actor
				object = scope:recipient
				scope:actor = {
					can_start_scheme = {
						type = steal_back_artifact
						target_character = scope:recipient
					}
				}
			}
		}
		trigger_if = {
		   limit = {
				scope:actor = {
					NOR = {
						employs_court_position = master_thief_camp_officer 
						any_character_task_contract = {
							has_task_contract_type = laamp_steal_artifact_contract
							var:task_contract_target ?= scope:recipient
						}
					}
				}
			}
			custom_description = {
				text = steal_back_artifact_must_have_claim_blocker
				subject = scope:actor
				object = scope:recipient

				scope:recipient = {
					any_character_artifact = {
						scope:actor = { 
							has_artifact_claim = prev
						}
					}
				}
			}
		}
		custom_description = {
			object = scope:recipient
			text = you_have_been_caught_trying_to_steal_artifact_from_target
			scope:recipient = {
				NOT = {
					has_opinion_modifier = {
						target = scope:actor
						modifier = attempted_to_steal_artifact_from_me
					}
				}
			}
		}

		custom_description = {
			object = scope:recipient
			text = you_have_recently_stolen_artifact_from_target
			scope:recipient = {
				NOT = {
					has_opinion_modifier = {
						target = scope:actor
						modifier = stole_artifact_from_me
					}
				}
			}
		}
	}

	desc = {
		triggered_desc = {
			trigger = {
				scope:actor = {
					can_start_scheme = {
						type = steal_back_artifact
						target_character = scope:recipient
					}
				}
			}
			desc = scheme_interaction_tt_steal_back_artifact_approved
		}
	}
	can_be_picked_artifact = {
		trigger_if = {
			limit = {
				scope:actor = {
					NOR = {
						employs_court_position = master_thief_camp_officer
						any_character_active_contract = {
							has_task_contract_type = laamp_steal_artifact_contract
							var:task_contract_object ?= scope:target
						}
					}
				}
			}
			scope:actor = {
				has_artifact_claim = scope:target
			}
		}
	}
	# Scheme Starter Packages
	options_heading = schemes.t.agent_packages
	send_options_exclusive = yes
	## Balanced agents.
	send_option = {
		flag = agent_focus_balance
		current_description = start_stealing_back_artifact.tt.agent_focus_balance
	}
	## Focused on Success Chance.
	send_option = {
		flag = agent_focus_success
		current_description = start_stealing_back_artifact.tt.agent_focus_success
	}
	## Focused on Speed.
	send_option = {
		flag = agent_focus_speed
		current_description = start_stealing_back_artifact.tt.agent_focus_speed
	}
	## Focused on Secrecy.
	send_option = {
		flag = agent_focus_secrecy
		current_description = start_stealing_back_artifact.tt.agent_focus_secrecy
	}

	on_accept = {
		scope:actor = {
			stress_impact = {
				vengeful = medium_stress_impact_loss
				honest = minor_stress_impact_gain
				just = minor_stress_impact_loss
			}
		}
		hidden_effect = {
			scope:actor = {
				send_interface_toast = {
					type = event_toast_effect_neutral
					title = start_stealing_back_artifact_notification

					left_icon = scope:actor					
					right_icon = scope:recipient

					if =  {
						limit = {
							any_character_active_contract = {
								has_task_contract_type = laamp_steal_artifact_contract
								var:task_contract_target ?= scope:recipient
							}
						}
						random_character_active_contract = {
							limit = {
								has_task_contract_type = laamp_steal_artifact_contract
								var:task_contract_target ?= scope:recipient
							}
							save_scope_as = scheme_contract
						}
						# Success.
						if = {
							limit = { scope:agent_focus_success ?= yes }
							begin_contract_scheme_with_agents_effect = {
								SCHEME_TYPE = steal_back_artifact
								TARGET_TYPE = target_character
								TARGET_SCOPE = scope:recipient
								TASK_CONTRACT = scope:scheme_contract
								# Success.
								AGENT_1 = agent_thief
								AGENT_2 = agent_thief
								AGENT_3 = agent_thug
								# Speed.
								AGENT_4 = agent_infiltrator
								# Secrecy.
								AGENT_5 = agent_lookout
							}
						}
						# Speed.
						else_if = {
							limit = { scope:agent_focus_speed ?= yes }
							begin_contract_scheme_with_agents_effect = {
								SCHEME_TYPE = steal_back_artifact
								TARGET_TYPE = target_character
								TARGET_SCOPE = scope:recipient
								TASK_CONTRACT = scope:scheme_contract
								# Speed.
								AGENT_1 = agent_infiltrator
								AGENT_2 = agent_infiltrator
								AGENT_3 = agent_footpad
								# Success.
								AGENT_4 = agent_thief
								# Secrecy.
								AGENT_5 = agent_lookout
							}
						}
						# Secrecy.
						else_if = {
							limit = { scope:agent_focus_secrecy ?= yes }
							begin_contract_scheme_with_agents_effect = {
								SCHEME_TYPE = steal_back_artifact
								TARGET_TYPE = target_character
								TARGET_SCOPE = scope:recipient
								TASK_CONTRACT = scope:scheme_contract
								# Secrecy.
								AGENT_1 = agent_lookout
								AGENT_2 = agent_alibi
								AGENT_3 = agent_decoy
								# Success.
								AGENT_4 = agent_thief
								# Speed.
								AGENT_5 = agent_infiltrator
							}
						}
						# Balanced.
						else = {
							begin_contract_scheme_with_agents_effect = {
								SCHEME_TYPE = steal_back_artifact
								TARGET_TYPE = target_character
								TARGET_SCOPE = scope:recipient
								TASK_CONTRACT = scope:scheme_contract
								# Success.
								AGENT_1 = agent_thief
								AGENT_2 = agent_thief
								# Speed.
								AGENT_3 = agent_infiltrator
								AGENT_4 = agent_infiltrator
								# Secrecy.
								AGENT_5 = agent_lookout
							}
						}
					}
					else = {
						# Success.
						if = {
							limit = { scope:agent_focus_success ?= yes }
							begin_scheme_with_agents_effect = {
								SCHEME_TYPE = steal_back_artifact
								TARGET_TYPE = target_character
								TARGET_SCOPE = scope:recipient
								# Success.
								AGENT_1 = agent_thief
								AGENT_2 = agent_thief
								AGENT_3 = agent_thug
								# Speed.
								AGENT_4 = agent_infiltrator
								# Secrecy.
								AGENT_5 = agent_lookout
							}
						}
						# Speed.
						else_if = {
							limit = { scope:agent_focus_speed ?= yes }
							begin_scheme_with_agents_effect = {
								SCHEME_TYPE = steal_back_artifact
								TARGET_TYPE = target_character
								TARGET_SCOPE = scope:recipient
								# Speed.
								AGENT_1 = agent_infiltrator
								AGENT_2 = agent_infiltrator
								AGENT_3 = agent_footpad
								# Success.
								AGENT_4 = agent_thief
								# Secrecy.
								AGENT_5 = agent_lookout
							}
						}
						# Secrecy.
						else_if = {
							limit = { scope:agent_focus_secrecy ?= yes }
							begin_scheme_with_agents_effect = {
								SCHEME_TYPE = steal_back_artifact
								TARGET_TYPE = target_character
								TARGET_SCOPE = scope:recipient
								# Secrecy.
								AGENT_1 = agent_lookout
								AGENT_2 = agent_alibi
								AGENT_3 = agent_decoy
								# Success.
								AGENT_4 = agent_thief
								# Speed.
								AGENT_5 = agent_infiltrator
							}
						}
						# Balanced.
						else = {
							begin_scheme_with_agents_effect = {
								SCHEME_TYPE = steal_back_artifact
								TARGET_TYPE = target_character
								TARGET_SCOPE = scope:recipient
								# Success.
								AGENT_1 = agent_thief
								AGENT_2 = agent_thief
								# Speed.
								AGENT_3 = agent_infiltrator
								AGENT_4 = agent_infiltrator
								# Secrecy.
								AGENT_5 = agent_lookout
							}
						}
					}
					scope:new_scheme ?= {
						set_variable = {
							name = target_artifact
							value = scope:target
						}
					}
					show_as_tooltip = {
						stress_impact = {
							vengeful = medium_stress_impact_loss
							honest = minor_stress_impact_gain
							just = minor_stress_impact_loss
						}
					}
				}
			}
		}
	}
	
	# AI
	ai_potential = {
		is_imprisoned = no
		ai_greed >= low_negative_ai_value
		intrigue >= low_skill_rating
		has_outstanding_artifact_claims = yes
		NOT = {
			any_scheme = {
				OR = {
					scheme_type = murder
					scheme_type = abduct
					scheme_type = claim_throne
					scheme_type = fabricate_hook
					scheme_type = steal_back_artifact
				}
			}
		}
	}
	
	ai_target_quick_trigger = {
		adult = yes
	}
	ai_targets = {
		ai_recipients = scripted_relations
	}

	ai_targets = {
		ai_recipients = liege
	}
	ai_targets = {
		ai_recipients = neighboring_rulers
		ai_recipients = peer_vassals
		ai_recipients = nearby_domicile_owners
		max = 10
	}
	ai_targets = {
		ai_recipients = family
		max = 10
	}
	ai_targets = {
		ai_recipients = vassals
		max = 10
	}

	ai_frequency = 60

	ai_will_do = {
		base = -30
		# Factor for personality (excluding realism).
		modifier = {
			add = {
				value = ai_boldness
				multiply = -1
			}
		}
		modifier = {
			ai_vengefulness > 0
			add = ai_vengefulness
		}
		modifier = {
			add = {
				value = ai_compassion
				multiply = -0.25
			}
		}
		modifier = {
			scope:actor = {
				has_relation_rival = scope:recipient
			}
			add = 60
		}
		modifier = {
			scope:actor = {
				has_relation_nemesis = scope:recipient
			}
			add = 150
		}
		# Recipient is flaunting their artifacts and needs to be taken down a peg - from hold_court.3080
		modifier = {
			scope:recipient = {
				OR = {
					has_character_modifier = petition_event_artifact_exhibition_for_prestige
					has_character_modifier = petition_event_artifact_exhibition_for_gold
				}
			}
			add = 35
		}
		modifier = {
			scope:actor = {
				opinion = {
					target = scope:recipient
					value >= medium_positive_opinion
				}
				ai_greed <= high_positive_ai_value
			}
			factor = 0
		}
		modifier = {
			scope:recipient = {
				OR = {
					has_relation_friend = scope:actor
					has_relation_lover = scope:actor
				}
			}
			factor = 0
		}
		modifier = {
			scope:actor = {
				has_royal_court = no
			}
			scope:target = {
				OR = {
					artifact_slot_type = throne
					artifact_slot_type = wall_big
					artifact_slot_type = wall_small
					artifact_slot_type = sculpture
					artifact_slot_type = book
					artifact_slot_type = pedestal
				}
			}
			factor = 0
		}
		modifier = {
			scope:recipient = {
				OR = {
					AND = {
						scope:target = {
							artifact_slot_type = primary_armament
						}
						OR = {
							any_equipped_character_artifact = {
								artifact_slot_type = primary_armament
								rarity = illustrious
							}
							AND = {
								any_equipped_character_artifact = {
									artifact_slot_type = primary_armament
									rarity = famed
								}
								scope:target = {
									OR = {
										rarity = famed
										rarity = masterwork
										rarity = common
									}
								}
							}
							AND = {
								any_equipped_character_artifact = {
									artifact_slot_type = primary_armament
									rarity = masterwork
								}
								scope:target = {
									OR = {
										rarity = masterwork
										rarity = common
									}
								}
							}
							AND = {
								any_equipped_character_artifact = {
									artifact_slot_type = primary_armament
									rarity = common
								}
								scope:target = {
									rarity = common
								}
							}
						}
					}
					AND = {
						scope:target = {
							artifact_slot_type = regalia
						}
						OR = {
							any_equipped_character_artifact = {
								artifact_slot_type = regalia
								rarity = illustrious
							}
							AND = {
								any_equipped_character_artifact = {
									artifact_slot_type = regalia
									rarity = famed
								}
								scope:target = {
									OR = {
										rarity = famed
										rarity = masterwork
										rarity = common
									}
								}
							}
							AND = {
								any_equipped_character_artifact = {
									artifact_slot_type = regalia
									rarity = masterwork
								}
								scope:target = {
									OR = {
										rarity = masterwork
										rarity = common
									}
								}
							}
							AND = {
								any_equipped_character_artifact = {
									artifact_slot_type = regalia
									rarity = common
								}
								scope:target = {
									rarity = common
								}
							}
						}	
					}
					AND = {
						scope:target = {
							artifact_slot_type = helmet
						}
						OR = {
							any_equipped_character_artifact = {
								artifact_slot_type = helmet
								rarity = illustrious
							}
							AND = {
								any_equipped_character_artifact = {
									artifact_slot_type = helmet
									rarity = famed
								}
								scope:target = {
									OR = {
										rarity = famed
										rarity = masterwork
										rarity = common
									}
								}
							}
							AND = {
								any_equipped_character_artifact = {
									artifact_slot_type = helmet
									rarity = masterwork
								}
								scope:target = {
									OR = {
										rarity = masterwork
										rarity = common
									}
								}
							}
							AND = {
								any_equipped_character_artifact = {
									artifact_slot_type = helmet
									rarity = common
								}
								scope:target = {
									rarity = common
								}
							}
						}	
					}
					AND = {
						scope:target = {
							artifact_slot_type = armor
						}
						OR = {
							any_equipped_character_artifact = {
								artifact_slot_type = armor
								rarity = illustrious
							}
							AND = {
								any_equipped_character_artifact = {
									artifact_slot_type = armor
									rarity = famed
								}
								scope:target = {
									OR = {
										rarity = famed
										rarity = masterwork
										rarity = common
									}
								}
							}
							AND = {
								any_equipped_character_artifact = {
									artifact_slot_type = armor
									rarity = masterwork
								}
								scope:target = {
									OR = {
										rarity = masterwork
										rarity = common
									}
								}
							}
							AND = {
								any_equipped_character_artifact = {
									artifact_slot_type = armor
									rarity = common
								}
								scope:target = {
									rarity = common
								}
							}
						}
					}
					AND = {
						scope:target = {
							artifact_slot_type = miscellaneous
							rarity = common
						}
						any_equipped_character_artifact = {
							count >= 4
							artifact_slot_type = miscellaneous
						}
					}
					AND = {
						scope:target = {
							artifact_slot_type = throne
						}
						OR = {
							any_equipped_character_artifact = {
								artifact_slot_type = throne
								rarity = illustrious
							}
							AND = {
								any_equipped_character_artifact = {
									artifact_slot_type = throne
									rarity = famed
								}
								scope:target = {
									OR = {
										rarity = famed
										rarity = masterwork
										rarity = common
									}
								}
							}
							AND = {
								any_equipped_character_artifact = {
									artifact_slot_type = throne
									rarity = masterwork
								}
								scope:target = {
									OR = {
										rarity = masterwork
										rarity = common
									}
								}
							}
							AND = {
								any_equipped_character_artifact = {
									artifact_slot_type = throne
									rarity = common
								}
								scope:target = {
									rarity = common
								}
							}
						}
					}
					AND = {
						scope:target = {
							artifact_slot_type = wall_big
							rarity = common
						}
						any_equipped_character_artifact = {
							count >= 3
							artifact_slot_type = wall_big
						}
					}
					AND = {
						scope:target = {
							artifact_slot_type = wall_small
							rarity = common
						}
						any_equipped_character_artifact = {
							count >= 3
							artifact_slot_type = wall_small
						}
					}
					AND = {
						scope:target = {
							artifact_slot_type = sculpture
							rarity = common
						}
						any_equipped_character_artifact = {
							count >= 2
							artifact_slot_type = sculpture
						}
					}
					AND = {
						scope:target = {
							artifact_slot_type = book
							rarity = common
						}
						any_equipped_character_artifact = {
							count >= 2
							artifact_slot_type = book
						}
					}
					AND = {
						scope:target = {
							artifact_slot_type = pedestal
							rarity = common
						}
						any_equipped_character_artifact = {
							count >= 4
							artifact_slot_type = pedestal
						}
					}
				}
			}
			factor = 0
		}
		start_hostile_scheme_ai_base_modifiers = yes # At the end so Cowed can block it completely
	}

	auto_accept = yes
}

buy_artifact_claim = {
	category = interaction_category_diplomacy
	common_interaction = yes
	ignores_pending_interaction_block = yes
	icon = artisan_inspiration

	target_type = artifact
	target_filter = recipient_artifacts 

	is_shown = {
		# interaction locked behind Accomplished Forger perk from the Diplomacy lifestyle
		scope:actor = {
			has_perk = accomplished_forger_perk
			is_landless_adventurer = no
		}
		NOR = {
			# Can't buy from yourself
			scope:recipient = scope:actor
			# Can't buy from one of your prisoners
			scope:recipient = { is_imprisoned_by = scope:actor }
		}
		scope:recipient = {
			in_diplomatic_range = scope:actor
			any_character_artifact = {
				exists = this
				scope:actor = {
					NOT = { has_personal_artifact_claim = prev }
				}
				NOR = {
					# maybe? nah. we can't.
					has_variable = pope_hat
					# This is the only way I have found to exclude dynastic banners
					artifact_type = wall_big
				}
			}
		}
	}

	can_be_picked = {
		scope:target = {
			NOR = {
				# can't already have a claim on the artifact
				scope:actor = { has_personal_artifact_claim = prev }
				# no pope hats or dynastic banners
				has_variable = pope_hat
				artifact_type = wall_big
			}
		}
	}

	is_valid_showing_failures_only = {
		# Can't buy an artifact claim against yourself or one of your prisoners
		NOR = {
			scope:recipient = scope:actor
			scope:recipient = { is_imprisoned_by = scope:actor }
		}
		scope:recipient = {
			# needs to have an artifact
			any_character_artifact = { 
				exists = this
				# actor can't already have a claim on said artifact
				scope:actor = {
					NOT = { has_personal_artifact_claim = prev }
				}
			}
			is_busy_in_events_localised = yes
		}

		# Claim costs are calculated with scripted values located 00_lifestyle_values. The piety interaction costs copy those used for the regular Buy Claim interaciton and the prestige costs are calculated according to the same method.

		# Checks to determine piety cost for Religious Artifacts
		trigger_if = {
			limit = {
				exists = scope:target.var:relic
				scope:target = { rarity = common }
			}
			scope:actor = { piety >= minor_buy_claim_piety_value }
		}
		trigger_else_if = {
			limit = {
				exists = scope:target.var:relic
				scope:target = { rarity = masterwork }
			}
			scope:actor = { piety >= medium_buy_claim_piety_value }
		}
		trigger_else_if = {
			limit = {
				exists = scope:target.var:relic
				scope:target = { rarity = famed }
			}
			scope:actor = { piety >= major_buy_claim_piety_value }
		}
		trigger_else = {
			limit = {
				exists = scope:target.var:relic
				scope:target = { rarity = illustrious }
			}
			scope:actor = { piety >= massive_buy_claim_piety_value }
		}

		# Checks to determine prestige cost for regular artifacts
		trigger_if = {
			limit = {
				exists = scope:target
				NOT = { exists = scope:target.var:relic }
				scope:target = { rarity = common }
			}
			scope:actor = { prestige >= minor_buy_claim_prestige_value }
		}
		trigger_else_if = {
			limit = {
				exists = scope:target
				NOT = { exists = scope:target.var:relic }
				scope:target = { rarity = masterwork }
			}
			scope:actor = { prestige >= medium_buy_claim_prestige_value }
		}
		trigger_else_if = {
			limit = {
				exists = scope:target
				NOT = { exists = scope:target.var:relic }
				scope:target = { rarity = famed }
			}
			scope:actor = { prestige >= major_buy_claim_prestige_value }
		}
		trigger_else = {
			limit = {
				exists = scope:target
				NOT = { exists = scope:target.var:relic }
				scope:target = { rarity = illustrious }
			}
			scope:actor = { prestige >= massive_buy_claim_prestige_value }
		}
	}

	desc = buy_artifact_claim_desc

	auto_accept = yes

	on_accept = {
		# If it's a religous artifact...
		if = {
			limit = {
				exists = scope:target.var:relic
			}
			# Toast to the actor
			scope:actor = {
				send_interface_toast = {
					type = event_artifact_good
					title = bought_artifact_claim.t
					left_icon = scope:recipient
					right_icon = scope:target
					# Determine piety cost
					if = {
						limit = {
							exists = scope:target.var:relic
							scope:target = { rarity = common }
						}
						scope:actor = { add_piety = minor_buy_claim_piety_loss }
					}
					else_if = {
						limit = {
							exists = scope:target.var:relic
							scope:target = { rarity = masterwork }
						}
						scope:actor = { add_piety = medium_buy_claim_piety_loss }
					}
					else_if = {
						limit = {
							exists = scope:target.var:relic
							scope:target = { rarity = famed }
						}
						scope:actor = { add_piety = major_buy_claim_piety_loss }
					}
					else_if = {
						limit = {
							exists = scope:target.var:relic
							scope:target = { rarity = illustrious }
						}
						scope:actor = { add_piety = massive_buy_claim_piety_loss }
					}
					add_personal_artifact_claim = scope:target
				}
			}
			# Toast to the recipient
			scope:recipient = {
				send_interface_message = {
					type = event_artifact_bad_text
					title = sold_artifact_claim.t
					desc = sold_artifact_claim.desc
					left_icon = scope:actor
					right_icon = scope:target
				}
			}
		}
		# If it's not a religous artifact...
		else = {
			scope:actor = {
				send_interface_toast = {
					type = event_artifact_bad
					title = bought_artifact_claim.t
					left_icon = scope:recipient
					right_icon = scope:target
					# Determine prestige cost
					if = {
						limit = {
							exists = scope:target
							scope:target = { rarity = common }
						}
						scope:actor = { add_prestige = minor_buy_claim_prestige_loss }
					}
					else_if = {
						limit = {
							exists = scope:target
							scope:target = { rarity = masterwork }
						}
						scope:actor = { add_prestige = medium_buy_claim_prestige_loss }
					}
					else_if = {
						limit = {
							exists = scope:target
							scope:target = { rarity = famed }
						}
						scope:actor = { add_prestige = major_buy_claim_prestige_loss }
					}
					else_if = {
						limit = {
							exists = scope:target
							scope:target = { rarity = illustrious }
						}
						scope:actor = { add_prestige = massive_buy_claim_prestige_loss}
					}
					add_personal_artifact_claim = scope:target
				}
			}
			
			scope:recipient = {
				send_interface_message = {
					type = event_artifact_bad_text
					title = sold_artifact_claim.t
					desc = sold_artifact_claim.desc
					left_icon = scope:actor
					right_icon = scope:target
				}
			}
		}
		scope:actor = {
			stress_impact = {
				just = medium_stress_impact_gain
				honest = medium_stress_impact_gain
			}
		}
		scope:recipient = {
			add_opinion = {
				target = scope:actor
				modifier = claimed_my_artifact_opinion
				opinion = -40
			}
			# Recipient grows closer to forming a rivalry with the actor
			if = {
				limit = {
					can_set_relation_potential_rival_trigger = { 
						CHARACTER = scope:actor
					}
				}
				set_relation_potential_rival = scope:actor
			}
		}

		# If we're a clan this interaction affects unity
		add_clan_unity_interaction_effect = {
			CHARACTER = scope:actor
			TARGET = scope:recipient
			VALUE = minor_unity_loss
			DESC = clan_unity_bought_artifact_claim.desc
			REVERSE_NON_HOUSE_TARGET = no
		}
	}

	# AI STUFF
	ai_target_quick_trigger = {
		adult = yes
	}

	ai_targets = {
		# Only want AI to target neighbors
		ai_recipients = neighboring_rulers
		ai_recipients = nearby_domicile_owners
	}

	ai_frequency = 30

	ai_potential = {
		# The basic requirements
		is_imprisoned = no 
		is_playable_character = yes 
		is_available_ai_adult = yes

		# They must be well supplied
		prestige > major_prestige_value
		piety > major_piety_value

		# Only really greedy AI characters get to use this
		ai_greed >= high_positive_ai_value
	}

	ai_will_do = {
		base = 30

		# Unity modifiers
		evaluate_action_decreasing_house_unity = {
			VALUE = 100
		}

		# Make it more likely for AI characters to buy claims if they have a royal court
		modifier = {
			scope:actor = {
				has_royal_court = yes 
				has_dlc_feature = court_artifacts
			}
			factor = 2
		}

		# Prevent AI from buying artifact claims for court artifacts if they don't have a royal court
		modifier = {
			scope:actor = {
				has_royal_court = no
			}
			scope:target = {
				OR = {
					artifact_slot_type = throne
					artifact_slot_type = wall_big
					artifact_slot_type = wall_small
					artifact_slot_type = sculpture
					artifact_slot_type = book
					artifact_slot_type = pedestal
				}
			}
			factor = 0
		}

		# AI won't buy claims on artifacts owned by their lovers or friends
		modifier = {
			scope:recipient = {
				OR = {
					has_relation_friend = scope:actor
					has_relation_lover = scope:actor
#					is_close_or_extended_family_of = scope:actor
				}
			}
			factor = 0
		}
	}
}

# Demand an artifact you have a claim on
demand_dynasty_banner_interaction = {
	icon = icon_dynasty
	category = interaction_category_diplomacy
	common_interaction = yes
	interface_priority = 60
	use_diplomatic_range = yes
	desc = demand_dynasty_banner_interaction_desc

	target_type = artifact
	target_filter = recipient_artifacts

	greeting = negative
	notification_text = DEMAND_ARTIFACT_PROPOSAL

	answer_accept_key = DEMAND_ARTIFACT_ACCEPT
	answer_reject_key = DEMAND_ARTIFACT_REJECT

	ai_targets = {
		ai_recipients = scripted_relations
	}
	ai_targets = {
		ai_recipients = liege
	}
	ai_targets = {
		ai_recipients = neighboring_rulers
		ai_recipients = peer_vassals
		ai_recipients = nearby_domicile_owners
		max = 10
	}
	ai_targets = {
		ai_recipients = vassals
		max = 10
	}
	ai_targets = {
		ai_recipients = family
		max = 10
	}
	ai_target_quick_trigger = {
		adult = yes
	}
	ai_frequency = 60

	is_shown = {
		NOT = {
			scope:recipient = scope:actor
		}
		NOT = { #Landless have no court in which to display such a banner, and no real authority over a landed relative
			scope:actor = { government_has_flag = government_is_landless_adventurer }
		}
		exists = scope:actor.dynasty
		exists = scope:recipient.dynasty
		scope:recipient.dynasty = scope:actor.dynasty
		scope:recipient = {
			# needs to have a banner of our dynasty
			any_character_artifact = {
				AND = {
					exists = var:banner_dynasty
					var:banner_dynasty = scope:recipient.dynasty
					var:banner_dynasty.dynast = scope:actor
				}
			}
		}
	}
	
	is_highlighted = {
		always = yes
	}

	is_valid_showing_failures_only = {

		scope:recipient = { is_busy_in_events_localised = yes }
		
		scope:actor = {
			NOT = {
				is_at_war_with = scope:recipient
			}
			is_imprisoned = no
		}
		trigger_if = {
			limit = { exists = scope:target }
			custom_description = {
				text = "demand_dynasty_banner_artifact_tt"
				exists = scope:target.var:banner_dynasty
				scope:target.var:banner_dynasty = scope:recipient.dynasty
				scope:actor = scope:target.var:banner_dynasty.dynast
			}
		}
	}

	on_accept = {
		scope:target = {
			save_scope_as = demanded_artifact
		}
		if = {
			limit = {
				exists = scope:demanded_artifact
			}
			scope:actor = {
				set_variable = {
					name = demanded_this_artifact_interaction_recently
					value = scope:demanded_artifact
					years = 5
				}
			}
		}
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_good
				title = demand_artifact_interaction_notification
				left_icon = scope:recipient
				right_icon = scope:target
				scope:target = {
					set_owner = scope:actor
				}
			}
		}
		if = {
			limit = {
				scope:actor = {
					is_ai = yes
				}
			}
			scope:actor = {
				add_opinion = {
					target = scope:recipient
					modifier = pleased_opinion
					opinion = 30
				}
			}
		}

		# If we're a clan this interaction affects unity
		add_clan_unity_interaction_effect = {
			CHARACTER = scope:actor
			TARGET = scope:recipient
			VALUE = minor_unity_gain
			DESC = clan_unity_received_banner.desc
			REVERSE_NON_HOUSE_TARGET = no
		}
	}

	on_decline = {
		scope:target = {
			save_scope_as = demanded_artifact
		}
		if = {
			limit = {
				exists = scope:demanded_artifact
			}
			scope:actor = {
				set_variable = {
					name = demanded_this_artifact_interaction_recently
					value = scope:demanded_artifact
					years = 5
				}
			}
		}
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_bad
				title = demand_artifact_interaction_notification
				left_icon = scope:recipient
				right_icon = scope:target
				custom_tooltip = demand_artifact_interaction_notification_refused

				scope:recipient = {
					add_opinion = {
						target = scope:actor
						modifier = insult_opinion
						opinion = -10
					}
				}
			}
		}
		if = {
			limit = {
				scope:actor = {
					is_ai = yes
				}
			}
			scope:actor = {
				add_opinion = {
					target = scope:recipient
					modifier = refusal_opinion
					opinion = -10
				}
			}
		}

		# If we're a clan this interaction affects unity
		add_clan_unity_interaction_effect = {
			CHARACTER = scope:actor
			TARGET = scope:recipient
			VALUE = minor_unity_loss
			DESC = clan_unity_refused_banner.desc
			REVERSE_NON_HOUSE_TARGET = no
		}
	}

	auto_accept = {
		custom_description = {
			text = "spending_hook"
			subject = scope:actor
			object = scope:recipient
			scope:hook = yes
			scope:actor = { has_strong_hook = scope:recipient }
		}
	}
	
	send_option = {
		is_shown = {
			NOT = { scope:actor = scope:recipient }
		}
		is_valid = {
			scope:actor = {
				has_usable_hook = scope:recipient
			}
		}
		flag = hook
		localization = GENERIC_SPEND_A_HOOK
	}
	should_use_extra_icon = {
		scope:actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	send_options_exclusive = no
	
	ai_accept = {
		base = 100
		modifier = {
			add = 70
			scope:actor.max_military_strength > scope:recipient.max_military_strength
			desc = ARTIFACT_MILITARY_STRONGER_REASON
		}
		modifier = {
			add = -70
			scope:actor.max_military_strength < scope:recipient.max_military_strength
			desc = ARTIFACT_MILITARY_WEAKER_REASON
		}
		modifier = {
			add = {
				value = ai_boldness
				multiply = -1
				divide = 2
			}
			NOT = { ai_boldness = 0 }
			desc = ARTIFACT_BOLDNESS_REASON
		}
		modifier = {
			add = -50
			scope:actor = {
				has_relation_rival = scope:recipient
			}
			desc = ARTIFACT_RIVAL_REASON
		}
		modifier = {
			add = -80
			scope:actor = {
				has_relation_nemesis = scope:recipient
			}
			desc = ARTIFACT_NEMESIS_REASON
		}
		modifier = {
			add = 50
			scope:recipient = {
				target_is_liege_or_above = scope:actor
			}
			desc = ARTIFACT_LIEGE_REASON
		}
		modifier = {
			scope:hook = yes
			add = 100
			desc = SCHEME_WEAK_HOOK_USED
		}
		# Unity modifiers
		evaluate_action_increasing_house_unity = {
			VALUE = 100
		}
	}
	
	ai_potential = {
		is_adult = yes
		is_at_war = no
		ai_greed >= low_negative_ai_value
		has_outstanding_artifact_claims = yes
	}


	
	ai_min_reply_days = 7
	ai_max_reply_days = 14
	
	ai_will_do = {
		base = 100
		
		modifier = { # The AI will only use a Hook if they couldn't otherwise do this
			scope:hook = yes
			add = -1
		}

		modifier = {
			add = 50
			has_relation_rival = scope:recipient
		}
		modifier = {
			add = 80
			has_relation_nemesis = scope:recipient
		}
		modifier = {
			add = 50
			target_is_liege_or_above = scope:recipient
		}
		modifier = { # An Intimidated character is very unlikely to raise their hand
			add = -25
			scope:actor = {
				has_dread_level_towards = {
					target = scope:recipient
					level = 1
				}
			}
		}
		# Unity modifiers
		evaluate_action_increasing_house_unity = {
			VALUE = 100
		}
		modifier = { # A Cowed character will never take this interaction
			factor = 0
			scope:actor = {
				has_dread_level_towards = {
					target = scope:recipient
					level = 2
				}
			}
		}
		modifier = {
			scope:recipient = {
				OR = {
					has_relation_friend = scope:actor
					has_relation_lover = scope:actor
				}
			}
			factor = 0
		}
	}
}

# 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 = {
		custom_tooltip = {
			text = artifact_is_related_to_contract_tt
			NOT = {
				scope:target = { has_variable = 1025_treasure_map }
			}
		}
	}

	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 }
			}
		}
		scope:actor = {
			trigger_if = {
				limit = { is_landless_adventurer = yes }
				employs_court_position = armorer_camp_officer
			}
		}
	}

	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
				}
			}
		}
	}
}
