﻿start_raid_camp_interaction = {
	icon = icon_raid_camp
	interface_priority = 90
	category = interaction_category_hostile
	send_name = START_SCHEME
	scheme = raid_camp
	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 = 3 }

	is_shown = {
		OR = {
			scope:actor = {
				has_game_rule = raid_camp_scheme_on_for_landed
				OR = {
					is_landed = yes
					is_landless_adventurer = yes
				}
			}
			scope:actor = {
				has_game_rule = raid_camp_scheme_on
				is_landed = no
				is_landless_adventurer = yes
			}
		}
		scope:recipient = {
			is_landless_adventurer = yes
			has_domicile = yes
		}
		NOT = { scope:recipient = scope:actor }
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			OR = {
				is_landless_adventurer = yes
				is_landed = yes
				is_available_adult = yes
				any_held_title = { is_noble_family_title = yes }
			}
		}

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

		# Target must be close enough.
		trigger_if = {
			limit = { scope:actor = { is_landless_adventurer = yes } }
			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
					}
				}
			}
		}

		# trigger_if = {
		# 	limit = { scope:actor = { is_landed = yes } }
		# 	custom_tooltip = {
		# 		text = target_too_far_away_landed
		# 		ep3_laamp_diplo_range_trigger = {
		# 			TARGET = scope:actor
		# 			LAAMP = scope:recipient
		# 		}
		# 	}
		# }
	}

	desc = start_raid_camp_interaction_desc

	# Scheme Starter Packages
	options_heading = schemes.t.agent_packages
	send_options_exclusive = yes
	## Balanced agents.
	send_option = {
		flag = agent_focus_balance
		current_description = start_raid_camp_interaction.tt.agent_focus_balance
	}
	## Focused on Success Chance.
	send_option = {
		flag = agent_focus_success
		current_description = start_raid_camp_interaction.tt.agent_focus_success
	}
	## Focused on Speed.
	send_option = {
		flag = agent_focus_speed
		current_description = start_raid_camp_interaction.tt.agent_focus_speed
	}
	## Focused on Secrecy.
	send_option = {
		flag = agent_focus_secrecy
		current_description = start_raid_camp_interaction.tt.agent_focus_secrecy
	}

	on_accept = {
		scope:recipient = {
			custom_tooltip = raid_camp_kill_maim_imprison_camp_followers_tt
			custom_tooltip = raid_camp_destroy_buildings_tt
			#custom_tooltip = raid_camp_house_modifier_tt
			random_held_title = {
				limit = { is_landless_type_title = yes }
				save_scope_as = target_title
			}
		}
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = start_raid_camp_notification
				left_icon = scope:recipient
				right_icon = scope:target_title
				# Success.
				if = {
					limit = { scope:agent_focus_success ?= yes }
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = raid_camp
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
						# Success.
						AGENT_1 = agent_scout
						AGENT_2 = agent_scout
						AGENT_3 = agent_muscle
						# Speed.
						AGENT_4 = agent_infiltrator
						# Secrecy.
						AGENT_5 = agent_lookout
					}
				}
				# Speed.
				else_if = {
					limit = { scope:agent_focus_speed ?= yes }
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = raid_camp
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
						# Speed.
						AGENT_1 = agent_infiltrator
						AGENT_2 = agent_infiltrator
						AGENT_3 = agent_footpad
						# Success.
						AGENT_4 = agent_scout
						# Secrecy.
						AGENT_5 = agent_lookout
					}
				}
				# Secrecy.
				else_if = {
					limit = { scope:agent_focus_secrecy ?= yes }
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = raid_camp
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
						# Secrecy.
						AGENT_1 = agent_lookout
						AGENT_2 = agent_lookout
						AGENT_3 = agent_alibi
						# Success.
						AGENT_4 = agent_scout
						# Speed.
						AGENT_5 = agent_infiltrator
					}
				}
				# Balanced.
				else = {
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = raid_camp
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
						# Success.
						AGENT_1 = agent_scout
						AGENT_2 = agent_muscle
						# Speed.
						AGENT_3 = agent_infiltrator
						AGENT_4 = agent_footpad
						# Secrecy.
						AGENT_5 = agent_lookout
					}
				}
			}
			# Scheme progress bonus from education
			education_5_scheme_progress_effect = { SKILL = intrigue }
			# Scheme bonuses from being the emperor/dominant family/powerful family
			#ep3_actor_scheme_modifier_effect = yes

			custom_tooltip = raid_camp_gain_coin_tt
			if = {
				limit = {
					is_landless_adventurer = yes
				}
				custom_tooltip = raid_camp_gain_provisions_tt
			}

			if = {
				limit = {
					has_relation_rival = scope:recipient
				}
				custom_tooltip = raid_camp_nemesis_relation_tt
			}
			else = {
				custom_tooltip = raid_camp_rival_relation_tt
			}

			stress_impact = {
				content = medium_stress_impact_gain
			}
			if = {
				limit = {
					has_relation_nemesis = scope:recipient
				}
				stress_impact = { base = major_stress_impact_loss }
			}
			else_if = {
				limit = {
					has_relation_rival = scope:recipient
				}
				stress_impact = { base = medium_stress_impact_loss }
			}
		}
	}

	ai_potential = {
		NOT = {
			any_scheme = { is_hostile = yes }
		}
	}

	auto_accept = yes

	ai_will_do = {
		base = -20
		#Personality
		modifier = {
			has_trait = vengeful
			add = 25
		}
		modifier = {
			has_trait = forgiving
			add = -15
		}
		modifier = {
			has_trait = brave
			add = 15
		}
		modifier = {
			has_trait = craven
			add = -15
		}
		# Relationships
		modifier = {
			add = 50
			has_opinion_modifier = {
				target = scope:recipient
				modifier = eviction_ignored_opinion
			}
		}
		modifier = {
			add = -25
			has_any_moderate_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}
		modifier = {
			add = -50
			has_any_best_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}
		modifier = {
			add = 15
			has_any_mild_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}
		modifier = {
			add = 25
			has_any_moderate_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}
		modifier = {
			add = 50
			has_any_worst_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}
		opinion_modifier = {
			who = scope:actor
			opinion_target = scope:recipient
			multiplier = -0.3
		}
	}
}