﻿# LAAMP SUPPORTER EXPIRING
action_laamp_support_expiring_legend = {
	type = alert
	icon = action_can_start_legend

	check_create_action = {
		if = {
			limit = {
				NOT = { exists = promoted_legend }
				any_legend = {
					save_temporary_scope_as = legend
					root = {
						can_become_owner_of_legend = scope:legend
					}
				}
			}

			try_create_important_action = {
				important_action_type = action_inherit_legend
				recipient = this
			}
		}
	}

	effect = {
		open_view_data = legends
	}
}

# LAAMP THREAT OF APPREHENSION
action_laamp_apprehension_threat = {
	priority = 300
	combine_into_one = yes
	is_dangerous = yes
	check_create_action = {
		if = {
			limit = {
				has_government = landless_adventurer_government
				domicile.domicile_location.county.holder ?= {
					OR = {
						#Unop Check if they can actually imprison you
						has_opinion_modifier = {
							target = root
							modifier = eviction_ignored_opinion
						}
						any_liege_or_above = {
							has_opinion_modifier = {
								target = root
								modifier = eviction_ignored_opinion
							}
						}
					}
				}
			}
			domicile.domicile_location.county.holder ?= {
				if = {
					limit = {
						#Unop Check if they can actually imprison you
						has_opinion_modifier = {
							target = root
							modifier = eviction_ignored_opinion
						}
					}
					add_to_list = apprehender_list
				}
				every_liege_or_above = {
					limit = {
						#Unop Check if they can actually imprison you
						has_opinion_modifier = {
							target = root
							modifier = eviction_ignored_opinion
						}
					}
					add_to_list = apprehender_list
				}
			}
			ordered_in_list = {
				list = apprehender_list
				order_by = highest_held_title_tier
				save_scope_as = apprehender
				try_create_important_action = {
					important_action_type = action_laamp_apprehension_threat
					actor = this
					recipient = root
				}
			}
		}
	}

	effect = {
		open_view_data = move_domicile_planner
	}
}

action_laamp_camp_purpose = {
	type = alert
	icon = action_camp

	check_create_action = {
		if = {
			limit = {
				AND = {
					has_government = landless_adventurer_government
					# Wanderers are default camp purpose, therefore only show when you DO have Wanderers
					has_realm_law = camp_purpose_wanderers
				}
			}

			try_create_important_action = {
				important_action_type = action_laamp_camp_purpose
				recipient = this
			}
		}
	}

	effect = {
		open_view_data = {
			view = my_realm
			data = flag:bookmark_laws
		}
	}
}

action_ep3_can_ask_hof_for_influence = {
	priority = 900
	check_create_action = {
		if = {
			limit = {
				exists = faith.religious_head
				faith.religious_head = {
					root = {
						is_character_interaction_potentially_accepted = {
							recipient = prev
							interaction = ep3_hof_ask_for_influence_interaction
						}
					}
				}
			}
			faith.religious_head = {
				try_create_important_action = {
					important_action_type = action_ep3_can_ask_hof_for_influence
					actor = root
					recipient = this
				}
			}
		}
	}

	effect = {
		open_interaction_window = {
			interaction = ep3_hof_ask_for_influence_interaction
			actor = scope:actor
			recipient = scope:recipient
		}
	}
}

action_ep3_laamp_contract_travel = {
	check_create_action = {
		if = {
			limit = {
				has_ep3_dlc_trigger = yes
				government_has_flag = government_is_landless_adventurer
				is_travelling = no
				domicile ?= { provisions >= 250 }
				any_character_active_contract = { count < 1 }
				any_character_task_contract = { count <= 3 }
				is_available = yes
				is_at_war = no
			}
			try_create_important_action = {
				important_action_type = action_ep3_laamp_contract_travel
				actor = root
			}
		}
	}
	effect = {
		domicile.domicile_location.duchy ?= {
			save_scope_as = original_duchy
		}
		random_duchy = {
			limit = {
				this != scope:original_duchy
				NOT = {
					any_title_to_title_neighboring_duchy = {
						this = scope:original_duchy
					}
				}
				title_capital_county.title_province ?= {
					squared_distance = {
						target = root.domicile.domicile_location
						value <= squared_distance_large
					}
				}
				title_capital_county.title_province ?= {
					squared_distance = {
						target = root.domicile.domicile_location
						value >= squared_distance_medium
					}
				}
				title_capital_county.holder ?= {
					root = {
						is_character_interaction_valid = {
							recipient = prev
							interaction = relocate_camp_to_interaction
						}
					}
				}
			}
			save_scope_as = new_duchy
			title_capital_county.title_province = { save_scope_as = destination_province }
			title_capital_county.holder = { save_scope_as = destination_holder }
		}
		if = {
			limit = {
				exists = scope:destination_province
				exists = scope:destination_holder
			}
			pan_camera_to_province = scope:destination_province
			scope:destination_province = { open_view_data = holding_view }
			open_interaction_window = {
				interaction = relocate_camp_to_interaction
				actor = root
				recipient = scope:destination_holder
			}
		}
	}
}

action_in_debt_landless = {
	is_dangerous = yes
	
	check_create_action = {
		if = {
			limit = {
				is_landed = no
				gold < 0
			}
			try_create_important_action = {
				important_action_type = action_in_debt_landless
				actor = root
			}
		}
	}
}

# ADMIN

# LOSING HIGHEST TIER HELD ADMIN TITLE(S)
action_primary_heir_not_inheriting_held_admin_title = {
	priority = 250
	combine_into_one = yes
	is_dangerous = yes
	check_create_action = {
		if = {
			limit = {
				government_has_flag = government_is_administrative
				save_temporary_scope_as = holder_temp
			}
			every_held_title = {
				limit = {
					tier = scope:holder_temp.highest_held_title_tier
					is_landless_type_title = no
					is_noble_family_title = no
					OR = {
						current_heir ?= {
							OR = {
								is_lowborn = yes
								house ?= { this != scope:holder_temp.house }
							}
						}
					}
					OR = {
						has_title_law_flag = appointment_type_succession
						holder = { has_realm_law_flag = appointment_type_succession }
					}
				}
				try_create_important_action = {
					important_action_type = action_primary_heir_not_inheriting_held_admin_title
					landed_title = this
				}
			}
		}
	}

	unimportant = {
		scope:landed_title != root.primary_title
	}

	effect = {
		scope:landed_title = {
			open_view_data = {
				view = title_view_window
			}
		}
	}
}

# INVESTED CANDIDATE NOT CURRENT HEIR
action_invested_candidate_not_inheriting_admin_title = {
	priority = 249
	combine_into_one = yes
	is_dangerous = yes
	check_create_action = {
		if = {
			limit = {
				government_has_flag = government_is_administrative
				save_temporary_scope_as = holder_temp
			}
			every_succession_appointment_invested_title = {
				limit = {
					is_landless_type_title = no
					is_noble_family_title = no
					OR = {
						has_title_law_flag = appointment_type_succession
						holder = { has_realm_law_flag = appointment_type_succession }
					}
					current_heir ?= {
						save_temporary_scope_as = heir_temp
						NOT = {
							root = { has_appointment_invested_character = scope:heir_temp }
						}
					}
					any_title_heir = {
						save_temporary_scope_as = candidate_temp
						root = { has_appointment_invested_character = scope:candidate_temp }
					}
				}
				save_scope_as = title
				current_heir ?= { save_scope_as = heir }
				random_title_heir = {
					limit = {
						save_temporary_scope_as = candidate_temp
						root = { has_appointment_invested_character = scope:candidate_temp }
					}
					save_scope_as = candidate
				}
				save_scope_as = landed_title
				try_create_important_action = {
					important_action_type = action_invested_candidate_not_inheriting_admin_title
					landed_title = this
					recipient = scope:heir
					actor = scope:candidate
				}
			}
		}
	}

	unimportant = {
		scope:heir.house = root.house
	}

	effect = {
		scope:landed_title = {
			open_view_data = {
				view = title_view_window
			}
		}
	}
}
