﻿#Interactions relating to leaving factions

force_leave_faction_interaction = {
	category = interaction_category_vassal
	# special_interaction = force_leave_faction
	desc = force_leave_faction_interaction_desc
	icon = scroll_scales

	force_notification = yes
	greeting = positive
	notification_text = FORCE_LEAVE_FACTION_NOTIFICATION

	is_shown = {
		scope:recipient = {
			is_a_faction_member = yes
			liege = scope:recipient.liege
			scope:actor = scope:recipient.liege
			joined_faction = {
				OR = {
					faction_is_type = claimant_faction
					faction_is_type = independence_faction
					faction_is_type = liberty_faction
					faction_is_type = nation_fracturing_faction
				}
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			trigger_if = {
				limit = { government_allows = administrative }
				custom_tooltip = {
					text = force_leave_faction_admin_requirement_desc
					OR = {
						has_usable_hook = scope:recipient
						AND = {
							influence >= scope:actor.major_influence_value
							scope:recipient ?= {
								NOT = { opinion = { target = scope:actor value <= -50 } }
							}
						}
					}
				}
			}
			trigger_else = {
				# Make sure to update the NFaction::POTENTIAL_FORCE_LEAVE_HOOK_TYPE define if you change the type of hook used here
				has_usable_hook = scope:recipient
			}
			NOT = { is_at_war_with = scope:recipient }
		}
	}
	
	on_accept = {
		scope:actor = {
			send_interface_message = {
				type = event_faction_neutral
				title = force_leave_faction_interaction_notification
				right_icon = scope:recipient
				if = {
					limit = { scope:hook = yes }
					use_hook = scope:recipient
				}
				else_if = {
					limit = { scope:influence = yes }
					change_influence = {
						value = major_influence_value
						multiply = -2
					}
				}
			}
		}
		scope:recipient = {
			leave_faction_with_cooldown_effect = {
				FACTION = joined_faction
				YEARS = 5
			}
		}
	}

	auto_accept = yes

	#Use hook
	send_option = {
		is_valid = {
			exists = scope:recipient
			scope:actor ?= { has_usable_hook = scope:recipient }
		}
		flag = hook
		localization = GENERIC_SPEND_A_HOOK
	}

	#Spend influence
	send_option = {
		is_shown = {
			scope:actor = { government_allows = administrative }
			scope:actor.top_liege ?= { government_allows = administrative }
		}
		is_valid = {
			scope:actor ?= { influence >= scope:actor.major_influence_value }
			scope:recipient ?= {
				NOT = { opinion = { target = scope:actor value <= -50 } }
			}
		}
		flag = influence
		localization = SPEND_INFLUENCE
	}

	send_options_exclusive = yes
	
	# AI
	ai_targets = {
		ai_recipients = vassals
	}
	ai_frequency = 3
	
	ai_will_do = {
		base = 100
		modifier = {
			factor = 100
			scope:recipient = {
				joined_faction = {
					faction_power >= faction_power_threshold
				}
			}
		}
	}
}
