﻿switch_adventurer = {
	category = interaction_category_diplomacy
	desc = switch_adventurer_desc
	icon = request_invasion_sponsorship_interaction
	common_interaction = yes

	interface_priority = 1
	auto_accept = yes
	use_diplomatic_range = no
	ignores_pending_interaction_block = yes

	is_shown = {
		has_ep3_dlc_trigger = yes #DLC check nearly forgot
		scope:actor = { is_ai = no }
		scope:recipient = {
			OR = {
				NOT = { exists = primary_title }
				is_landed = yes
			}
			is_ai = yes
		}
	}

	can_send = {
		scope:actor = { is_ai = no }
	}

	on_accept = {
		scope:recipient = {
			# Non-rulers
			if = {
				limit = {
					NOT = { exists = primary_title }
				}
				save_scope_as = new_landless_adventurer
				create_landless_adventurer_title_effect = {
					REASON = flag:voluntary
					FLAVOR_CHAR = scope:actor
				}
				hidden_effect = {
					if = {
						limit = { exists = location }
						populate_task_contracts_for_area = {
							location = location
							amount = 3
							group = { 
								laamp_contracts_transport_group 
								laamp_contracts_criminal_group
								laamp_contracts_diplomacy_group
								laamp_contracts_hireling_group
								laamp_contracts_hunting_group
								laamp_contracts_intrigue_group
								laamp_contracts_learning_group
								laamp_contracts_martial_group
								laamp_contracts_stewardship_group
								laamp_contracts_justicar_group 
							}
						}
					}
				}
			}
			# Rulers
			else = {
				if = {
					limit = {
						player_heir ?= {
							NOT = { this = scope:recipient }
							is_adult = yes
						}
					}
					player_heir = {
						save_scope_as = laamp_heir
						save_scope_as = laamp_inheritor
						custom_tooltip = become_landless_adventurer_decision_title_scope_tt
					}
				}
				else_if = {
					limit = { is_independent_ruler = no }
					liege = {
						save_scope_as = laamp_liege
						save_scope_as = laamp_inheritor
						custom_tooltip = become_landless_adventurer_decision_title_scope_tt
					}
				}
				else = {
					custom_tooltip = become_landless_adventurer_decision_title_created_tt
					if = {
						limit = {
							NOT = { exists = scope:laamp_inheritor }
						}
						hidden_effect_new_object = {
							create_character = {
								template = laamp_inheritor_template
								culture = root.capital_county.culture
								faith = root.capital_county.faith
								dynasty = generate
								location = root.capital_province
								after_creation = {
									save_scope_as = laamp_inheritor
									add_character_flag = new_laamp_inheritor
								}
							}
						}
					}
				}
				create_landless_adventurer_title_tooltip_effect = yes
				show_as_tooltip = {
					add_prestige = medium_prestige_gain
					add_character_modifier = {
						modifier = ep3_voluntary_laamp_character_modifier
						years = 5
					}
				}
				trigger_event = { id = ep3_laamps.0030 }
				hidden_effect = {
					populate_task_contracts_for_area = {
						location = scope:recipient.capital_province
						amount = 3
						group = { 
							laamp_contracts_transport_group 
							laamp_contracts_criminal_group
							laamp_contracts_diplomacy_group
							laamp_contracts_hireling_group
							laamp_contracts_hunting_group
							laamp_contracts_intrigue_group
							laamp_contracts_learning_group
							laamp_contracts_martial_group
							laamp_contracts_stewardship_group
							laamp_contracts_justicar_group 
						}
					}
				}
			}
		}
		scope:actor = {
			set_player_character = scope:recipient
		}
	}

	ai_frequency = 0
	ai_will_do = 0
}
