﻿offer_laamp_invasion_sponsorship_interaction = {
	common_interaction = no
	category = interaction_category_diplomacy
	interface_priority = 20
	cooldown_against_recipient = { years = 5 }
	can_send_despite_rejection = yes
	greeting = positive
	notification_text = offer_laamp_INVASION_SPONSORSHIP_PROPOSAL

	answer_accept_key = offer_laamp_INVASION_SPONSORSHIP_ACCEPT
	answer_reject_key = offer_laamp_INVASION_SPONSORSHIP_REJECT

	icon = request_invasion_sponsorship_interaction
	desc = offer_laamp_invasion_sponsorship_interaction_desc

	is_shown = {
		has_ep3_dlc_trigger = yes
		scope:recipient = { is_landless_adventurer = yes }
		scope:actor = { is_landed = yes }
		NOT = { scope:recipient = scope:actor }
		NOT = { scope:recipient = { has_realm_law = camp_purpose_legitimists } }
	}

	is_valid_showing_failures_only = {
		scope:recipient = {
			is_independent_ruler = yes
			custom_tooltip = {
				text = offer_laamp_invasion_sponsorship_existing_supporter_tt
				NOT = { exists = var:adventurer_invasion_supporter }
			}
			NOT = { is_at_war_with = scope:actor }
		}
		scope:actor = {
			is_independent_ruler = yes
			highest_held_title_tier >= tier_kingdom
			custom_tooltip = {
				text = offer_laamp_invasion_sponsorship_existing_supportee_tt
				NOT = { exists = var:adventurer_invasion_supportee }
			}
		}
		#Has to be used instead of diplo range checks in laamp to landed interactions
		loaa_ep3_laamp_diplo_range_trigger = {
			TARGET = scope:actor
			LAAMP = scope:recipient
		}
	}

	populate_recipient_list = {
		every_independent_ruler = {
			limit = {
				highest_held_title_tier >= tier_kingdom
				is_landed = yes
				in_diplomatic_range = scope:actor
				in_diplomatic_range = scope:recipient
				NOR = {
					is_at_war_with = scope:actor
					is_at_war_with = scope:recipient
					is_allied_to = scope:actor
					is_allied_to = scope:recipient
					has_truce = scope:actor
					has_truce = scope:recipient
					this = scope:actor
					this = scope:recipient
					government_has_flag = government_is_wastelands
					any_character_trait = {
						has_trait_flag = ruin_character
						has_trait_flag = wilderness_character
					}
				}
			}
			add_to_list = characters
		}
	}

	send_options_exclusive = no

	send_option = {
		flag = request_soldiers
		localization = offer_laamp_invasion_sponsorship_option_request_soldiers
		current_description = offer_laamp_invasion_sponsorship_option_request_soldiers_desc
		starts_enabled = { always = yes }
	}

	send_option = {
		flag = join_war
		localization = offer_laamp_invasion_sponsorship_option_join_war
		current_description = offer_laamp_invasion_sponsorship_option_join_war_desc
		is_valid = {
			scope:secondary_recipient ?= {
				# NOR = {
				# 	is_at_war_with = scope:recipient
				# 	is_allied_to = scope:recipient
				# 	has_truce = scope:recipient
				# }
				NOR = {
					is_at_war_with = scope:actor
					is_allied_to = scope:actor
					has_truce = scope:actor
				}
			}
		}
	}

	send_option = {
		flag = offer_gold
		localization = offer_laamp_invasion_sponsorship_option_offer_gold
		current_description = offer_laamp_invasion_sponsorship_option_offer_gold_desc
		is_shown = { exists = scope:recipient }
		is_valid = { scope:actor.gold >= scope:actor.request_laamp_invasion_sponsorship_gold_cost }
	}

	send_option = {
		flag = hook
		is_valid = {
			scope:actor = {
				has_usable_hook = scope:recipient
			}
		}
		localization = GENERIC_SPEND_A_HOOK
	}

	cost = {
		prestige = {
			value = massive_prestige_value
			if = {
				limit = { scope:join_war = yes }
				add = major_prestige_value
			}
		}
		gold = {
			value = 100
			if = {
				limit = { scope:request_soldiers = yes }
				add = 100
			}
			if = {
				limit = { scope:offer_gold = yes }
				add = scope:actor.request_laamp_invasion_sponsorship_gold_cost
			}
		}
	}

	can_send = {
		custom_tooltip = {
			text = offer_laamp_invasion_sponsorship_minimum_request_tt
			OR = {
				scope:join_war = yes
				scope:request_soldiers = yes
			}
		}
	}

	on_accept = {
		scope:recipient = { save_scope_as = adventurer }
		scope:actor ?= {
			if = {
				limit = {
					scope:request_soldiers = yes
					scope:join_war = yes
				}
				custom_tooltip = loaa_adventurer_invasion_supporter_tt
			}
			else_if = {
				limit = { scope:request_soldiers = yes }
				custom_tooltip = loaa_adventurer_invasion_supporter_soldiers_tt
			}
			else_if = {
				limit = { scope:join_war = yes }
				custom_tooltip = loaa_adventurer_invasion_supporter_join_tt
			}
			else = { custom_tooltip = offer_laamp_invasion_sponsorship_minimum_request_tt }
			hidden_effect = {
				set_variable = {
					name = adventurer_invasion_supportee
					value = scope:recipient
					years = 5
				}
				set_variable = {
					name = adventurer_invasion_target
					value = scope:secondary_recipient
					years = 5
				}
				if = {
					limit = { scope:join_war = yes }
					set_variable = {
						name = adventurer_invasion_join_war
						value = scope:recipient
						years = 5
					}
				}
				if = {
					limit = { scope:request_soldiers = yes }
					set_variable = {
						name = adventurer_invasion_request_soldiers
						value = scope:recipient
						years = 5
					}
				}
			}
		}
        scope:recipient = {
            custom_tooltip = {
				text = loaa_adventurer_invasion_supporter_victory_tt
				set_variable = {
					name = adventurer_invasion_supporter
					value = scope:actor
					years = 5
				}
				set_variable = {
					name = adventurer_invasion_target
					value = scope:secondary_recipient
					years = 5
				}
			}

        }
		scope:actor = {
			if = {
				limit = { scope:offer_gold = yes }
				pay_short_term_gold = {
					gold = scope:actor.request_laamp_invasion_sponsorship_gold_cost
					target = scope:recipient
				}
			}
			if = {
				limit = { scope:hook = yes }
				use_hook = scope:recipient
			}

			send_interface_message = {
				type = event_sponsorship_accepted
				title = loaa_sponsorship_accepted.tt
				desc = loaa_sponsorship_accepted.desc
				left_icon = scope:actor
				right_icon = scope:recipient
			}
		}
		scope:recipient = {
			if = {
				limit = { is_ai = yes }

				show_as_tooltip = {
					start_war = {
						casus_belli = ep3_laamp_adventurer_county_invasion
						#target = scope:actor.var:adventurer_invasion_target
						target = scope:secondary_recipient
						claimant = scope:recipient
						#target_title = scope:invasion_target_title
					}
				}

				trigger_event = { id = loaa_invasion_sponsorship_events.1 days = 2 }
			}
		}
	}

	on_decline = {
		#scope:actor = { trigger_event = ep3_laamps.0201 }
		scope:actor = {
			send_interface_message = {
				type = event_sponsorship_declined
				title = loaa_sponsorship_declined.tt
				left_icon = scope:actor
				right_icon = scope:recipient
			}
		}

	}

	use_diplomatic_range = yes

	ai_accept = {
		base = -25

		# Relationships: actor -> recipient / We avoid more relationship checks for balance reasons (and because important decisions tend to care little for relationships)
		modifier = { # Rivalry modifier.
			desc = offer_vassalization_interaction_aibehavior_rival_tt
			scope:recipient = {
				has_relation_rival = scope:actor
				NOT = { has_relation_nemesis = scope:actor }
			}
			add = -10
		}
		modifier = { # Nemesis modifier.
			desc = offer_vassalization_interaction_aibehavior_nemesis_tt
			scope:recipient = { has_relation_nemesis = scope:actor }
			add = -30
		}
		modifier = { # Same Dynasty modifier.
			desc = offer_vassalization_interaction_aibehavior_dynasty_tt
			scope:recipient.dynasty = scope:actor.dynasty
			add = 10
		}

		# Compare Opinion modifier
		opinion_modifier = {
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 0.5
		}
		opinion_modifier = {
			who = scope:recipient
			opinion_target = scope:secondary_recipient
			multiplier = -0.5
		}

		# AI who are in debt will take whatever windfalls they can.
		modifier = {
			add = {
				value = scope:recipient.debt_level
				add = 1 # Our first level is 0, so we add one to always get a positive number.
				multiply = 10
			}
			scope:offer_gold = yes
			scope:recipient.debt_level > 0
			desc = PT_AI_IS_IN_DEBT
		}

		# Pacifist AI don't like raiding
		modifier = {
			add = -25
			scope:recipient.faith = { has_doctrine_parameter = pacifist_opinion_active }
			desc = PT_AI_IS_PACIFIST_FAITH
		}
		modifier = {
			add = -25
			scope:recipient.culture = { has_cultural_parameter = reduced_cost_for_conversion_to_pacifist_faith }
			desc = PT_AI_IS_PACIFIST_CULTURE
		}

		modifier = {
			culture != scope:actor.culture
			"scope:recipient.culture.cultural_acceptance(scope:actor.culture)" < 50
			add = {
				value = 50
				subtract = "scope:recipient.culture.cultural_acceptance(scope:actor.culture)"
				multiply = -0.25
				round = yes
			}
			desc = CULTURAL_ACCEPTANCE
		}
		modifier = {
			culture != scope:actor.culture
			"scope:recipient.culture.cultural_acceptance(scope:actor.culture)" >= 50
			add = {
				value = "scope:recipient.culture.cultural_acceptance(scope:actor.culture)"
				subtract = 50
				multiply = 0.25
				round = yes
			}
			desc = CULTURAL_ACCEPTANCE
		}

		# Military strength
		modifier = {
			add = {
				value = scope:recipient.current_military_strength
				multiply = 0.5
				max = 100
			}
			desc = RECIPIENT_MILITARY_STRENGTH
		}

		modifier = {
			add = {
				value = scope:secondary_recipient.top_liege.current_military_strength
				multiply = -0.5
				min = -200
			}
			desc = SECONDARY_RECIPIENT_MILITARY_STRENGTH
		}

		# Own war
		modifier = {
			add = -1000
			scope:recipient = { is_at_war = yes }
			desc = offer_laamp_INVASION_SPONSORSHIP_OWN_WAR_REASON
		}

		modifier = { # You're my friend
			add = 10
			desc = youre_my_friend_tt
			has_relation_friend = scope:actor
		}


		modifier = { # Distance

			# Turned off due to incorrect calculations in several cases

			# add = {
			# 	value = 0
			# 	add = scope:distance
			# 	if = {
			# 		limit = { scope:distance >= squared_distance_medium }
			# 		add = scope:distance
			# 		multiply = -0.00001
			# 	}
			# 	min = -100
			# }
			desc = offer_laamp_INVASION_SPONSORSHIP_DISTANCE_REASON
			scope:actor = {
				NOR = {
					any_neighboring_top_liege_realm_owner = { this = scope:secondary_recipient }
					any_neighboring_top_liege_realm_owner = { this = scope:secondary_recipient.top_liege }
				}
			}
			add = -80
			# scope:actor.capital_county = {
			# 	save_temporary_scope_value_as = {
			# 		name = distance
			# 		value = "squared_distance(scope:secondary_recipient.capital_county)"
			# 	}
			# }
		}

		modifier = {
			add = -30
			scope:recipient.faith = scope:secondary_recipient.faith
			desc = SELF_I_AM_ATTACKING_A_CORELIGIONIST
		}
		modifier = {
			add = -10
			NOT = { scope:actor.faith = scope:recipient.faith }
			desc = DIFFERENT_FAITH
		}
		modifier = {
			add = -200
			scope:recipient.primary_heir ?= scope:secondary_recipient
			desc = WONT_FIGHT_HEIR_REASON
		}
		modifier = {
			add = -200
			scope:recipient = { is_consort_of = scope:secondary_recipient }
			desc = WONT_FIGHT_SPOUSE_REASON
		}
		modifier = {
			add = -100
			scope:recipient = {
				has_relation_friend = scope:secondary_recipient
				NOT = { has_relation_best_friend = scope:secondary_recipient }
			}
			desc = WONT_FIGHT_FRIEND_REASON
		}
		modifier = {
			add = -200
			scope:recipient = { has_relation_best_friend = scope:secondary_recipient }
			desc = WONT_FIGHT_BEST_FRIEND_REASON
		}
		modifier = {
			add = -100
			scope:recipient = {
				has_relation_lover = scope:secondary_recipient
				NOT = { has_relation_soulmate = scope:secondary_recipient }
			}
			desc = WONT_FIGHT_LOVER_REASON
		}
		modifier = {
			add = -200
			scope:recipient = { has_relation_soulmate = scope:secondary_recipient }
			desc = WONT_FIGHT_SOULMATE_REASON
		}
		modifier = {
			add = -200
			scope:recipient = { is_allied_to = scope:secondary_recipient }
			desc = WAR_WITH_ALLY_REASON
		}

		modifier = {
			add = 50
			scope:hook = yes
			desc = YOU_HAVE_HOOK_REASON
		}

		# Offered proportional gold
		modifier = {
			add = 50
			scope:request_soldiers = yes
			desc = offer_laamp_INVASION_SPONSORSHIP_REQUEST_SOLDIERS_REASON
		}
		modifier = {
			scope:join_war = yes
			add = {
				value = scope:actor.current_military_strength
				if = {
					limit = { scope:actor = { is_at_war = yes } }
				multiply = 0.25
				}
				else = {
					multiply = 0.5
				}
				min = 0
				max = 100
			}
			desc = offer_laamp_INVASION_SPONSORSHIP_JOIN_WAR_REASON
		}
		modifier = {
			add = 35
			scope:offer_gold = yes
			desc = GOLD_REASON
		}

		# AI value mod
		ai_value_modifier = {
			ai_greed = 0.5
			ai_boldness = 0.25
			min = 0
			max = 25
		}
	}
	can_send_despite_rejection = no
	ai_will_do = {
		base = 10
	}
}

challenge_for_dominance_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
	desc = challenge_for_dominance_interaction_desc

	greeting = negative
	notification_text = REQUEST_TRIAL_BY_COMBAT_TEXT

	is_shown = {
		# First, check for the perk.
		scope:actor = {
			can_challenge_rival_to_single_combat_trigger = yes
			is_landless_adventurer = yes
		}
		scope:recipient = {
			is_landless_adventurer = yes
		}

		# Can't duel yourself.
		NOT = { scope:actor = scope:recipient }
	}

	is_valid_showing_failures_only = {
		# Calc some stuff that might invalidate elsewhere before the bout is sorted.
		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 = {
			custom_description = {
				text = fp1_tbc_recipient_banned_from_combat
				can_start_single_combat_banned_checks_trigger = no
			}
		}
		# Neither of the characters can be imprisoned.
		scope:actor = { is_imprisoned = no }
		scope:recipient = { is_imprisoned = no }

		# Target must be close enough.
		custom_tooltip = {
			text = target_too_far_away
			scope:recipient.domicile.domicile_location ?= {
				squared_distance = {
					target = scope:actor.domicile.domicile_location
					value < loaa_adventurer_distance_value
				}
			}
		}
	}

	can_send = {
		scope:actor = {
			custom_description = {
				text = "character_interactions_hostile_actions_disabled_delay"
				NOT = { has_character_flag = flag_hostile_actions_disabled_delay }
			}
		}
	}

	cost = { prestige = medium_prestige_value }
	cooldown = { years = 3 }
	cooldown_against_recipient = { years = 5 }

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

	on_accept = {
		# Set up the bout immediately.
		## First inform.
		scope:actor = {
			custom_tooltip = challenge_for_dominance_interaction.enter_non_lethal_bout.tt
			custom_tooltip = challenge_for_dominance_interaction.victor_gets.tt
			custom_tooltip = challenge_for_dominance_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 = loaa_duel_events.1
			INVALIDATION_EVENT = loaa_duel_events.2
		}

		# If we're a clan this interaction affects unity
		if = {
			limit = {
				scope:actor = {
					exists = scope:actor.house
					house = { # But only if we have high unity!
						OR = {
							has_house_unity_stage = harmonious
							has_house_unity_stage = friendly
						}
					}
				}
			}
			add_clan_unity_interaction_effect = {
				CHARACTER = scope:actor
				TARGET = scope:recipient
				VALUE = medium_unity_loss
				DESC = clan_unity_challenge_to_combat.desc
				REVERSE_NON_HOUSE_TARGET = no
			}
			custom_description_no_bullet = { text = active_unity_level_description_tt }
		}
	}

	on_decline = {
		# Scope:actor decline processing.
		scope:actor = {
			# Inform them of the decline & scope:recipient loses some prestige.
			send_interface_toast = {
				type = event_toast_effect_bad
				title = challenge_for_dominance_interaction.challenge_rejected.t
				left_icon = scope:recipient
				right_icon = scope:actor
				scope:recipient = { add_prestige = medium_prestige_loss }
				show_as_tooltip = {
					add_prestige = medium_prestige_value
				}
			}
			hidden_effect = {
				add_prestige_no_experience = medium_prestige_value
			}
			# Cooldown is removed.
			hidden_effect = { remove_interaction_cooldown = challenge_for_dominance_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 = 0 # Try to make it 0 for most interactions

		# Relative fightan 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 = {
				if = {
					limit = {
						scope:recipient = {
							ai_boldness > 0
							ai_rationality < 0
						}
					}
					value = 2
				}
				else_if = {
					limit = {
						scope:recipient = {
							NOT = { ai_boldness = 0 }
						}
					}
					value = 1
				}
			}
			# ai_vengefulness = {
			# 	if = {
			# 		limit = {
			# 			scope:recipient = {
			# 				NOT = { ai_vengefulness = 0 }
			# 			}
			# 		}
			# 		value = 0.75
			# 	}
			# }
			ai_honor = {
				if = {
					limit = {
						scope:recipient = {
							ai_honor > 0
						}
					}
					value = 0.5
				}
			}
		}
		# Nemesis modifier.
		modifier = {
			desc = offer_vassalization_interaction_aibehavior_nemesis_tt
			trigger = {
				scope:recipient = {
					has_relation_nemesis = scope:actor
				}
			}
			add = 50
		}

		# Unity modifiers
		evaluate_action_decreasing_house_unity = {
			VALUE = 100
		}
	}

	# AI
	ai_potential = {
		can_challenge_rival_to_single_combat_trigger = yes
		NOT = { has_trait = craven }
		num_of_relation_rival > 0
		is_imprisoned = no
		can_start_single_combat_trigger = yes
	}

	ai_target_quick_trigger = {
		adult = yes
	}
	ai_targets = {
		ai_recipients = scripted_relations
	}

	ai_frequency = 60

	ai_will_do = {
		base = -50

		# Factor for personality (excluding realism).
		modifier = {
			add = {
				value = ai_boldness
				multiply = 1
			}
		}
		modifier = { add = ai_vengefulness }
		modifier = {
			add = {
				value = ai_energy
				multiply = -0.25
			}
		}

		# Unity modifiers
		evaluate_action_decreasing_house_unity = {
			VALUE = 100
		}

		# Don't challenge kinslayer-counting family, unless they're your nemesis.
		modifier = {
			scope:actor = {
				murdering_character_is_kinslaying_in_faith_trigger = {
					CHARACTER = scope:recipient
					FAITH = scope:actor.faith
				}
			}
			scope:recipient = {
				NOT = { has_relation_nemesis = scope:actor }
			}
			add = -1000
		}
		# 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
		}
	}
}

offer_contract = {
    common_interaction = no
    category = interaction_category_diplomacy
    interface_priority = 10

    greeting = positive
    notification_text = offer_contract_proposal

	icon = contract
    desc = offer_contract_interaction_desc

	cooldown_against_recipient = { years = 2 }
	can_send_despite_rejection = yes
	secondary_scopes_optional = no

	populate_recipient_list = {
		scope:actor = {
			add_to_list = characters
			liege ?= {
				add_to_list = characters
			}
			every_relation = {
				limit = {
					is_adult = yes
					is_landed = yes
					is_within_diplo_range = { CHARACTER = scope:actor }
					NOT = { government_has_flag = government_is_wastelands }
					NOT = {
						any_character_trait = {
							OR = {
								has_trait_flag = ruin_character
								has_trait_flag = wilderness_character
							}
						}
					}
				}
			}
			every_vassal = {
				limit = {
					is_ruler = yes
					is_landed = yes
					highest_held_title_tier >= tier_county
					NOT = { prev.faith.religious_head = this }
					NOT = { government_has_flag = government_is_wastelands }
					NOT = {
						any_character_trait = {
							OR = {
								has_trait_flag = ruin_character
								has_trait_flag = wilderness_character
							}
						}
					}
				}
				add_to_list = characters
			}
			every_neighboring_and_across_water_top_liege_realm_owner = {
				limit = {
					is_ruler = yes
					highest_held_title_tier >= tier_county
					NOT = { prev.faith.religious_head = this }
					NOT = { government_has_flag = government_is_wastelands }
					NOT = {
						any_character_trait = {
							OR = {
								has_trait_flag = ruin_character
								has_trait_flag = wilderness_character
							}
						}
					}
				}
				add_to_list = characters
			}
		}
	}

	on_send = {
		scope:recipient = { add_character_flag = offer_contract_sent }
	}

	# Can send
	can_send = {
		scope:actor = {
			trigger_if = {
				limit = {
					OR = {
						scope:contract_murder ?= yes
						scope:contract_abduct ?= yes
						scope:contract_raid_for_captives ?= yes
						scope:contract_pillage ?= yes
					}
				}
				custom_tooltip = {
					text = "unsuitable_target"

					NOT =  { scope:secondary_recipient = this }

				}
			}
			trigger_if = {
				limit = {
					OR = {
						scope:contract_protect_domain ?= yes
					}
				}
				custom_tooltip = {
					text = "already_protected_by_adventurer"
					NOT =  { scope:secondary_recipient = { has_variable = protect_domain_adventurer } }

				}
			}
			trigger_if = {
				limit = {
					OR = {
						scope:contract_conduct_census ?= yes
					}
				}
				custom_tooltip = {
					text = "only_self_targeting_contract"
					scope:secondary_recipient = scope:actor
				}

			}
			custom_tooltip = {
				text = "oc_no_option_selected"
				OR = {
					scope:contract_deliver_artifact ?= yes
					scope:contract_protect_domain ?= yes
					scope:contract_conduct_census ?= yes
					scope:contract_improve_reputation ?= yes
					scope:contract_murder ?= yes
					scope:contract_sabotage ?= yes
					scope:contract_abduct ?= yes
					scope:contract_raid_for_captives ?= yes
					scope:contract_pillage ?= yes
					scope:contract_support_faction ?= yes
				}
			}

		}
	}

    is_shown = {
        scope:actor = {
            is_alive = yes
            is_ruler = yes
			is_landed = yes
        }
        scope:recipient = {
            is_alive = yes
            is_landless_adventurer = yes # Recipient is a landless adventurer
        }
    }

    is_valid_showing_failures_only = {
		scope:actor = {
			age >= 10
		}
		scope:recipient = {
			is_imprisoned = no
			is_at_war = no
		}

		custom_tooltip = {
			text = "max_adventurers_employed"
			scope:actor = {
				OR = {
					trigger_if = {
						limit = { exists = var:employed_adventurers_num }
						var:employed_adventurers_num < 1
					}
					NOT = { exists = var:employed_adventurers_num }
				}
			}
		}

		custom_tooltip = {
			text = "outside_of_the_realm"
			scope:recipient = {
				location.county.holder ?= { top_liege = scope:actor.top_liege }
			}
		}
    }

	# AI Acceptance
	ai_accept = {
		base = 0
		opinion_modifier = { # Opinion Factor
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 0.5
			desc = AI_OPINION_REASON
		}
		opinion_modifier = { # Opinion Factor
			trigger = {
				exists = scope:secondary_recipient
				OR = {
					scope:contract_murder ?= yes
					scope:contract_abduct ?= yes
					scope:contract_pillage ?= yes
					scope:contract_sabotage ?= yes
					scope:contract_support_faction ?= yes
					scope:contract_raid_for_captives ?= yes
				}
				NOT = { scope:actor = scope:secondary_actor }
			}
			who = scope:recipient
			opinion_target = scope:secondary_recipient
			multiplier = -0.5
			desc = AI_OPINION_REASON
		}
		modifier = {
			add = -100
			scope:recipient = {
				num_taken_task_contracts != 0
			}
			desc = already_busy_with_contract_value
		}
		modifier = {
			add = 100
			scope:recipient = {
				num_taken_task_contracts != 0
				any_character_active_contract = {
					task_contract_employer = {
						highest_held_title_tier < scope:actor.highest_held_title_tier
					}

				}
			}

			desc = more_interesting_opportunity
		}
		modifier = {  # Tends to accept if low on cash
			add = 50
			scope:recipient = {
				ai_greed < 20
				short_term_gold <= minor_gold_value
			}
			desc = NEEDS_CASH
		}
		modifier = {  # Tends to accept if low on cash
			add = 100
			scope:recipient = {
				ai_greed >= 20
				short_term_gold <= minor_gold_value
			}
			desc = NEEDS_CASH
		}
		modifier = {
			desc = loaa_insufficient_skills
			OR = {
				scope:contract_improve_reputation ?= yes
			}
			scope:recipient.diplomacy < 10
			add = -50
		}
		modifier = {
			desc = loaa_insufficient_skills
			OR = {
				scope:contract_murder ?= yes
				scope:contract_abduct ?= yes
				scope:contract_sabotage ?= yes
			}
			scope:recipient.intrigue < 10
			add = -50
		}
		modifier = {
			add = 50
			scope:recipient = {
				has_realm_law = camp_purpose_mercenaries
			}
			OR = {
				scope:contract_protect_domain ?= yes
				scope:contract_pillage ?= yes
				scope:contract_raid_for_captives ?= yes
				scope:contract_support_faction ?= yes
			}
			desc = camp_purpose_mercenaries_reason
		}

		loaa_offer_protect_domain_contract_modifier = yes

		loaa_offer_raid_contract_modifier = yes

		loaa_fp3_struggle_resist_allied_wars_modifier = yes

		modifier = {
			desc = OC_RELATIVE_MILITARY_STRENGTH
			OR = {
				scope:contract_pillage ?= yes
				scope:contract_raid_for_captives ?= yes
				scope:contract_support_faction ?= yes
			}
			add = {
				value = {
					add = scope:recipient.current_military_strength
					subtract = scope:secondary_recipient.current_military_strength
					multiply = 0.5
					min = -100
					max = 100
				}
			}
		}
		modifier = {
			desc = OC_HAS_TRUCE
			AND = {
				OR = {
					scope:contract_pillage ?= yes
					scope:contract_raid_for_captives ?= yes
				}
				has_truce = scope:secondary_recipient
			}
			add = {
				value = -1000
			}
		}
		modifier = {
			desc = OC_AT_WAR_WITH
			AND = {
				OR = {
					scope:contract_pillage ?= yes
					scope:contract_raid_for_captives ?= yes
				}
				is_at_war_with = scope:secondary_recipient
			}
			add = {
				value = -1000
			}
		}
		modifier = {
			desc = NO_SIEGE_ENGINES
			AND = {
				OR = {
					scope:contract_pillage ?= yes
					scope:contract_raid_for_captives ?= yes
				}
				scope:recipient = {
					NOT = {
						any_maa_regiment = {
							is_unit_type = siege_weapon
						}
					}
				}
			}
			add = {
				value = {
					value = -2.5
					multiply = scope:secondary_recipient.capital_province.fort_level
				}
			}
		}
		# Weight up for personality values.
		ai_value_modifier = {
			who = scope:recipient

			ai_boldness = {
				if = {
					limit = {
						scope:recipient = {
							ai_greed > 0
						}
					}
					value = 0.5
				}
			}
		}
	}

	options_heading = oc_t_contract_selection

	## Protect Domain
	send_option = {
		flag = contract_protect_domain
		is_shown = {
			exists= scope:secondary_recipient
			#scope:recipient.current_military_strength >= 50
		}
		current_description = offer_protect_domain_contract
	}

	## Raid for Captives
	send_option = {
		flag = contract_raid_for_captives
		is_shown = {
			scope:secondary_recipient ?= { this != scope:actor }
			#scope:recipient.current_military_strength >= 100
		}
		current_description = offer_raid_for_captives_contract
	}

	## Pillaging Raid
	send_option = {
		flag = contract_pillage
		is_shown = {
			# Turned off temporarily
			always = no
			#scope:secondary_recipient ?= { this != scope:actor }
		}
		current_description = offer_pillage_contract
	}

	## Improve Reputation
	send_option = {
		flag = contract_improve_reputation
		is_shown = {
			scope:secondary_recipient ?= { exists = this }
		}
		current_description = offer_improve_reputation_contract
	}

	## Conduct Census
	send_option = {
		flag = contract_conduct_census
		is_shown = {
			scope:secondary_recipient ?= scope:actor
		}
		current_description = offer_conduct_census_contract
	}

	## Deliver Artifact
	send_option = {
		flag = contract_deliver_artifact
		is_shown = {
			scope:secondary_recipient ?= { NOT = { this = scope:actor } }
			scope:actor = {
				any_character_artifact = {
					count >= 1
				}
			}
		}
		is_valid = {
			custom_tooltip = {
				text = loaa_recipient_artifact_opinion
				scope:actor = {
					any_character_artifact = {
						loaa_artifact_acceptance_trigger = {
							ARTIFACT = this
							CONTRACT_TARGET = scope:secondary_recipient
							CONTRACT_EMPLOYER = scope:actor
						}
						NOR = {
							has_variable = 1025_treasure_map
							has_variable = ungiftable
						}
					}
				}
			}
		}
		current_description = offer_deliver_artifact_contract
	}

	## Support Faction
	send_option = {
		flag = contract_support_faction
		is_shown = {
			scope:secondary_recipient ?= { NOT = { this = scope:actor } }
			scope:secondary_recipient ?= {
				any_targeting_faction = {
					exists = yes
					count >= 1
					faction_is_at_war = no
					# scope:recipient = { can_join_faction = prev }
				}
			}
		}
		is_valid = {
			scope:recipient = {
				custom_tooltip = {
					text = NOT_FACTION_CANT_JOIN_CREATE_ADULT
					is_adult = yes
				}
				custom_tooltip = {
					text = NOT_FACTION_CANT_JOIN_CREATE_ALLIED
					trigger_if = {
						limit = { exists = scope:secondary_recipient }
						NOT = { is_allied_to = scope:secondary_recipient }
					}
				}
				custom_tooltip = {
					text = NOT_FACTION_CANT_JOIN_CREATE_HOOK
					trigger_if = {
						limit = { exists = scope:secondary_recipient }
						scope:secondary_recipient = {
							NOT = { has_strong_hook = scope:recipient }
						}
					}
				}
				custom_tooltip = {
					text = NOT_FACTION_CANT_JOIN_CREATE_INCAPABLE
					NOT = { has_trait = incapable }
				}
				custom_tooltip = {
					text = loaa_character_blocked_from_joining
					NOT = { has_character_flag = joining_faction_block }
				}
				custom_tooltip = {
					text = NOT_faction_relation_blocks_joining_friend
					trigger_if = {
						limit = { exists = scope:secondary_recipient }
						NOT = {
							scope:recipient = { has_relation_friend = scope:secondary_recipient }
						}
					}
				}
				custom_tooltip = {
					text = NOT_faction_relation_blocks_joining_lover
					trigger_if = {
						limit = { exists = scope:secondary_recipient }
						NOR = {
							scope:recipient = { has_relation_lover = scope:secondary_recipient }
							scope:recipient = { has_secret_relation_lover = scope:secondary_recipient }
						}
					}
				}
			}
		}
		current_description = offer_support_faction_contract
	}

	## Sabotage
	send_option = {
		flag = contract_sabotage
		is_shown = {
			scope:secondary_recipient ?= { NOT = { this = scope:actor } }
		}
		current_description = offer_sabotage_contract
	}

	## Abduct
	send_option = {
		flag = contract_abduct
		is_shown = {
			scope:secondary_recipient ?= { NOT = { this = scope:actor } }
			scope:secondary_recipient ?= { NOT = { is_imprisoned_by = scope:actor } }
			# Restriction based on scheme restrictions
			scope:actor = {
				OR = {
					has_perk = kidnapper_perk # Same as with the Scheme
					AND = {
						any_character_struggle = {
							involvement = involved
							has_struggle_phase_parameter = unlocks_abduct_for_all
							is_secondary_character_involvement_involved_trigger = {
								CHAR = scope:recipient
							}
						}
					}
				}
			}
		}
		is_valid = {
			custom_tooltip = {
				text = abduct_own_children_block
				OR = {
					scope:secondary_recipient ?= { NOT = { is_child_of = scope:actor } }
					scope:actor = { has_trait = sadistic }
				}
			}
		}
		current_description = offer_abduct_contract
	}

	## Murder
	send_option = {
		flag = contract_murder
		is_shown = {
			scope:secondary_recipient ?= { this != scope:actor }
		}
		is_valid = {
			custom_tooltip = {
				text = abduct_own_children_block
				OR = {
					scope:secondary_recipient ?= { NOT = { is_child_of = scope:actor } }
					scope:actor = { has_trait = sadistic }
				}
			}
		}
		current_description = offer_murder_contract
	}

    on_accept = {
		scope:actor = {
			switch = {
				trigger = yes
				scope:contract_protect_domain ?= {
					custom_tooltip = {
						text = loaa_laamp_accept_contract_protect_domain
					}
				}
				scope:contract_raid_for_captives ?= {
					custom_tooltip = {
						text = loaa_laamp_accept_contract_raid_for_captives
					}
				}
				scope:contract_pillage ?= {
					custom_tooltip = {
						text = loaa_laamp_accept_contract_pillage
					}
				}
				scope:contract_improve_reputation ?= {
					custom_tooltip = {
						text = loaa_laamp_accept_contract_improve_reputation
					}
				}
				scope:contract_conduct_census ?= {
					custom_tooltip = {
						text = loaa_laamp_accept_contract_conduct_census
					}
				}
				scope:contract_support_faction ?= {
					custom_tooltip = {
						text = loaa_laamp_accept_contract_support_faction
					}
				}
				scope:contract_deliver_artifact ?= {
					custom_tooltip = {
						text = loaa_laamp_accept_contract_deliver_artifact
					}
				}
				scope:contract_murder ?= {
					custom_tooltip = {
						text = loaa_laamp_accept_contract_murder
					}
				}
				scope:contract_abduct ?= {
					custom_tooltip = {
						text = loaa_laamp_accept_contract_abduct
					}
				}
				scope:contract_sabotage ?= {
					custom_tooltip = {
						text = loaa_laamp_accept_contract_sabotage
					}
				}
				fallback = {
					custom_tooltip = {
						text = loaa_laamp_accept_contract
					}
				}
			}
			if = {
				limit = {
					OR = {
						scope:contract_abduct ?= yes
						scope:contract_murder ?= yes
						scope:contract_sabotage ?= yes
					}
				}
				custom_tooltip = {
					text = loaa_laamp_accept_crime_success
				}
			}
			else_if = {
				limit = {
					OR = {
						scope:contract_protect_domain ?= yes
						scope:contract_support_faction ?= yes
					}
				}
				custom_tooltip = {
					text = loaa_laamp_accept_protect_domain_success
				}
			}
			else_if = {
				limit = {
					scope:contract_raid_for_captives ?= yes
				}
				custom_tooltip = {
					text = loaa_laamp_accept_raid_for_captives_success
				}
			}
			else_if = {
				limit = {
					OR = {
						scope:contract_deliver_artifact ?= yes
						scope:contract_conduct_census ?= yes
						scope:contract_improve_reputation ?= yes
					}
				}
				custom_tooltip = {
					text = loaa_laamp_accept_success
				}
			}
		}

		hidden_effect = {
			if = {
				limit = { scope:contract_protect_domain ?= yes }
					scope:recipient = {
					create_task_contract = {
						task_contract_type = loaa_protect_domain
						task_contract_tier = {
							value = scope:actor.highest_held_title_tier
							max = 3
						}
						location = scope:actor.capital_province
						task_contract_employer = scope:actor
						target = scope:secondary_recipient
						save_temporary_scope_as = chosen_contract
					}
				}
			}
			else_if = {
				limit = { scope:contract_raid_for_captives ?= yes }
					scope:recipient = {
					create_task_contract = {
						task_contract_type = loaa_laamp_raid_contract
						task_contract_tier = {
							value = scope:actor.highest_held_title_tier
							max = 3
						}
						location = scope:actor.capital_province
						task_contract_employer = scope:actor
						target = scope:secondary_recipient
						save_temporary_scope_as = chosen_contract
					}
				}
			}
			else_if = {
				limit = { scope:contract_pillage ?= yes }
				scope:recipient = {
					create_task_contract = {
						task_contract_type = loaa_pillage_contract
						task_contract_tier = {
							value = scope:actor.highest_held_title_tier
							max = 3
						}
						location = scope:actor.capital_province
						task_contract_employer = scope:actor
						target = scope:secondary_recipient
						save_temporary_scope_as = chosen_contract
					}
				}
			}
			else_if = {
				limit = { scope:contract_improve_reputation ?= yes }
					scope:recipient = {
					create_task_contract = {
						task_contract_type = loaa_laamp_base_0011
						task_contract_tier = {
							value = scope:actor.highest_held_title_tier
							max = 3
						}
						location = scope:actor.capital_province
						task_contract_employer = scope:actor
						target = scope:secondary_recipient
						save_temporary_scope_as = chosen_contract
					}
				}
			}
			else_if = {
				limit = { scope:contract_conduct_census ?= yes }
					scope:recipient = {
					create_task_contract = {
						task_contract_type = loaa_laamp_base_2011
						task_contract_tier = {
							value = scope:actor.highest_held_title_tier
							max = 3
						}
						location = scope:actor.capital_province
						task_contract_employer = scope:actor
						target = scope:secondary_recipient
						save_temporary_scope_as = chosen_contract
					}
				}
			}
			else_if = {
				limit = { scope:contract_support_faction ?= yes }
					scope:recipient = {
					create_task_contract = {
						task_contract_type = loaa_laamp_join_faction_contract
						task_contract_tier = {
							value = scope:actor.highest_held_title_tier
							max = 3
						}
						location = scope:actor.capital_province
						task_contract_employer = scope:actor
						target = scope:secondary_recipient
						save_temporary_scope_as = chosen_contract
					}
				}
			}
			else_if = {
				limit = { scope:contract_deliver_artifact ?= yes }
					scope:recipient = {
					create_task_contract = {
						task_contract_type = loaa_deliver_artifact_contract
						task_contract_tier = {
							value = scope:actor.highest_held_title_tier
							max = 3
						}
						location = scope:actor.capital_province
						task_contract_employer = scope:actor
						target = scope:secondary_recipient
						save_temporary_scope_as = chosen_contract
					}
				}
			}
			else_if = {
				limit = { scope:contract_sabotage ?= yes }
					scope:recipient = {
					create_task_contract = {
						task_contract_type = loaa_sabotage_contract
						task_contract_tier = {
							value = scope:actor.highest_held_title_tier
							max = 3
						}
						location = scope:actor.capital_province
						task_contract_employer = scope:actor
						target = scope:secondary_recipient
						save_temporary_scope_as = chosen_contract
					}
				}
			}
			else_if = {
				limit = { scope:contract_abduct ?= yes }
					scope:recipient = {
					create_task_contract = {
						task_contract_type = loaa_laamp_base_3021
						task_contract_tier = {
							value = scope:actor.highest_held_title_tier
							max = 3
						}
						location = scope:actor.capital_province
						task_contract_employer = scope:actor
						target = scope:secondary_recipient
						save_temporary_scope_as = chosen_contract
					}
				}
			}
			else_if = {
				limit = { scope:contract_murder ?= yes }
					scope:recipient = {
					create_task_contract = {
						task_contract_type = loaa_laamp_base_3011
						task_contract_tier = {
							value = scope:actor.highest_held_title_tier
							max = 3
						}
						location = scope:actor.capital_province
						task_contract_employer = scope:actor
						target = scope:secondary_recipient
						save_temporary_scope_as = chosen_contract
					}
				}
			}
			scope:recipient = {
				if = {
					limit = {
						# is_ai = yes
						exists = scope:chosen_contract
					}
					accept_task_contract = scope:chosen_contract
				}
			}
		}
		scope:recipient = {
			if = {
				limit = {
					OR = {
						scope:contract_deliver_artifact ?= yes
						scope:contract_protect_domain ?= yes
						scope:contract_conduct_census ?= yes
						scope:contract_improve_reputation ?= yes
						scope:contract_murder ?= yes
						scope:contract_sabotage ?= yes
						scope:contract_abduct ?= yes
						scope:contract_raid_for_captives ?= yes
						scope:contract_pillage ?= yes
						scope:contract_support_faction ?= yes
					}
				}
				custom_tooltip = {
					text = loaa_laamp_recipient_tt
				}
				# custom_tooltip = {
				# 	text = loaa_laamp_recipient_tt_target
				# }
			}
		}

		scope:recipient = { remove_character_flag = offer_contract_sent }
    }

	on_decline = {
		scope:actor = {
			send_interface_toast = {
				type = event_contract_declined
				title = event_contract_declined_tt
				desc = event_contract_declined_desc
				left_icon = scope:actor
				right_icon = scope:recipient
			}
		}
		scope:recipient = { remove_character_flag = offer_contract_sent }
	}

    cost = {
		prestige = {
			value = 150
		}
	}
    ai_will_do = {
        base = 0 # AI won't initiate this
    }
}

cancel_contract = {
	common_interaction = no
    category = interaction_category_diplomacy
    interface_priority = 10

    greeting = negative
    # notification_text = offer_contract_proposal

	icon = cancel_contract
    desc = cancel_contract_interaction_desc

	can_send_despite_rejection = yes
	secondary_scopes_optional = no


	# Can send
	can_send = {

	}

    is_shown = {
        scope:actor = {
            is_alive = yes
            is_ruler = yes
			is_landed = yes
			has_variable = offered_contract
			var:offered_contract ?= { task_contract_taker = scope:recipient }
		}
		scope:recipient = {
			is_landless_adventurer = yes
		}
    }

    is_valid_showing_failures_only = {
    }

	auto_accept = yes

	on_accept = {
		scope:actor = {
			var:offered_contract = {  save_temporary_scope_as = task_contract }
			loaa_contract_invalidation_penalty_effect = yes
		}
		scope:recipient = {
			custom_tooltip = {
				text = cancel_contract_recipient
			}
		}
	}

	ai_accept = {
		base = 0
	}
}

invite_adventurer = {
	category = interaction_category_diplomacy
	interface_priority = 30
	icon = icon_invite_adventurer_new3

	desc = invite_adventurer_desc
    greeting = positive
	cooldown_against_recipient = { years = 2 }

	notification_text = {
		first_valid = {
			desc = INVITE_ADVENTURER_PROPOSAL
		}
	}

	popup_on_receive = yes
	pause_on_receive = yes

	interface_priority = 60
	ignores_pending_interaction_block = no

	send_options_exclusive = no

	auto_accept = {
		custom_description = {
			text = "spending_hook"
			subject = scope:actor
			object = scope:recipient
			scope:hook = yes
			scope:actor = { has_strong_hook = scope:recipient }
		}
	}

	is_shown = {
		scope:actor = {
			is_ruler = yes
			is_landed = yes
			is_landless_adventurer = no # Only rulers can invite adventurers
		}
		scope:recipient = {
			is_landless_adventurer = yes
		}
	}


	is_valid_showing_failures_only = {
		scope:recipient = {
			is_available_healthy_adult = yes
		}
		custom_tooltip = {
			text = invite_adventurer_already_in_realm_tt
			NOT = { scope:actor.capital_county.title_province = scope:recipient.location }
		}
	}


	on_accept = {
		scope:actor.capital_province = {
			save_scope_as = relocation_destination
		}
		scope:actor = {
			if = {
				limit = { scope:offer_gold = yes }
				pay_short_term_gold = {
					gold = 100
					target = scope:recipient
				}
			}
			if = {
				limit = { scope:hook = yes }
				use_hook = scope:recipient
			}
		}

		scope:recipient = {
			custom_tooltip = {
				text = invite_adventurer_accept_tt
				scope:recipient = {
					start_travel_plan = {
						destination = scope:relocation_destination
						on_start_on_action = on_travel_relocation_start
						on_arrival_on_action = on_travel_relocation_end
						on_arrival_destinations = last
						return_trip = no # One way
						travel_with_domicile = yes
					}
				}

			}
			add_character_flag = recently_invited_adventurer
		}

	}

	send_option = {
		flag = offer_gold
		localization = offer_laamp_invasion_sponsorship_option_offer_gold
		current_description = offer_laamp_invasion_sponsorship_option_offer_gold_desc
		is_shown = { exists = scope:recipient }
		is_valid = { scope:actor.gold >= 100 }
	}

	send_option = {
		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"

	cost = {
		prestige = {
			value = 150
		}
	}

	on_decline = {
		# scope:actor = {
		# 	save_scope_as = adventurer
		# 	trigger_event = ep3_laamps.0102
		# }
	}

	ai_targets = {
		ai_recipients = nearby_domicile_owners
		max = 10
	}
	ai_frequency = 120

	ai_accept = {
		base = 0
		opinion_modifier = { # Opinion Factor
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 1
			desc = AI_OPINION_REASON
		}

		modifier = {
			add = 10
			desc = youre_my_friend_tt
			has_relation_friend = scope:actor
		}

		modifier = {
			add = 10
			desc = lover_reason_tt
			has_relation_lover = scope:actor
		}

		modifier = {
			faith = {
				faith_hostility_level = {
					target = scope:actor.faith
					value >= faith_astray_level
				}
			}
			add = {
				value = "faith.faith_hostility_level(scope:actor.faith)"
				multiply = -10
			}
			desc = FAITH_HOSTILITY_LEVEL
		}

		modifier = {
			add = 50
			scope:hook = yes
			desc = YOU_HAVE_HOOK_REASON
		}

		modifier = {
			add = 35
			scope:offer_gold = yes
			desc = GOLD_REASON
		}

	}

	ai_will_do = {
		base = 0
	}
}

offer_laamp_legitimist_support = {
	interface_priority = 50
	common_interaction = no
	category = interaction_category_diplomacy
	cooldown_against_recipient = { years = 5 }

	greeting = positive

	icon = request_invasion_sponsorship_interaction
	desc = offer_laamp_legitimist_support_interaction_desc

	notification_text = {
		first_valid = {
			desc = OFFER_LEGITIMIST_SUPPORT_PROPOSAL
		}
	}

	popup_on_receive = yes
	pause_on_receive = yes

	interface_priority = 60
	ignores_pending_interaction_block = no

	can_send_despite_rejection = yes

	is_shown = {
		has_ep3_dlc_trigger = yes
		OR = {
			scope:recipient = {
				is_landless_adventurer = yes
				has_realm_law = camp_purpose_legitimists
			}
			AND = {
				has_game_rule = legitimist_support_target_min_tier_courtiers
				scope:recipient = {
					is_courtier_of = scope:actor
					any_claim = {
						count >= 1
						tier >= tier_kingdom
					}
				}
			}
		}

		scope:actor = {
			is_landed = yes
		}
		NOT = { scope:recipient = scope:actor }
	}

	is_valid_showing_failures_only = {
		# NOR = { #so legitimist AI can get lucky. It looks ugly but formats the tooltip correctly
		# 	NOT = {
		# 		ep3_laamp_diplo_range_trigger = {
		# 			TARGET = scope:actor
		# 			LAAMP = scope:recipient
		# 		}
		# 	}
		# 	# scope:recipient = {
		# 	# 	is_available_ai_adult = yes
		# 	# }
		# }
		scope:actor = {
			highest_held_title_tier >= tier_kingdom
		}
		custom_tooltip = {
			text = request_laamp_legitimist_have_claim_on_target
			scope:recipient = {
				NOT = {
					any_claim = {
						OR = {
							holder = {
								this = scope:actor
							}
							holder.top_liege = {
								this = scope:actor
							}
						}
					}
				}
			}
		}

		custom_tooltip = {
			text = offer_laamp_legitimist_support_already_supporting
			scope:actor = {
				NOT = {
					has_character_flag = legitimist_supporter
				}
			}
		}
		scope:recipient = {
			is_busy_in_events_localised = yes
			is_at_war = no
			is_travelling = no
		}

		# Adventurers can't join wars in places they're exiled from.
		custom_tooltip = {
			text = the_wake_1
			NOT = {
				is_laamp_exiled_from_province_trigger = {
					PROVINCE = scope:actor.capital_province
					LAAMP = scope:recipient
				}
			}
		}
	}

	cost = {
		prestige = 100
	}

	on_accept = {
		scope:recipient = { save_scope_as = sender }
		scope:recipient = {
			create_task_contract = {
				task_contract_type = loaa_laamp_legitimist_support_contract
				task_contract_tier = 3
				location = scope:actor.capital_province
				task_contract_employer = scope:actor
				save_temporary_scope_as = legitimist_contract
			}
			if = {
				limit = {
					is_ai = yes
				}
				custom_tooltip = loaa_ruler_legitimist_support_contract_success
			}
			else = {
				custom_tooltip = loaa_laamp_legitimist_support_contract_success
			}

			hidden_effect = {
				if = {
					limit = {
						scope:recipient = {
							is_ai = yes
							is_landless_adventurer = yes
							location = scope:actor.capital_province
						}
					}
					accept_task_contract = scope:legitimist_contract
				}
				else_if = {
					limit = {
						scope:recipient = {
							is_ai = yes
							is_landless_adventurer = yes
							NOT = { location = scope:actor.capital_province }
						}

					}
					set_variable = {
						name = potential_legitimist_supporter
						value = scope:actor
					}
					set_variable = {
						name = legitimist_contract
						value = scope:legitimist_contract
					}
					start_travel_plan = {
						destination = scope:actor.capital_province
						on_start_on_action = on_travel_relocation_start
						on_arrival_on_action = on_legitimist_travel_relocation_end
						on_arrival_destinations = last
						return_trip = no # One way
						travel_with_domicile = yes
					}
				}
				else_if = {
					limit = {
						scope:recipient = {
							is_ai = yes
							is_courtier_of = scope:actor
						}
					}
					scope:actor = { save_scope_as = petitioned_ruler }
					save_scope_as = claimant
					trigger_event = loaa_legitimist_support_events.1
				}
			}
		}
	}

	on_decline = {
		scope:recipient = { save_scope_as = sender }
		scope:actor = { trigger_event = loaa_legitimist_support_events.11 }
	}

	use_diplomatic_range = yes

	ai_accept = {
		base = 0
		opinion_modifier = { # Opinion Factor
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 0.5
			desc = AI_OPINION_REASON
		}

		# Relationships: actor -> recipient / We avoid more relationship checks for balance reasons (and because important decisions tend to care little for relationships)
		modifier = { # Rivalry modifier.
			desc = offer_vassalization_interaction_aibehavior_rival_tt
			scope:recipient = {
				has_relation_rival = scope:actor
				NOT = { has_relation_nemesis = scope:actor }
			}
			add = -10
		}

		modifier = { # Nemesis modifier.
			desc = offer_vassalization_interaction_aibehavior_nemesis_tt
			scope:recipient = { has_relation_nemesis = scope:actor }
			add = -30
		}

		modifier = { # Same Dynasty modifier.
			desc = offer_vassalization_interaction_aibehavior_dynasty_tt
			scope:recipient.dynasty = scope:actor.dynasty
			add = 10
		}
		modifier = {
			add = 60
			scope:actor = {
				has_hook = scope:recipient
			}
			desc = YOU_HAVE_HOOK_REASON
		}
		modifier = {
			add = 10
			scope:actor.dynasty = scope:recipient.dynasty
			desc = BF_AI_SAME_DYNASTY_REASON
		}
		modifier = {
			add = 20
			scope:actor.house = scope:recipient.house
			desc = IS_SAME_HOUSE_REASON
		}
		modifier = {
			add = 20
			scope:recipient = { has_trait = ambitious }
			desc = RECIPIENT_IS_AMBITIOUS
		}
		modifier = {
			add = 10
			scope:recipient = { has_trait = humble }
			desc = DEMAND_SUBMISSION_RECIPIENT_IS_HUMBLE
		}
		modifier = {
			add = 10
			scope:recipient = { has_trait = trusting }
			desc = DEMAND_SUBMISSION_RECIPIENT_IS_TRUSTING
		}
		modifier = {
			add = -20
			scope:recipient = { has_trait = paranoid }
			desc = DEMAND_SUBMISSION_RECIPIENT_IS_PARANOID
		}
		modifier = {
			add = -10
			scope:recipient = { has_trait = cynical }
			desc = ASK_FOR_CONVERSION_RECIPIENT_IS_CYNICAL
		}
		modifier = {
			add = -10
			scope:recipient = { has_trait = arrogant }
			desc = DEMAND_SUBMISSION_RECIPIENT_IS_ARROGANT
		}
		modifier = {
			add = 10
			scope:recipient = { has_trait = just }
			desc = RECIPIENT_IS_JUST
		}
		modifier = {
			add = 10
			scope:recipient = { has_trait = greedy }
			desc = RECIPIENT_IS_GREEDY
		}
	}

	# can_send_despite_rejection = no
	# ai_frequency = 60
	# ai_targets = {
	# 	ai_recipients = scripted_relations
	# 	ai_recipients = nearby_domicile_owners
	# }
	# ai_potential = {
	# 	is_at_war = no
	# 	NOT = { ai_has_economical_boom_personality = yes }
	# 	ai_greed <= 25
	# }
	ai_will_do = {
		base = 0
	}
}

offer_to_merge_camps = {
	icon = icon_ally
	desc = offer_to_merge_camps_desc
    greeting = positive
	interface_priority = 100
	category = interaction_category_diplomacy
	#ignores_pending_interaction_block = yes
	ai_frequency = 60

	ai_targets = {
		ai_recipients = nearby_domicile_owners
		ai_recipients = top_realm_domicile_owners
		ai_recipients = scripted_relations
		max = 30
	}
	use_diplomatic_range = yes
	cooldown = { years = 10 }

	is_shown = {
		scope:actor = {
			is_landless_adventurer = yes
			has_domicile = yes
		}
		scope:recipient = {
			is_landless_adventurer = yes
			is_ai = yes
			has_domicile = yes
		}
		NOT = { scope:recipient = scope:actor }
	}

	is_valid_showing_failures_only = {
		custom_tooltip = {
			text = loaa_ongoing_camp_construction
			scope:actor.domicile = {
				has_ongoing_domicile_construction = no
			}
		}

		scope:recipient = {
			is_landless_adventurer = yes
			domicile ?= { is_domicile_type = camp }
		}

		# Target must be close enough.
		custom_tooltip = {
			text = target_too_far_away
			scope:recipient.domicile.domicile_location ?= {
				squared_distance = {
					target = scope:actor.domicile.domicile_location
					value < loaa_adventurer_distance_value
				}
			}
		}
	}

	send_options_exclusive = no

	send_option = {
		flag = offer_gold
		localization = offer_laamp_invasion_sponsorship_option_offer_gold
		current_description = offer_laamp_invasion_sponsorship_option_offer_gold_desc
		is_shown = { exists = scope:recipient }
		is_valid = { scope:actor.gold >= 100 }
	}

	send_option = {
		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"

	cost = {
		prestige = {
			value = 150
		}
	}

	on_accept = {
		scope:actor = {
			if = {
				limit = {
					scope:offer_gold = yes
				}
				pay_short_term_gold = {
					gold = {
						value = scope:recipient.current_military_strength
						divide = 10
						add = {
							value = 0
							scope:recipient = {
								every_courtier = {
									add = 10
								}
							}
						}
						min = 100
						max = 800
					}
					target = scope:recipient
				}
			}
			if = {
				limit = { scope:hook = yes }
				use_hook = scope:recipient
			}
		}
		scope:recipient = {
			custom_tooltip = offer_to_merge_camps_tt
			show_as_tooltip = {
				destroy_title = primary_title
			}
			save_scope_as = joined_leader
		}
		scope:actor = {
			trigger_event = loaa_merge_camps_events.1
		}
	}

	ai_accept = {
		base = -60
		opinion_modifier = { # Opinion Factor
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 1
			desc = AI_OPINION_REASON
		}

		# Relationships: actor -> recipient / We avoid more relationship checks for balance reasons (and because important decisions tend to care little for relationships)
		modifier = { # Rivalry modifier.
			desc = offer_vassalization_interaction_aibehavior_rival_tt
			scope:recipient = {
				has_relation_rival = scope:actor
				NOT = { has_relation_nemesis = scope:actor }
			}
			add = -10
		}

		modifier = {
			desc =  NEGOTIATE_SETTLEMENT_LEGITIMIST_REASON
			scope:recipient = {
				has_realm_law = camp_purpose_legitimists
			}
			add = -150
		}

		modifier = {
			add = 10
			desc = youre_my_friend_tt
			has_relation_friend = scope:actor
		}

		modifier = {
			add = 10
			desc = lover_reason_tt
			has_relation_lover = scope:actor
		}

		modifier = {
			desc = RELATIVE_MILITARY_POWER_REASON
			#scope:recipient.current_military_strength > actor.current_military_strength
			add = {
				value = 0
				add = scope:actor.current_military_strength
				subtract = scope:recipient.current_military_strength
				divide = 10
			}
		}

		modifier = { # Nemesis modifier.
			desc = offer_vassalization_interaction_aibehavior_nemesis_tt
			scope:recipient = { has_relation_nemesis = scope:actor }
			add = -50
		}

		modifier = { # Same Dynasty modifier.
			desc = offer_vassalization_interaction_aibehavior_dynasty_tt
			scope:recipient.dynasty = scope:actor.dynasty
			add = 10
		}
		modifier = {
			add = 60
			scope:hook = yes
			desc = YOU_HAVE_HOOK_REASON
		}
		modifier = {
			add = 10
			scope:actor.dynasty = scope:recipient.dynasty
			desc = BF_AI_SAME_DYNASTY_REASON
		}
		modifier = {
			add = 20
			scope:actor.house = scope:recipient.house
			desc = IS_SAME_HOUSE_REASON
		}
		modifier = {
			add = -20
			scope:recipient = { has_trait = ambitious }
			desc = RECIPIENT_IS_AMBITIOUS
		}
		modifier = {
			faith = {
				faith_hostility_level = {
					target = scope:actor.faith
					value >= faith_astray_level
				}
			}
			add = {
				value = "faith.faith_hostility_level(scope:actor.faith)"
				multiply = -10
			}
			desc = FAITH_HOSTILITY_LEVEL
		}

		modifier = {
			add = 35
			scope:offer_gold = yes
			desc = GOLD_REASON
		}
	}

	ai_will_do = {
		base = 0
	}
}