﻿#From \common\character_interactions\00_artifact_interactions.txt

# 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_targets = {
		ai_recipients = liege
	}
	ai_targets = {
		ai_recipients = spouses
	}
	ai_targets = {
		ai_recipients = neighboring_rulers
		ai_recipients = peer_vassals
		max = 10
	}
	ai_targets = {
		ai_recipients = vassals
		max = 10
	}
	ai_targets = {
		ai_recipients = children
		max = 10
	}
	ai_targets = {
		ai_recipients = family
		max = 20
	}
	ai_targets = {
		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
			}
		}
	}
	#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
		}
		
        #Modded with code thanks to CirclePete, dynasty banners can only be gifted to dynasty head
		trigger_if = {
            limit = {
                exists = scope:target.var:banner_dynasty
				#Modded to test, new vanilla line
				#exists = scope:recipient.dynasty
            }
            custom_description = {
                text = "gift_artifact_dynasty_banner_head_tt"
                scope:recipient = scope:target.var:banner_dynasty.dynast
            }
        }
		
		#Modded to prevent AI gifting artifacts the recipient can not use like religious artifacts from different religions
		trigger_if = {
			limit = {
				exists = scope:target
				scope:actor = {
					#Modded change to test
					is_ai = yes
				}
				scope:recipient = {
					NOT = {
						can_benefit_from_artifact = scope:target
					}
				}
			}
			custom_description = {
				text = "demand_artifact_no_ai"
				exists = scope:demanded_artifact
			}
		}
	}

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

		scope:target = {
			set_variable = suppress_artifact_notifications
			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_generic_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 = { remove_house_artifact_claim = scope:target }
						}
					}
				}
				scope:target = {
					set_owner = scope:recipient
				}
				stress_impact = {
					greedy = medium_stress_impact_gain
				}
				if = {
					limit = {
						scope:recipient = { is_ai = yes }
					}
					reverse_add_opinion = {
						target = scope:recipient
						modifier = gift_artifact_opinion
						opinion = gift_artifact_opinion
					}
				}
			}

			# 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_generic_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
							}
						}
					}
				}
				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
				}
			}
		}
	}
	
	ai_potential = {
		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
						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
				}
			}
		}
		
		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
		max = 10
	}
	ai_targets = {
		ai_recipients = vassals
		max = 10
	}
	ai_targets = {
		ai_recipients = family
		max = 10
	}
	ai_target_quick_trigger = {
		adult = yes
	}
	#Modded to 15 years (180 months) from 5 years (60 months)
	ai_frequency = 180

	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 = {
			#Modded to fix vanilla interaction as a per artifact block, not global per character
			limit = {
				#scope:actor = {
				#	has_variable = demanded_this_artifact_interaction_recently
				#}
				#Modded to scope:target. The scope:target = { save_scope_as scope:demanded_arifact } isn't set until line 637 of vanilla (line 146 here)
				exists = scope:target
				scope:actor = {
					has_variable = demanded_this_artifact_interaction_recently
					var:demanded_this_artifact_interaction_recently = scope:target
				}
			}
			custom_description = {
				text = "demand_artifact_interaction_is_valid_tt_2"
				exists = scope:target
				scope:actor = {
					has_variable = demanded_this_artifact_interaction_recently
					var:demanded_this_artifact_interaction_recently = scope:demanded_artifact
				}
			}
		}
		#Couldn't get it to work with either target or recipent variables :(
		#trigger_if = {
			#Modded added relinquished artifact block (see lines 150-173) with same fix to vanilla  interaction as a per artifact block, not global per character
		#	limit = {
		#		exists = scope:target
		#		scope:target = {
		#			has_variable = relinquished_by_value
		#			#var:relinquished_by_value = scope:actor
		#		}
		#	}
		#	custom_description = {
		#		text = "relinquished_artifact_interaction_is_valid"
		#		exists = scope:target
		#		scope:target = {
		#			has_variable = relinquished_by_value
		#			var:relinquished_by_value = scope:actor
		#		}			
		#	}
		#}
		
		#TODO
		#Try using can_be_picked_artifact trigger
		
		#Modded to prevent house claims on same dynasty with personal claim
		trigger_if = {
			limit = {
				scope:actor.dynasty = scope:recipient.dynasty
				exists = scope:target
				scope:actor = {
					NOT = {
						has_personal_artifact_claim = scope:target
					}
				}
				scope:actor.house = {
					has_house_artifact_claim = scope:target
				}
				scope:recipient.house = {
					has_house_artifact_claim = scope:target
				}	
			}
			custom_description = {
				text = "demand_artifact_interaction_house_claim_same_dynasty"
				exists = scope:demanded_artifact
			}
		}
		
		#Modded to prevent AI asking for artifacts it can not use, like dynasty banners from dynasties it doesn't belong to, or religious artifacts from different religions
		trigger_if = {
			limit = {
				exists = scope:target
				scope:actor = {
					#Modded change to test
					is_ai = yes
					NOT = {
						can_benefit_from_artifact = scope:target
					}
				}
			}
			custom_description = {
				text = "demand_artifact_no_ai"
				exists = scope:demanded_artifact
			}			
		}
		
		scope:actor = { is_imprisoned = no }
	}

	on_accept = {
		scope:target = {
			save_scope_as = demanded_artifact
		}
		#Modded. Comment: Why is this needed on acceptance other than to be used as a global character block on any use of the interaction not just per-artifact, should be on recipient to prevent asking for return immeadiatley?
		if = {
			limit = {
				exists = scope:demanded_artifact
			}
			scope:actor = {
				set_variable = {
					name = demanded_this_artifact_interaction_recently
					value = scope:demanded_artifact
					years = 5
				}
			}
		}
		#Couldn't get it to work with either target or recipient variables :(
		#Modded to make it apply to recipient to prevent asking for it back for 30 years after giving it away
		#if = {
		#	limit = {
		#		exists = scope:demanded_artifact
		#	}
		#	scope:demanded_artifact = {
		#		set_variable = {
		#			name = relinquished_by_value
		#			value = scope:recipient
		#			years = 5
		#			#years = relinquished_years
		#		}
		#	}
		#}
		scope:actor = {
			send_interface_toast = {
				type = event_generic_neutral
				title = demand_artifact_interaction_notification
				left_icon = scope:recipient
				right_icon = scope:target
				scope:target = {
					set_owner = scope:actor
				}				
				#Modded to tier opinion based on artifact rarity
				if = {
					limit = {
						scope:demanded_artifact = {
							rarity = illustrious
						}
					}
					scope:recipient = {
						add_opinion = {
							target = scope:actor
							modifier = insult_opinion
							opinion = -60
						}
					}
				}
				if = {
					limit = {
						scope:demanded_artifact = {
							rarity = famed
						}
					}
					scope:recipient = {
						add_opinion = {
							target = scope:actor
							modifier = insult_opinion
							opinion = -40
						}
					}
				}
				if = {
					limit = {
						scope:demanded_artifact = {
							rarity = masterwork
						}
					}
					scope:recipient = {
						add_opinion = {
							target = scope:actor
							modifier = insult_opinion
							opinion = -20
						}
					}
				}
				if = {
					limit = {
						scope:demanded_artifact = {
							rarity = common
						}
					}
					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
					}
				}
			}
		}
		#Modded to tier opinion based on artifact rarity
		if = {
			limit = {
				scope:actor = {
					is_ai = yes
				}
				scope:demanded_artifact = {
					rarity = illustrious
				}
			}
			scope:actor = {
				add_opinion = {
					target = scope:recipient
					modifier = pleased_opinion
					opinion = 60
				}
			}
		}
		if = {
			limit = {
				scope:actor = {
					is_ai = yes
				}
				scope:demanded_artifact = {
					rarity = famed
				}
			}
			scope:actor = {
				add_opinion = {
					target = scope:recipient
					modifier = pleased_opinion
					opinion = 40
				}
			}
		}
		if = {
			limit = {
				scope:actor = {
					is_ai = yes
				}
				scope:demanded_artifact = {
					rarity = masterwork
				}
			}
			scope:actor = {
				add_opinion = {
					target = scope:recipient
					modifier = pleased_opinion
					opinion = 20
				}
			}
		}
		if = {
			limit = {
				scope:actor = {
					is_ai = yes
				}
				scope:demanded_artifact = {
					rarity = common
				}
			}
			scope:recipient = {
				add_opinion = {
					target = scope:recipient
					modifier = pleased_opinion
					opinion = 10
				}
			}
		}
	}

	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
		}
	}
	
	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
		}
		#Modded to put 30 year limit on AI making demands
		#Only works for the last artifact declined unless turned into a global character block on the interaction, not a per-artifact demand block
		if = {
			limit = {
				exists = scope:demanded_artifact
				scope:actor = { is_ai = no }
			}
			scope:actor = {
				set_variable = {
					name = demanded_this_artifact_interaction_recently
					value = scope:demanded_artifact
					years = 5
				}
			}
		}
		if = {
			limit = {
				exists = scope:demanded_artifact
				scope:actor = { is_ai = yes }
			}
			scope:actor = {
				set_variable = {
					name = demanded_this_artifact_interaction_recently
					value = scope:demanded_artifact
					years = 30
				}
			}
		}	
		scope:actor = {
			send_interface_toast = {
				type = event_generic_bad
				title = demand_artifact_interaction_notification
				left_icon = scope:recipient
				right_icon = scope:target
				custom_tooltip = demand_artifact_interaction_notification_refused

				#Modded to tier opinion based on artifact rarity
				if = {
					limit = {
						scope:demanded_artifact = {
							rarity = illustrious
						}
					}
					scope:recipient = {
						add_opinion = {
							target = scope:actor
							modifier = insult_opinion
							opinion = -60
						}
					}
				}
				if = {
					limit = {
						scope:demanded_artifact = {
							rarity = famed
						}
					}
					scope:recipient = {
						add_opinion = {
							target = scope:actor
							modifier = insult_opinion
							opinion = -40
						}
					}
				}
				if = {
					limit = {
						scope:demanded_artifact = {
							rarity = masterwork
						}
					}
					scope:recipient = {
						add_opinion = {
							target = scope:actor
							modifier = insult_opinion
							opinion = -20
						}
					}
				}
				if = {
					limit = {
						scope:demanded_artifact = {
							rarity = common
						}
					}
					scope:recipient = {
						add_opinion = {
							target = scope:actor
							modifier = insult_opinion
							opinion = -10
						}
					}
				}
			}
		}
		#Modded to tier opinion based on artifact rarity
		if = {
			limit = {
				scope:actor = {
					is_ai = yes
				}
				scope:demanded_artifact = {
					rarity = illustrious
				}
			}
			scope:actor = {
				add_opinion = {
					target = scope:recipient
					modifier = refusal_opinion
					opinion = -60
				}
			}
		}
		if = {
			limit = {
				scope:actor = {
					is_ai = yes
				}
				scope:demanded_artifact = {
					rarity = famed
				}
			}
			scope:actor = {
				add_opinion = {
					target = scope:recipient
					modifier = refusal_opinion
					opinion = -40
				}
			}
		}
		if = {
			limit = {
				scope:actor = {
					is_ai = yes
				}
				scope:demanded_artifact = {
					rarity = masterwork
				}
			}
			scope:actor = {
				add_opinion = {
					target = scope:recipient
					modifier = insult_opinion
					opinion = -20
				}
			}
		}
		if = {
			limit = {
				scope:actor = {
					is_ai = yes
				}
				scope:demanded_artifact = {
					rarity = common
				}
			}
			scope:recipient = {
				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
				}
			}
		}
		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 }

		#Modded to prevent AI asking for artifacts it can not use, like dynasty banners from dynasties it doesn't belong to, or religious artifacts from different religions
		trigger_if = {
			limit = {
				exists = scope:target
				scope:actor = {
					#Modded change to test
					is_ai = yes
					NOT = {
						can_benefit_from_artifact = scope:target
					}
				}
			}
			custom_description = {
				text = "demand_artifact_no_ai"
				exists = scope:demanded_artifact
			}			
		}		
	}

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

	on_decline = {
		# Scope:recipient declines processing.
		scope:actor = {
			# Inform them of the decline & scope:recipient loses some prestige.
			send_interface_toast = {
				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_nemesis = 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
		}
	}

	# 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
		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
				}
			}
		}
		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_hostile
	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_claimable
	
	is_shown = {
		NOR = {
			scope:recipient = scope:actor
			scope:recipient = { is_imprisoned_by = scope:actor }
		}
		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 = {
		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 = 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
					}
				}
			}
		}
		
		#Modded to prevent AI asking for artifacts it can not use, like dynasty banners from dynasties it doesn't belong to, or religious artifacts from different religions
		trigger_if = {
			limit = {
				exists = scope:target
				scope:actor = {
					#Modded change to test
					is_ai = yes
					NOT = {
						can_benefit_from_artifact = scope:target
					}
				}
			}
			custom_description = {
				text = "demand_artifact_no_ai"
				exists = scope:demanded_artifact
			}			
		}		
	}

	desc = {
		triggered_desc = {
			trigger = {
				scope:actor = {
					can_start_scheme = {
						type = steal_back_artifact
						target = scope:recipient
					}
				}
			}
			desc = scheme_interaction_tt_steal_back_artifact_approved
		}
	}

	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 = {
					title = start_stealing_back_artifact_notification

					left_icon = scope:actor					
					right_icon = scope:recipient

					start_scheme = {
						type = steal_back_artifact
						target = scope:recipient
						artifact = 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
		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
}