﻿evict_adventurer_interaction = {
	common_interaction = yes
	category = interaction_category_diplomacy
	cooldown_against_recipient = { years = 5 }
	greeting = positive
	icon = icon_evict_adventurer
	desc = evict_adventurer_interaction_desc

	popup_on_receive = yes
	pause_on_receive = yes

	interface_priority = 60
	ai_min_reply_days = 4
	ai_max_reply_days = 9

	is_shown = {
		has_ep3_dlc_trigger = yes
		scope:actor = { is_landed = yes }
		NOT = { scope:recipient = scope:actor }
		scope:recipient = {
			government_has_flag = government_is_landless_adventurer
			NOT = { has_character_flag = agot_landless_interaction_blocker }
			is_landed = no
		}
		# # LOTR compatibility
		# 	scope:actor = {
		# 		is_wastelands = no
		# 		is_in_valinor = no
		# 	}
		# 	scope:recipient = {
		# 		is_wastelands = no
		# 		is_in_valinor = no
		# 	}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			is_at_war = no
			NOR = {
				is_spouse_of = scope:recipient
				has_relation_friend = scope:recipient
				has_relation_lover = scope:recipient
			}
		}
		scope:recipient = {
			# Adventurer must be in the subrealm
			domicile.domicile_location.county.holder ?= {
				OR = {
					this = scope:actor
					any_liege_or_above = { this ?= scope:actor }
				}
			}
		}
		scope:actor = {
			NOT = {
				has_opinion_modifier = {
					modifier = crushed_capture_attempt_opinion
					target = scope:recipient
				}
			}
		}
		# AI should not against hired adventurers
		trigger_if = {
			limit = {
				scope:actor = { is_ai = yes }
			}
			scope:actor = {
				opinion = {
					target = scope:recipient
					value < 25
				}
			}
			NOT = {
				scope:recipient = {
					any_character_active_contract = { task_contract_employer = scope:actor }
				}
			}
		}
		scope:recipient = {
			is_busy_in_events_localised = yes
			NOT = { has_strong_hook = scope:actor }
		}
		trigger_if = {
			limit = {
				NOT = { exists = global_var:AGOT_is_loaded }
			}
			# Story blockers.
			## Hereward cannot be exiled by active participants in the Harrying of the North.
			disable_interaction_for_hereward_trigger = yes
			## Hasan cannot be exiled by anyone during his story.
			disable_interaction_for_hasan_trigger = yes
		}
		# # LOTR compatibility
		# disable_interaction_for_bountig_trigger = yes
	}

	on_send = {
		scope:recipient = {
			send_interface_toast = {
				type = diplo_contract_scheme_invalidated_message
				title = evict_adventurer_interaction.tt.contracts_invalidated.t
				right_icon = scope:actor
				custom_tooltip = {
					text = evict_adventurer_interaction.tt.contracts_invalidated
					every_character_task_contract = {
						limit = {
							task_contract_location.county.holder = {
								OR = {
									this = scope:actor
									any_liege_or_above = { this = scope:actor }
								}
							}
						}
						invalidate_contract = yes
					}
					# We also need to invalidate your active contract, if you've got one, since you need to be travelling.
					every_character_active_contract = { invalidate_contract = yes }
				}
			}
		}
	}

	on_accept = {
		scope:actor = { save_scope_as = expeller }
		scope:recipient = {
			save_scope_as = adventurer
			add_opinion = {
				target = scope:actor
				modifier = demanded_eviction_opinion
			}
			custom_tooltip = evict_adventurer_contracts_tt
		}
		scope:actor = {
			custom_description_no_bullet = {
				text = evict_adventurer_consequences_tt
				object = scope:recipient
				subject = scope:actor
			}
			custom_tooltip = evict_adventurer_casus_belli_tt
			show_as_tooltip = {
				add_opinion = {
					target = scope:recipient
					modifier = eviction_ignored_opinion
				}
			}
		}
		scope:recipient = {
			set_variable = {
				name = adventurer_expeller
				value = scope:actor
				months = 4
			}
			trigger_event = {
				id = loaa_eviction_events.0500
				days = 1
			}
			trigger_event = {
				id = loaa_eviction_events.0501
				months = 3
			}
		}
	}

	on_decline = {
		scope:recipient = {
			start_war = {
				cb = ep3_laamp_apprehend_adventurer_cb
				target = scope:actor
			}
		}
	}

	auto_accept = yes

	ai_frequency = 6
	ai_targets = {
		ai_recipients = sub_realm_domicile_owners
		max = 10
	}
	ai_potential = {
		is_at_war = no
		is_imprisoned = no
		NOT = { has_trait = incapable }
	}
	ai_will_do = {
		base = -25
		opinion_modifier = {
			who = scope:actor
			opinion_target = scope:recipient
			multiplier = -0.5
		}
		# Independent rulers or kings and over will happily exile claimants.
		modifier = {
			add = 250
			OR = {
				is_independent_ruler = yes
				highest_held_title_tier >= tier_kingdom
			}
			scope:recipient = {
				any_claim = {
					tier >= scope:actor.highest_held_title_tier
					holder ?= scope:actor
				}
			}
		}
		modifier = {
			add = 10
			has_opinion_modifier = {
				modifier = failed_task_contract_opinion
				target = scope:recipient
			}
		}
		modifier = {
			add = 30
			has_opinion_modifier = {
				modifier = left_war_early
				target = scope:recipient
			}
		}
		modifier = {
			add = 100
			has_opinion_modifier = {
				modifier = switched_sides_in_war
				target = scope:recipient
			}
		}
		modifier = {
			add = {
				if = {
					limit = {
						OR = {
							has_opinion_modifier = {
								modifier = gallowsbait_scum_opinion
								target = scope:recipient
								value >= 100
							}
							has_opinion_modifier = {
								modifier = succeeded_criminal_contract_against_me_opinion
								target = scope:recipient
								value >= 100
							}
						}
					}
					add = 200
				}
				else_if = {
					limit = {
						OR = {
							has_opinion_modifier = {
								modifier = gallowsbait_scum_opinion
								target = scope:recipient
								value >= 80
							}
							has_opinion_modifier = {
								modifier = succeeded_criminal_contract_against_me_opinion
								target = scope:recipient
								value >= 80
							}
						}
					}
					add = 150
				}
				else_if = {
					limit = {
						OR = {
							has_opinion_modifier = {
								modifier = gallowsbait_scum_opinion
								target = scope:recipient
								value >= 60
							}
							has_opinion_modifier = {
								modifier = succeeded_criminal_contract_against_me_opinion
								target = scope:recipient
								value >= 60
							}
						}
					}
					add = 100
				}
				else_if = {
					limit = {
						OR = {
							has_opinion_modifier = {
								modifier = gallowsbait_scum_opinion
								target = scope:recipient
								value >= 40
							}
							has_opinion_modifier = {
								modifier = succeeded_criminal_contract_against_me_opinion
								target = scope:recipient
								value >= 40
							}
						}
					}
					add = 75
				}
				else_if = {
					limit = {
						OR = {
							has_opinion_modifier = {
								modifier = gallowsbait_scum_opinion
								target = scope:recipient
								value >= 20
							}
							has_opinion_modifier = {
								modifier = succeeded_criminal_contract_against_me_opinion
								target = scope:recipient
								value >= 20
							}
						}
					}
					add = 50
				}
				else_if = {
					limit = {
						OR = {
							has_opinion_modifier = {
								modifier = gallowsbait_scum_opinion
								target = scope:recipient
								value >= 0
							}
							has_opinion_modifier = {
								modifier = succeeded_criminal_contract_against_me_opinion
								target = scope:recipient
								value >= 0
							}
						}
					}
					add = 25
				}
			}
			OR = {
				has_opinion_modifier = {
					modifier = gallowsbait_scum_opinion
					target = scope:recipient
				}
				has_opinion_modifier = {
					modifier = succeeded_criminal_contract_against_me_opinion
					target = scope:recipient
				}
			}
		}
		# Factors must got at the bottom.
		## Don't evict people we can't beat up.
		modifier = {
			factor = 0
			scope:actor.current_military_strength < scope:recipient.military_strength_75_percent_value
		}
		## Don't evict anyone currently doing a job for us.
		modifier = {
			factor = 0
			scope:recipient = {
				any_character_task_contract = { task_contract_employer = scope:actor }
			}
		}
		## We _only_ evict if we actually dislike someone.
		first_valid = {
			# People close to us are more willing to put up with our bullshit.
			modifier = {
				factor = 0
				has_any_moderate_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
				opinion = {
					target = scope:recipient
					value > -30
				}
			}
			modifier = {
				factor = 0
				opinion = {
					target = scope:recipient
					value > 0
				}
			}
		}
	}
}