﻿force_step_down_interaction = {
	icon = icon_force_to_step_down
	common_interaction = no
	interface_priority = 135
	category = interaction_category_succession
	filter_tags = { admin_governor }							 

	filter_tags = { admin_governor }							 
	cooldown_against_recipient = { years = 5 }

	target_type = title
	target_filter = recipient_domain_titles
	can_be_picked_title = {
		scope:target = {
			tier = tier_duchy
			is_noble_family_title = no
		}
	}
	has_valid_target_showing_failures_only = {
		scope:target = {
			tier = tier_duchy
			is_noble_family_title = no
		}
	}

	ai_target_quick_trigger = { adult = yes }
	ai_targets = {
		ai_recipients = vassals
		ai_recipients = peer_vassals
		max = 10
	}

	ai_maybe = yes
	ai_min_reply_days = 4
	ai_max_reply_days = 9
	can_send_despite_rejection = yes
	popup_on_receive = yes

	greeting = negative
	notification_text = FORCE_STEP_DOWN_PROPOSAL

	pre_answer_yes_key = ACCEPT
	pre_answer_no_key = DECLINE

	ai_frequency = 180

	is_shown = {
		scope:actor = {
			government_allows = administrative
			is_independent_ruler = no
			this != scope:recipient
		}
		scope:recipient = {
			government_allows = administrative
			is_governor = yes
		}
	}

	is_highlighted = {
		scope:recipient ?= {
			any_held_title = {
				current_heir ?= {
					OR = {
						scope:actor ?= this
						house ?= scope:actor.house
					}
				}
			}
		}
	}

	highlighted_reason = HIGHLIGHTED_FORCE_STEP_DOWN_HEIR
	is_valid_showing_failures_only = {
		scope:actor = {
			is_adult = yes
			is_imprisoned = no
			is_in_civil_war = no
			NOT = { has_trait = slave }
		}
		scope:recipient = {
			is_in_civil_war = no
		}
	}

	desc = scheme_interaction_tt_force_step_down_approved

	send_options_exclusive = no
	send_option = {
		flag = hook
		is_valid = {
			scope:actor = { has_usable_hook = scope:recipient }
			NOT = {
				scope:recipient = { has_hook = scope:actor }
			}
		}
		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"
	send_option = {
		flag = influence
		is_valid = {
			scope:actor.influence >= massive_influence_value
		}
		localization = SPEND_INFLUENCE
	}
	send_option = {
		flag = gold
		is_valid = {
			scope:actor.gold >= scope:actor.massive_gold_value
		}
		localization = GENERIC_SPEND_GOLD
	}
	send_option = {
		flag = criminal_secret_recipient
		is_shown = {
			scope:recipient = {
				any_secret = {
					is_criminal_for = scope:recipient
					is_known_by = scope:actor
					can_be_exposed_by = scope:actor
				}
			}
		}
		localization = LEVERAGE_CRIMINAL_SECRET_RECIPIENT
	}

	on_accept = {
		scope:actor = {
			# Save the number of held governorships
			scope:recipient = {
				save_scope_value_as = {
					name = recipient_number_of_governorships
					value = {
						value = 0
						every_held_title = {
							limit = {
								tier >= tier_duchy
								is_noble_family_title = no
							}
							add = 1
						}
					}
				}
			}

			if = {
				limit = { scope:hook = yes }
				use_hook = scope:recipient
			}
			if = {
				limit = { scope:influence = yes }
				change_influence = {
					value = massive_influence_loss
					multiply = 2
					multiply = scope:recipient_number_of_governorships
				}
			}
			if = {
				limit = { scope:gold = yes }
				pay_short_term_gold = {
					target = scope:recipient
					gold = {
						value = massive_gold_value
						multiply = scope:recipient_number_of_governorships
					}
				}
			}
			if = {
				limit = { scope:criminal_secret_recipient = yes}
				scope:actor = {
					random_known_secret = {
						limit = {
							secret_owner = scope:recipient
							is_criminal_for = scope:recipient
							can_be_exposed_by = scope:actor
						}
						disable_exposure_by = scope:actor
					}
				}
			}
			send_interface_toast = {
				type = event_toast_effect_good
				title = force_governor_resignation_accepted_toast
				left_icon = scope:target
				right_icon = scope:recipient
				scope:recipient = {
					custom_tooltip = loses_target_title_tt
					if = {
						limit = { is_ai = yes }
						add_opinion = {
							target = scope:actor
							modifier = forced_my_resignation_opinion
						}
					}
					if = {
						limit = { can_set_relation_rival_trigger = { CHARACTER = scope:actor } }
						set_relation_rival = {
							target = scope:actor
							reason = rival_forced_my_resignation_reason
						}
					}
					house ?= {
						if = {
							limit = {
								this != scope:actor.house
							}
							every_house_member = {
								custom = custom.every_house_member_recipient
								limit = {
									is_ai = yes
									this != scope:secondary_recipient
								}
								add_opinion = {
									target = scope:actor
									modifier = forced_my_house_members_resignation_opinion
								}
							}
						}
					}
	
					force_step_down_landed_titles = yes
				}
			}
		}
	}

	on_decline = {
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_bad
				title = force_governor_resignation_declined_toast
				left_icon = scope:target
				right_icon = scope:recipient

				change_influence = major_influence_loss
				add_prestige = medium_prestige_loss
				scope:recipient = {
					add_opinion = {
						target = scope:actor
						modifier = attempted_force_step_down_opinion
					}
					if = {
						limit = { can_set_relation_rival_trigger = { CHARACTER = scope:actor } }
						set_relation_rival = {
							target = scope:actor
							reason = rival_attempted_to_force_my_resignation_reason
						}
					}
				}
				if = {
					limit = { scope:criminal_secret_recipient = yes}
					scope:actor = {
						random_known_secret = {
							limit = {
								secret_owner = scope:recipient
								is_criminal_for = scope:recipient
								can_be_exposed_by = scope:actor
							}
							expose_secret = scope:actor
						}
					}
				}
			}
		}
	}

	auto_accept = {
		trigger_if = {
			limit = {
				scope:hook ?= yes
				scope:actor = { has_strong_hook = scope:recipient }
			}
			custom_description = {
				text = "spending_hook"
				subject = scope:actor
				object = scope:recipient
				scope:hook ?= yes
				scope:actor = { has_strong_hook = scope:recipient }
			}
		}
		trigger_else = { always = no }
	}

	ai_accept = {
		base = 0

		# SEND OPTIONS
		modifier = {
			scope:hook = yes
			add = 30
			desc = SCHEME_WEAK_HOOK_USED
		}
		modifier = {
			desc = INFLUENCE_REASON
			scope:influence = yes
			add = {
				value = 20
				multiply = scope:actor.influence_level
				min = 5
			}
		}
		modifier = {
			desc = GOLD_REASON
			scope:gold = yes
			add = 30
		}
		modifier = {
			desc = RECIPIENT_SECRET
			scope:criminal_secret_recipient = yes
			add = 50
		}

		# TRAITS
		modifier = {
			scope:recipient = { has_trait = craven }
			add = 10
			desc = INTERACTION_CRAVEN
		}
		modifier = {
			scope:recipient = { has_trait = trusting }
			add = 5
			desc = INTERACTION_TRUSTING
		}
		modifier = {
			scope:recipient = { has_trait = generous }
			add = 5
			desc = INTERACTION_GENEROUS
		}
		modifier = {
			scope:recipient = { has_trait = lazy }
			add = 10
			desc = INTERACTION_LAZY
		}
		modifier = {
			scope:recipient = { has_trait = paranoid }
			add = -20
			desc = INTERACTION_PARANOID
		}
		modifier = {
			scope:recipient = { has_trait = patient }
			add = -5
			desc = INTERACTION_PATIENT
		}
		modifier = {
			scope:recipient = { has_trait = brave }
			add = -10
			desc = INTERACTION_BRAVE
		}
		modifier = {
			scope:recipient = { has_trait = greedy }
			add = -10
			desc = INTERACTION_GREEDY
		}
		modifier = {
			scope:recipient = { has_trait = ambitious }
			add = -20
			desc = INTERACTION_AMBITIOUS
		}

		# INTRIGUE COMPARISON
		modifier = {
			add = {
				value = scope:actor.intrigue
				multiply = 2
			}
			desc = INTERACTION_ACTOR_INTRIGUE
		}
		modifier = {
			add = {
				value = scope:recipient.intrigue
				multiply = -2
			}
			desc = INTERACTION_RECIPIENT_INTRIGUE
		}
	}

	ai_potential = {
		NOT = {
			any_scheme = {
				is_scheme_category = political
			}
		}
		government_allows = administrative
		is_independent_ruler = no
		highest_held_title_tier >= tier_duchy
	}

	ai_will_do = {
		base = -200

		opinion_modifier = {
			who = scope:actor
			opinion_target = scope:recipient
			multiplier = -1
		}

		modifier = { # AI should really only use this if they have a house member in line for the title
			house = {
				any_house_member = {
					scope:recipient.primary_title = {
						place_in_line_of_succession = {
							target = prev
							value <= 3
						}
					}
				}
			}
			add = 100
		}

		#Personality
		modifier = {
			has_trait = vengeful
			add = 10
		}

		modifier = {
			has_trait = deceitful
			add = 10
		}

		modifier = {
			has_trait = honest
			add = -10
		}

		# House & Family
		modifier = {
			is_close_family_of = scope:recipient
			add = -500
		}
		modifier = {
			house = scope:recipient.house
			add = -500
		}

		#Feuds
		modifier = {
			house.house_head ?= {
				any_owned_story = {
					story_type = story_cycle_house_feud
					has_variable = house_feud_house
					var:house_feud_house = scope:recipient.house
				}
			}
			add = 75
		}

		# Relationships
		modifier = {
			add = 25
			has_any_mild_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}

		modifier = {
			add = 50
			has_any_moderate_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}

		modifier = {
			add = 100
			has_any_worst_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}

		modifier = {
			add = -50
			has_any_mild_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}

		modifier = {
			add = -100
			has_any_moderate_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}

		modifier = {
			factor = 0
			has_any_best_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}
	}
}