﻿provoke_vassals_interaction = {
	icon = provoke_vassals
	category = interaction_category_hostile
	scheme = provoke_vassals
	common_interaction = no
	interface_priority = 60
	ignores_pending_interaction_block = yes
	send_name = START_SCHEME

	desc = provoke_vassals_interaction_desc

	is_shown = {
		scope:recipient != scope:actor
		scope:actor = {
			is_adult = yes
		}
		scope:recipient = {
			highest_held_title_tier >= tier_kingdom
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			can_start_scheme = {
				type = provoke_vassals
				target_character = scope:recipient
			}
		}
		scope:recipient = { 
			highest_held_title_tier >= tier_kingdom
		}
		trigger_if = {
			limit = {
				scope:actor = {
					is_landless_adventurer = yes
				}
			}
			#Has to be used instead of diplo range checks in laamp to landed interactions
			ep3_laamp_diplo_range_trigger = {
				TARGET = scope:recipient
				LAAMP = scope:actor
			}
		}
	}

	# Scheme Starter Packages
	options_heading = schemes.t.agent_packages
	send_options_exclusive = yes
	## Balanced agents.
	send_option = {
		flag = agent_focus_balance
		current_description = provoke_vassals_interaction.tt.agent_focus_balance
	}
	## Focused on Success Chance.
	send_option = {
		flag = agent_focus_success
		current_description = provoke_vassals_interaction.tt.agent_focus_success
	}
	## Focused on Speed.
	send_option = {
		flag = agent_focus_speed
		current_description = provoke_vassals_interaction.tt.agent_focus_speed
	}
    ## Focused on Secrecy.
	send_option = {
		flag = agent_focus_secrecy
		current_description = provoke_vassals_interaction.tt.agent_focus_secrecy
	}
	on_accept = {
		scope:actor = {
			stress_impact = {
				shy = medium_stress_impact_gain
				craven = medium_stress_impact_gain
				fickle = minor_stress_impact_gain
			}
		}
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = provoke_vassals_interaction_notification
				left_icon = scope:actor					
				right_icon = scope:recipient

				# Success.
				if = {
					limit = { scope:agent_focus_success ?= yes }
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = provoke_vassals
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
						# Success.
						AGENT_1 = agent_rabble_rouser
						AGENT_2 = agent_diplomat
						AGENT_3 = agent_diplomat
						# Speed.
						AGENT_4 = agent_gabbler
						# Secrecy.
						AGENT_5 = agent_justiciar
					}
				}
				# Speed.
				else_if = {
					limit = { scope:agent_focus_speed ?= yes }
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = provoke_vassals
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
						# Success.
						AGENT_1 = agent_rabble_rouser
						# Speed.
						AGENT_2 = agent_gabbler
						AGENT_3 = agent_gabbler
						AGENT_4 = agent_herald
						# Secrecy.
						AGENT_5 = agent_justiciar
					}
				}
				# Secrecy.
				else_if = {
					limit = { scope:agent_focus_secrecy ?= yes }
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = provoke_vassals
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
						# Success.
						AGENT_1 = agent_rabble_rouser
						# Speed.
						AGENT_2 = agent_gabbler
						# Secrecy.
						AGENT_3 = agent_justiciar
						AGENT_4 = agent_justiciar
						AGENT_5 = agent_amanuensis
					}
				}
				# Balanced.
				else = {
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = provoke_vassals
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
						# Success.
						AGENT_1 = agent_rabble_rouser
						AGENT_2 = agent_diplomat
						# Speed.
						AGENT_3 = agent_gabbler
						AGENT_4 = agent_herald
						# Secrecy.
						AGENT_5 = agent_justiciar
					}
				}
				show_as_tooltip = {
					stress_impact = {
						shy = medium_stress_impact_gain
						craven = medium_stress_impact_gain
						fickle = minor_stress_impact_gain
					}
				}
			}
		}
	}
	
	auto_accept = yes
	ai_targets = { 
		ai_recipients = neighboring_rulers
	}
	ai_frequency_by_tier = {
		barony = 0
		county = 0
		duchy = 72
		kingdom = 24
		empire = 36
		hegemony = 36
	}

	ai_potential = {
		is_ruler = yes
		ai_boldness >= low_positive_ai_value
		OR = {
			AND = {
				diplomacy >= decent_skill_rating
				intrigue >= decent_skill_rating
			}
			intrigue >= high_skill_rating
			diplomacy >= high_skill_rating
		}
		exists = court_position:rabble_rouser_court_position
		exists = var:rabble_rouser_is_rousing_rabble
		var:rabble_rouser_is_rousing_rabble = yes
	}

	ai_will_do = {
		# They shouldn't always do this.
		base = -100

		# Opinion
		opinion_modifier = {
			opinion_target = scope:recipient
			multiplier = -1
		}
		# At war with target
		modifier = {
			add = 100
			scope:actor = { is_at_war_with = scope:recipient } 
		}

		ai_value_modifier = { ai_honor = -1 }
		ai_value_modifier = { ai_boldness = 1 }
		
		# Provoked Faction exists
		modifier = {
			scope:recipient = {
				any_targeting_faction = {
					OR = {
						faction_is_type = provoked_dissolution_faction
						faction_is_type = provoked_independence_faction
					}
				}
			}
			add = -1000
		}

		# Traits
		# Positive modifiers
		modifier = {
			add = 25
			scope:actor = { has_trait = brave }
			desc = ROUSE_RABBLE_BRAVE
		}
		modifier = {
			add = 50
			scope:actor = { has_trait = gregarious }
			desc = ROUSE_RABBLE_GREGARIOUS
		}
		modifier = {
			add = 25
			scope:actor = { has_trait = diplomat }
			desc = ROUSE_RABBLE_DIPLOMAT
		}
		modifier = {
			add = 50
			scope:actor = { has_trait = schemer }
			desc = ROUSE_RABBLE_SCHEMER
		}
		modifier = {
			add = 25
			scope:actor = { has_trait = lifestyle_wayfarer }
			desc = ROUSE_RABBLE_WAYFARER
		}
		modifier = {
			add = 75
			scope:actor = { has_trait = peasant_leader }
			desc = ROUSE_RABBLE_PEASANT_LEADER
		}
		modifier = {
			add = 75
			scope:actor = { has_trait = populist_leader }
			desc = ROUSE_RABBLE_POPULIST_LEADER
		}
		modifier = {
			add = 50
			scope:actor = { has_trait = ambitious }
			desc = PROVOKE_VASSALS_AMBITIOUS
		}
		modifier = {
			add = {
				value = 25
				scope:actor = {
					if = { 
						limit = {
							has_trait_xp = { trait = lifestyle_reveler value >= 50 }
						}
						add = 25
					}
				}
				scope:actor = {
					if = { 
						limit = {
							has_trait_xp = { trait = lifestyle_reveler value >= 100 }
						}
						add = 25
					}
				}
			}
			desc = ROUSE_RABBLE_REVELER
		}
		modifier = {
			add = {
				value = 15
				scope:actor = {
					if = { 
						limit = {
							OR = {
								has_trait_xp = { trait = lifestyle_traveler track = travel value >= 50 }
								has_trait_xp = { trait = lifestyle_traveler track = danger value >= 50 }
							}
						}
						add = 35
					}
				}
				scope:actor = {
					if = { 
						limit = {
							OR = {
								has_trait_xp = { trait = lifestyle_traveler track = travel value >= 100 }
								has_trait_xp = { trait = lifestyle_traveler track = danger value >= 100 }
							}
						}
						add = 50
					}
				}
			}
			desc = ROUSE_RABBLE_TRAVELER
		}

		# Negative modifiers
		modifier = {
			add = -75
			scope:actor = { has_trait = craven }
			desc = ROUSE_RABBLE_CRAVEN
		}
		modifier = {
			add = -25
			scope:actor = { has_trait = lazy }
			desc = ROUSE_RABBLE_LAZY
		}
		modifier = {
			add = -75
			scope:actor = { has_trait = shy }
			desc = ROUSE_RABBLE_SHY
		}
		modifier = {
			add = -25
			scope:actor = { has_trait = fickle }
			desc = ROUSE_RABBLE_FICKLE
		}
		modifier = {
			add = -75
			scope:actor = { has_trait = reclusive }
			desc = ROUSE_RABBLE_RECLUSIVE
		}
		modifier = {
			add = -100
			scope:actor = { has_trait = infirm }
			desc = ROUSE_RABBLE_INFIRM
		}
	}
}
