﻿
adventurer_recruit_local_interaction = {
	category = interaction_category_laamp
	icon = travel_mixed
	common_interaction = yes

	desc = adventurer_recruit_local_interaction_desc
	interface_priority = 100

	needs_recipient_to_open = no
	can_send_despite_rejection = yes
	#ai_accept_negotiation = yes

	is_shown = {
		scope:actor = {
			is_ruler = yes
			is_landless_adventurer = yes
		}
		scope:secondary_actor = {
			is_adult = yes
			OR = {
				this = scope:actor
				is_courtier_of = scope:actor
			}	
		}
	}

	is_valid_showing_failures_only = {
		scope:secondary_actor = {
			has_short_disease_trigger = no
		}
	}

	send_option = {
		is_valid = {
			scope:actor = {
				has_usable_hook = scope:recipient
			}
		}
		flag = hook
		localization = SCHEME_HOOK
	}

	send_option = {
		is_valid = {
			scope:actor.domicile ?= {
				provisions >= {
					value = 200
				}
			}
			scope:secondary_recipient ?= {
				NOT = { has_trait = paranoid }
			}
		}
		flag = provisions
		localization = USE_PROVISIONS
	}

	send_option = {
		is_valid = {
			scope:actor = {
				has_trait = gallowsbait
			}
			scope:secondary_recipient ?= {
				prowess < scope:secondary_actor.prowess
			}
		}
		flag = force
		localization = RCRL_USE_VIOLENCE
	}

	send_options_exclusive = no

	redirect = {
		if = {
			limit = {
				scope:recipient = {
					this = scope:actor
				}
			}
			scope:actor = {
				save_scope_as = secondary_actor
			}
		}
		else_if = {
			limit = {
				scope:recipient = {
					is_courtier_of = scope:actor
				}	
			}
			scope:recipient = {
				save_scope_as = secondary_actor
			}
		}

		random_pool_character = {
			province = scope:actor.location
			limit = {
				is_available_adult = yes
			}
			save_scope_as = secondary_recipient
		}
		scope:secondary_recipient ?= {
			location.county.holder = {
				save_scope_as = recipient
			}
		}

		clear_saved_scope = secondary_recipient
		
	}

	cooldown = { months = adventurer_recruit_local_interaction_major_cooldown }

	populate_actor_list = {
		scope:actor = {
			every_courtier = {
				limit = {
					basic_is_available_ai = yes
					has_short_disease_trigger = no
				}
				add_to_list = characters
			}
		}
		scope:actor = {
			if = {
				limit = {
					is_alive = yes
					is_imprisoned = no
					is_incapable = no
					has_short_disease_trigger = no
				}
				add_to_list = characters
			}
		}
	}

	populate_recipient_list = {
		every_pool_character = {
			province = scope:actor.location
			limit = {
				is_available_adult = yes
			}
			add_to_list = characters
		}
	}

	cost = {
		prestige = { 
			value = 100
			if = {
				limit = {
					scope:secondary_recipient ?= {
						is_lowborn = no
					}
				}
				add = 100
			}
		}
		piety = {
			value = 0
			if = {
				limit = {
					scope:secondary_recipient ?= {
						faith = {
							faith_hostility_level = {
								target = scope:actor.faith
								value > 2
							}
						}
					}
				}
				add = 50
				if = {
					limit = {
						scope:secondary_recipient ?= {
							is_lowborn = no
						}
					}
					add = 50
				}
			}
			
		}
	}

	on_accept = {
		rcrl_recruit_local_interaction_on_accept_effect = yes
		if = {
			limit = {
				scope:force = yes
			}
			scope:actor = {
				custom_tooltip = rcrl_recruit_local_people_using_violence_tt
				add_trait_xp = {
					trait = gallowsbait
					track = bandit
					value = 5
				}
				if = {
					limit = {
						scope:secondary_recipient ?= {
							faith = { #Same religion - But faith should not be considered Hostile or Evil
								religion = scope:actor.faith.religion
								faith_hostility_level = {
									target = scope:actor.faith
									value < 2
								}
							}
						}
					}
					add_piety = -25
				}
			}
			scope:secondary_recipient ?= {
				add_opinion = {
					modifier = demanded_recruitment
					target = scope:actor
				}
			}
		}
		if = {
			limit = {
				scope:hook = yes
			}
			scope:actor = {
				use_hook = scope:recipient
			}
			scope:secondary_recipient ?= {
				add_opinion = {
					modifier = demanded_recruitment
					target = scope:actor
				}
				add_opinion = {
					modifier = demanded_recruitment
					target = scope:recipient
					opinion = -10
				}
			}
		}
		else_if = {
			limit = {
				scope:force = no
			}
			scope:secondary_recipient ?= {
				add_opinion = {
					modifier = kindness_opinion
					target = scope:secondary_actor
					opinion = 5
				}
			}
			scope:secondary_actor = {
				add_opinion = {
					modifier = friendliness_opinion
					target = scope:secondary_recipient
					opinion = 5
				}
				if = {
					limit = {
						can_set_relation_potential_friend_trigger = { CHARACTER = scope:secondary_recipient }
					}
					set_relation_potential_friend = scope:secondary_recipient
					scope:secondary_recipient = {
						show_as_tooltip = {
							set_relation_potential_friend = scope:secondary_actor
						}
					}
				}
			}
			
		}
		if = {
			limit = {
				scope:provisions = yes
			}
			scope:actor = {
				custom_tooltip = {
					text = rcrl_recruit_local_people_using_provisions_tt
					domicile ?= {
						change_provisions = {
							value = 200
							multiply = -1
						}
					}
				}
				stress_impact = {
					arbitrary = medium_stress_impact_gain
					callous = medium_stress_impact_gain
					sadistic = major_stress_impact_gain
					generous = minor_stress_impact_loss
					humble = minor_stress_impact_loss
					compassionate = medium_stress_impact_loss
				}
			}
			scope:secondary_recipient ?= {
				add_opinion = {
					modifier = passed_favor_opinion
					target = scope:actor
					opinion = 10
				}
			}
			if = {
				limit = {
					scope:actor = {
						OR = {
							has_trait = fickle
							has_trait = eccentric
						}
					}
				}
				random_list = {
					25 = {
						scope:actor = {
							stress_impact = {
								fickle = minor_stress_impact_gain
								eccentric = minor_stress_impact_gain
							}
						}
					}
					25 = {
						scope:actor = {
							stress_impact = {
								fickle = minor_stress_impact_loss
								eccentric = minor_stress_impact_loss
							}
						}
					}
					25 = {
					}
				}
			}
		}
	}

	on_decline = {
		if = {
			limit = {
				scope:force = yes
			}
			configure_start_single_combat_effect = {
				SC_INITIATOR = scope:secondary_actor
				SC_ATTACKER = scope:secondary_actor
				SC_DEFENDER = scope:secondary_recipient
				FATALITY = no
				FIXED = no
				LOCALE = terrain_scope
				OUTPUT_EVENT = rcrl_perk_interaction.0101
				INVALIDATION_EVENT = fp1_tbc.0102
			}
		}
	}

	auto_accept = no

	ai_accept = {
 		base = -50

		modifier = {
			scope:hook = yes
			add = 25
			desc = SCHEME_HOOK_USED
		}

		modifier = {
			add = {
				value = scope:secondary_actor.diplomacy
			}
			desc = rcrl_recruit_local_people_sway_my_diplomacy_reason
		}
		
 		opinion_modifier = {
			trigger = {
				scope:recipient = {
					opinion = {
						value > 0
						target = scope:actor
					}
				}
			}
 			opinion_target = scope:actor
 			multiplier = 0.25
 		}

		opinion_modifier = {
			trigger = {
				scope:recipient = {
					opinion = {
						value < 0
						target = scope:actor
					}
				}
			}
 			opinion_target = scope:actor
 			multiplier = 0.5
 		}

		opinion_modifier = {
			trigger = {
				exists = scope:secondary_recipient
			}
			who = scope:secondary_recipient
			opinion_target = scope:secondary_actor
			multiplier = 0.5
		}

 		#Relations & relatives (with actor)
 		modifier = {
			scope:secondary_recipient ?= {	
 				has_relation_lover = scope:actor
			}
			add = 100
 			desc = RCRL_AI_YOUR_LOVER
 		}

 		modifier = {
			scope:secondary_recipient ?= {
 				has_relation_friend = scope:actor
			}
 			add = 75
 			desc = RCRL_AI_YOUR_FRIEND
 		}

 		modifier = {
			scope:secondary_recipient ?= {
	 			is_child_of = scope:actor
			}
			add = 160
 			desc = RCRL_AI_YOUR_CHILD
 		}

 		modifier = {
			scope:secondary_recipient ?= {
 				this.dynasty.dynast = scope:actor
			}
 			add = 30
 			desc = RCRL_AI_YOU_ARE_THE_DYNAST
 		}

 		modifier = {
			scope:secondary_recipient ?= {
 				this.house.house_head = scope:actor
			}
 			add = 60
 			desc = RCRL_AI_YOU_ARE_THE_HOUSE_HEAD
 		}
		
		modifier = {
			scope:secondary_recipient ?= {
 				NOT = { is_child_of = scope:actor }
 				NOT = { is_close_family_of = scope:actor }
				is_extended_family_of = scope:actor
			}
 			add = 30
 			desc = RCRL_RCRL_AI_YOUR_LOVER
 		}

 		modifier = {
			scope:secondary_recipient ?= {
 				NOT = { is_child_of = scope:actor }
 				is_close_family_of = scope:actor
			}
 			add = 75
 			desc = RCRL_RCRL_AI_YOUR_LOVER
 		}

 		modifier = {
			scope:secondary_recipient ?= {
 				is_spouse_of = scope:actor
			}
 			add = 160
 			desc = RCRL_AI_YOUR_SPOUSE
 		}

 		#Family (at location)
 		modifier = {
 			exists = location
			scope:secondary_recipient ?= {
				any_consort_not_in_traveling_family_trigger = yes
			}
 			desc = AI_LEAVING_MY_SPOUSE
 			add = -100
 		}

 		modifier = {
 			exists = location
			scope:secondary_recipient ?= {
	 			any_child_not_in_traveling_family_trigger = yes
			}
			desc = AI_LEAVING_MY_CHILD
 			add = -100
 		}

 		modifier = {
 			add = 500
 			desc = AI_WANDERLUST
			is_child_of = scope:actor
 			has_character_modifier = lust_for_adventure
 		}

		
		compatibility_modifier = {
			trigger = {
				exists = scope:secondary_recipient
			}
			who = scope:secondary_recipient
			compatibility_target = scope:secondary_actor
			min = -50
			max = 40
			multiplier = 1.5
		}

		#Wandering characters (who aren't doing anything else)
		modifier = {
 			add = {
				value = 10
				
				if = {
					limit = {
						scope:secondary_recipient ?= {
							faith = scope:actor.faith
						}
					}
					add = 10
				}
				else_if = {
					limit = {
						scope:secondary_recipient ?= {
							faith = { #Same religion - But faith should not be considered Hostile or Evil
								religion = scope:actor.faith.religion
								faith_hostility_level = {
									target = scope:actor.faith
									value < 2
								}
							}
						}
					}
					add = 5
				}
				if = {
					limit = {
						scope:secondary_recipient ?= {
							culture = scope:actor.culture
						}
					}
					add = 10
				}
				else_if = {
					limit = {
						scope:secondary_recipient ?= {
							culture = {
								has_same_culture_heritage = scope:actor.culture
							}
						}
					}
					add = 5
				}
				if = {
					limit = {
						scope:secondary_recipient ?= {
							has_trait = trusting
						}
					}
					add = 10
				}
				if = {
					limit = {
						scope:secondary_recipient ?= {
							OR = {
								has_trait = lazy
								has_trait = shy
							}
						}
					}
					add = -10
				}
			}
 			desc = AI_CAN_BE_PERSUADED_TO_STAY
			
			NOT = { has_relation_rival = scope:actor }
 		}

		modifier = {
			scope:provisions = yes
			add = 10
			desc = RCRL_OFFER_MEAL_REASON
		}

		modifier = {
			scope:force = yes
			add = 10
			desc = RCRL_FORCE_THEM_JOIN_REASON
		}
	}
	
	ai_targets = { ai_recipients = self }
	ai_frequency = 240
	
	ai_potential = {
		is_landless_adventurer = yes
	}
	
	ai_will_do = {
		base = 0
	}
}
