﻿@event_in_same_scheme_cooldown_years_value = 2

@laamp_base_contract_schemes_on_going_duel_diff_t1_value = medium_skill_rating
@laamp_base_contract_schemes_on_going_duel_diff_t2_value = decent_skill_rating
@laamp_base_contract_schemes_on_going_duel_diff_t3_value = high_skill_rating

@laamp_base_contract_schemes_duel_stress_wager_value = 30

@laamp_base_contract_schemes_0551_minimum_skill_value = high_skill_rating
@laamp_base_contract_schemes_1004_gallowsbait_xp_min_value = 25
@laamp_base_contract_schemes_1004_gallowsbait_xp_max_value = 55
@laamp_base_contract_schemes_1301_ai_min_prowess_value = 15
@laamp_base_contract_schemes_1782_min_gold_value = 50
@laamp_base_contract_schemes_2311_ai_weight_threshold_value = 35
@laamp_base_contract_schemes_2541_intrigue_threshold_value = extremely_high_skill_rating
@laamp_base_contract_schemes_2661_stewardship_threshold_value = extremely_high_skill_rating
@laamp_base_contract_schemes_2661_sacrifice_skill_threshold_value = decent_skill_rating
@laamp_base_contract_schemes_2671_prowess_gain_value = 1
@laamp_base_contract_schemes_3661_martial_threshold_value = extremely_high_skill_rating
@laamp_base_contract_schemes_3661_prowess_threshold_value = very_high_skill_rating
@laamp_base_contract_schemes_5901_min_gold_value = 50

namespace = loaa_laamp_base_contract_schemes

##################################################
# SCRIPTED TRIGGERS & EFFECTS

# Syncs stress lost from successfully completing a non-criminal contract scheme.
##################################################

# Syncs stress gained from successfully completing a non-criminal contract scheme.
scripted_effect loaa_laamp_base_contract_schemes_acknowledge_success_criminal_stress_effect = {
	stress_impact = {
		arrogant = minor_stress_impact_loss
		arbitrary = minor_stress_impact_loss
		just = medium_stress_impact_gain
	}
}

# Syncs stress gained from failing a non-criminal contract scheme.
scripted_effect loaa_laamp_base_contract_schemes_acknowledge_failure_criminal_stress_effect = {
	stress_impact = {
		base = minor_stress_impact_gain
		humble = minor_stress_impact_loss
		arrogant = minor_stress_impact_gain
		just = medium_stress_impact_gain
	}
}

# Syncs arbitrary duel difficulty + rewards to the tier of a contract, so that the same effect can dish out scaling rewards/have scaling odds if you're impressing a king rather than a baron.
scripted_effect loaa_laamp_base_contract_schemes_check_contract_difficulty_and_rewards_effect = {
	task_contract = {
		if = {
			limit = { task_contract_tier >= task_contract_t3_value }
			save_scope_value_as = {
				name = duel_diff
				value = @laamp_base_contract_schemes_on_going_duel_diff_t3_value
			}
			save_scope_value_as = {
				name = prestige_gain
				value = major_prestige_gain
			}
			save_scope_value_as = {
				name = piety_gain
				value = major_piety_gain
			}
			save_scope_value_as = {
				name = provisions_gain
				value = massive_provisions_gain
			}
		}
		else_if = {
			limit = { task_contract_tier >= task_contract_t2_value }
			save_scope_value_as = {
				name = duel_diff
				value = @laamp_base_contract_schemes_on_going_duel_diff_t2_value
			}
			save_scope_value_as = {
				name = prestige_gain
				value = medium_prestige_gain
			}
			save_scope_value_as = {
				name = piety_gain
				value = medium_piety_gain
			}
			save_scope_value_as = {
				name = provisions_gain
				value = major_provisions_gain
			}
		}
		else = {
			save_scope_value_as = {
				name = duel_diff
				value = @laamp_base_contract_schemes_on_going_duel_diff_t1_value
			}
			save_scope_value_as = {
				name = prestige_gain
				value = minor_prestige_gain
			}
			save_scope_value_as = {
				name = piety_gain
				value = minor_piety_gain
			}
			save_scope_value_as = {
				name = provisions_gain
				value = medium_provisions_gain
			}
		}
	}
}


##################################################
# Ambush travellers (setup)
# by Ewan Cowhig Croft
##################################################

scripted_effect loaa_laamp_base_contract_schemes_1044_organise_travel_effect = {
	start_travel_plan = {
		destination = scope:destination_1.title_province
		destination = scope:destination_2.title_province
		on_arrival_event = loaa_laamp_base_contract_schemes.1781
		travel_with_domicile = $DOMICILE$
		return_trip = $RETURN$
		on_travel_planner_cancel_event = laamp_base_contract_schemes.1045
		players_use_planner = no
		on_arrival_destinations = $EVENT_FIRE$
	}
}

#	Travel set-up event.
loaa_laamp_base_contract_schemes.1044 = {
	type = character_event
	title = laamp_base_contract_schemes.1044.t
	desc = laamp_base_contract_schemes.1044.desc
	theme = martial
	left_portrait = {
		character = root
		animation = marshal
	}
	right_portrait = {
		character = scope:employer
		animation = fear
	}
	override_background = { reference = bedchamber }

	immediate = {
		if = {
			limit = { exists = scope:employer.capital_county }
			scope:employer.capital_county = { save_scope_as = destination_1 }
		}
		else_if = {
			limit = { exists = scope:employer.location }
			scope:employer.location = { save_scope_as = destination_1 }
		}
		else = {
			location = { save_scope_as = destination_1 }
		}

		# Okay, find a suitable destination.
		scope:destination_1 = {
			# Counts travel a duchy or two over.
			if = {
				limit = { scope:employer.highest_held_title_tier = tier_county }
				duchy = {
					random_title_to_title_neighboring_duchy = {
						random_title_to_title_neighboring_duchy = {
							limit = {
								NOT = { this = scope:employer.capital_county.duchy }
							}
							title_capital_county = { save_scope_as = destination_2 }
						}
					}
				}
			}
			# Dukes travel a kingdom over.
			else_if = {
				limit = { scope:employer.highest_held_title_tier = tier_duchy }
				kingdom = {
					random_title_to_title_neighboring_kingdom = {
						title_capital_county = { save_scope_as = destination_2 }
					}
				}
			}
			# Kings and emperors travel an empire over.
			else = {
				empire = {
					random_title_to_title_neighboring_empire = {
						title_capital_county = { save_scope_as = destination_2 }
					}
				}
			}
		}
		# Work out how many encounters we'll have.
		scope:employer = {
			if = {
				limit = { highest_held_title_tier >= tier_empire }
				scope:task_contract = {
					increment_variable_effect = {
						VAR = encounters_max
						VAL = 6
					}
				}
			}
			else_if = {
				limit = { highest_held_title_tier >= tier_kingdom }
				scope:task_contract = {
					increment_variable_effect = {
						VAR = encounters_max
						VAL = 5
					}
				}
			}
			else_if = {
				limit = { highest_held_title_tier >= tier_duchy }
				scope:task_contract = {
					increment_variable_effect = {
						VAR = encounters_max
						VAL = 4
					}
				}
			}
			else_if = {
				limit = { highest_held_title_tier >= tier_county }
				scope:task_contract = {
					increment_variable_effect = {
						VAR = encounters_max
						VAL = 3
					}
				}
			}
		}
		# Right, grab the distance between us and the end zone.
		hidden_effect = {
			start_travel_plan = {
				destination = scope:destination_2.title_province
				travel_with_domicile = no
				return_trip = no
				players_use_planner = no
			}
			save_scope_value_as = {
				name = home_path_length
				value = {
					current_travel_plan = {
						every_future_path_location = { add = 1 }
					}
				}
			}
			current_travel_plan = { abort_travel_plan = yes }
		}
		custom_tooltip = laamp_base_contract_schemes.1044.tt.number_of_encounters
		custom_tooltip = laamp_base_contract_schemes.1044.tt.path_warning
	}

	# Travel without domicile.
	option = {
		name = laamp_base_contract_schemes.1044.a

		custom_tooltip = travel.stationary_domicile.tt
		custom_tooltip = laamp_base_contract_schemes.1044.tt.destination_list
		custom_tooltip = laamp_base_contract_schemes.1044.tt.explanation
		loaa_laamp_base_contract_schemes_1044_organise_travel_effect = {
			DOMICILE = no
			RETURN = yes
			EVENT_FIRE = all_but_last
		}

		# No stress here.
		# The AI should only choose to travel without their domicile.
		ai_chance = { base = 1000 }
	}

	# Travel with domicile.
	option = {
		name = laamp_base_contract_schemes.1044.b

		custom_tooltip = travel.mobile_domicile.tt
		custom_tooltip = laamp_base_contract_schemes.1044.tt.destination_list
		custom_tooltip = laamp_base_contract_schemes.1044.tt.explanation
		loaa_laamp_base_contract_schemes_1044_organise_travel_effect = {
			DOMICILE = yes
			RETURN = no
			EVENT_FIRE = all
		}

		# No stress here.
		# The AI should only choose to travel without their domicile.
		ai_chance = { base = 0 }
	}
}

##################################################
# Ambush travellers
# by Ewan Cowhig Croft
##################################################

#	Travel processing event.
loaa_laamp_base_contract_schemes.1781 = {
	hidden = yes

	immediate = {
		random_character_active_contract = {
			limit = {
				has_task_contract_type = loaa_laamp_base_1041
			}
			save_scope_as = task_contract
		}
		# If this is us reaching the start of our route, then flag that we want to start ambushing people.
		current_travel_plan = {
			if = {
				limit = {
					NOT = { has_variable = loaa_activate_laamp_base_1041_logic }
				}
				# Tell the on_action logic to activate.
				set_variable = loaa_activate_laamp_base_1041_logic
				root = {
					set_variable = {
						name = laamp_base_1041_travel_plan_contract_storage
						value = scope:task_contract
					}
				}
				# Calculate our path length.
				save_scope_value_as = {
					name = path_length_temp
					value = {
						every_future_path_location = { add = 1 }
						# Deduct the end locations.
						add = -1
						# And deduct our route on the way.
						subtract = scope:home_path_length
					}
				}
				# Aaand sort our provinces-per-event ratio.
				save_scope_value_as = {
					name = event_ratio_temp
					value = {
						value = scope:path_length_temp
						divide = scope:task_contract.var:encounters_max
						# Make it just a smidge faster, so that we're done by the time we get to our final destination.
						add = -1
						floor = yes
						min = 1
					}
				}
				scope:task_contract = {
					increment_variable_effect = {
						VAR = path_length
						VAL = scope:path_length_temp
					}
					increment_variable_effect = {
						VAR = event_ratio
						VAL = scope:event_ratio_temp
					}
					increment_variable_effect = {
						VAR = event_ratio_tracker
						VAL = scope:event_ratio_temp
					}
				}
			}
			else = {
				if = {
					limit = { scope:task_contract.var:haul_actual >= 1 }
					travel_plan_owner = { trigger_event = loaa_laamp_base_contract_schemes.1783 }
				}
				else = {
					travel_plan_owner = { trigger_event = loaa_laamp_base_contract_schemes.1784 }
				}
			}
		}
	}
}

scripted_trigger loaa_laamp_base_contract_schemes_1782_valid_target_char_trigger = {
	is_healthy = yes
	is_adult = yes
	is_ai = yes
	gold >= @laamp_base_contract_schemes_1782_min_gold_value
	NOR = {
		save_temporary_scope_as = char_temp
		scope:task_contract = {
			is_target_in_variable_list = {
				name = previous_victims_list
				target = scope:char_temp
			}
		}
		liege = root
	}
}

scripted_effect loaa_laamp_base_contract_schemes_1782_roll_duel_effect = {
	duel = {
		skill = $SKILL$
		value = $DIFF$
		# Victory!
		$WIN_CHANCE$ = {
			compare_modifier = {
				value = scope:duel_value
				multiplier = 3.5
				min = -49
			}
			min = 10
			desc = laamp_base_contract_schemes.1782.$OPTION$.tt.success
			send_interface_toast = {
				type = event_generic_good
				title = laamp_base_contract_schemes.1782.$OPTION$.tt.success
				left_icon = scope:victim
				scope:victim = {
					pay_short_term_gold = {
						target = root
						gold = $GOLD$
					}
					progress_towards_rival_effect = {
						REASON = rival_robbed_me
						CHARACTER = root
						OPINION = 0
					}
				}
			}
			reverse_add_opinion = {
				target = scope:victim
				modifier = gallowsbait_scum_opinion
				opinion = -50
			}
			laamp_rewards_apply_criminal_xp_effect = {
				TRACK = bandit
				XP_MAX = scope:gallowsbait_xp_win
				XP_MIN = scope:gallowsbait_xp_win
			}
			root.var:laamp_base_1041_travel_plan_contract_storage = {
				increment_variable_effect = {
					VAR = haul_actual
					VAL = $GOLD$
				}
			}
		}
		# Defeat.
		$LOSE_CHANCE$ = {
			compare_modifier = {
				value = scope:duel_value
				multiplier = -3.5
				min = -49
			}
			min = 10
			desc = laamp_base_contract_schemes.1782.$OPTION$.tt.failure
			send_interface_toast = {
				type = event_generic_bad
				title = laamp_base_contract_schemes.1782.$OPTION$.tt.failure
				left_icon = scope:victim
				custom_tooltip = laamp_base_contract_schemes.1782.tt.victim_escapes
				progress_towards_rival_effect = {
					REASON = rival_attempted_to_rob_me
					CHARACTER = root
					OPINION = 0
				}
			}
			reverse_add_opinion = {
				target = scope:victim
				modifier = gallowsbait_scum_opinion
				opinion = -25
			}
			laamp_rewards_apply_criminal_xp_effect = {
				TRACK = bandit
				XP_MAX = scope:gallowsbait_xp_lose
				XP_MIN = scope:gallowsbait_xp_lose
			}
		}
	}
}

#   You accost someone along the road.
loaa_laamp_base_contract_schemes.1782 = {
	type = character_event
	title = laamp_base_contract_schemes.1782.t
	desc = {
		random_valid = {
			desc = laamp_base_contract_schemes.1782.desc.intro.1
			desc = laamp_base_contract_schemes.1782.desc.intro.2
			desc = laamp_base_contract_schemes.1782.desc.intro.3
			desc = laamp_base_contract_schemes.1782.desc.intro.4
			desc = laamp_base_contract_schemes.1782.desc.intro.5
		}
		# Do we know the person?
		first_valid = {
			triggered_desc = {
				trigger = {
					has_any_moderate_good_relationship_with_character_trigger = { CHARACTER = scope:victim }
				}
				desc = laamp_base_contract_schemes.1782.desc.connection.negative
			}
			triggered_desc = {
				trigger = {
					has_any_moderate_bad_relationship_with_character_trigger = { CHARACTER = scope:victim }
				}
				desc = laamp_base_contract_schemes.1782.desc.connection.positive
			}
			triggered_desc = {
				trigger = { is_consort_of = scope:victim }
				desc = laamp_base_contract_schemes.1782.desc.connection.family_or_consort
			}
			desc = laamp_base_contract_schemes.1782.desc.connection.none
		}
		desc = boilerplate.paragraph
		# What type of person are they?
		first_valid = {
			triggered_desc = {
				trigger = { scope:victim_type = flag:pool }
				desc = laamp_base_contract_schemes.1782.desc.victim_type.pool
			}
			triggered_desc = {
				trigger = { scope:victim_type = flag:baron }
				desc = laamp_base_contract_schemes.1782.desc.victim_type.baron
			}
			triggered_desc = {
				trigger = { scope:victim_type = flag:travelling_ruler }
				desc = laamp_base_contract_schemes.1782.desc.victim_type.travelling_ruler
			}
			triggered_desc = {
				trigger = { scope:victim_type = flag:travelling_nobody }
				desc = laamp_base_contract_schemes.1782.desc.victim_type.travelling_nobody
			}
			triggered_desc = {
				trigger = { scope:victim_type = flag:laamp }
				desc = laamp_base_contract_schemes.1782.desc.victim_type.laamp
			}
			triggered_desc = {
				trigger = { scope:victim_type = flag:fallback }
				desc = laamp_base_contract_schemes.1782.desc.victim_type.fallback
			}
		}
		desc = boilerplate.paragraph
		desc = laamp_base_contract_schemes.1782.desc.outro
	}
	theme = martial
	left_portrait = {
		character = root
		animation = spymaster
	}
	right_portrait = {
		character = scope:victim
		animation = happiness
	}
	override_background = { reference = wilderness }

	immediate = {
		# Nab our contract.
		random_character_active_contract = {
			limit = { has_task_contract_type = loaa_laamp_base_1041 }
			save_scope_as = task_contract
		}
		scope:task_contract ?= {
			task_contract_employer = { save_scope_as = employer }
		}
		# Alright, gather our potential victims.
		## First we wipe anyone who might've been here to begin with.
		every_in_list = {
			list = potential_chars_list
			remove_from_list = potential_chars_list
		}
		## Pool chars.
		### Current location.
		every_pool_character = {
			province = root.location
			limit = { loaa_laamp_base_contract_schemes_1782_valid_target_char_trigger = yes }
			add_to_list = potential_chars_list
			add_to_list = is_pool_char_list
		}
		### Neighbouring locations.
		location.duchy = {
			every_title_to_title_neighboring_and_across_water_duchy = {
				title_capital_county.title_province = { save_scope_as = province_temp }
				every_pool_character = {
					province = scope:province_temp
					limit = { loaa_laamp_base_contract_schemes_1782_valid_target_char_trigger = yes }
					add_to_list = potential_chars_list
					add_to_list = is_pool_char_list
				}
			}
		}
		## Local barons & passers by.
		location.duchy = {
			every_dejure_vassal_title_holder = {
				limit = { highest_held_title_tier = tier_barony }
				# Grab suitable barons.
				if = {
					limit = {
						loaa_laamp_base_contract_schemes_1782_valid_target_char_trigger = yes
						is_available = yes
					}
					add_to_list = potential_chars_list
					add_to_list = is_baron_char_list
				}
				# And available travellers.
				primary_title.title_province = {
					every_character_in_location = {
						limit = {
							loaa_laamp_base_contract_schemes_1782_valid_target_char_trigger = yes
							is_travelling = yes
							is_landless_adventurer = no
						}
						save_scope_as = potential_chars_list
						add_to_list = is_travelling_char_list
					}
				}
			}
		}
		## Fellow laamps.
		### There can be quite a few of these, so we only check such for players and notable laamps.
		if = {
			limit = {
				OR = {
					is_ai = no
					prestige_level >= high_prestige_level
				}
			}
			every_in_global_list = {
				variable = laamps_tally
				limit = {
					domicile = {
						domicile_location.duchy = root.location.duchy
						# Laamps with defences can't be ambushed — partially for verisimilitude, partially just to keep loc variants down.
						NOT = { has_domicile_building_or_higher = camp_perimeter_01 }
					}
					loaa_laamp_base_contract_schemes_1782_valid_target_char_trigger = yes
					NOT = { this = root }
				}
				save_scope_as = potential_chars_list
				add_to_list = is_laamp_char_list
			}
		}
		# Aaaand process them to pick out the one we want.
		random_in_list = {
			list = potential_chars_list
			weight = {
				# Take our wealth as the standard measurement.
				modifier = {
					add = {
						value = gold
						subtract = @laamp_base_contract_schemes_1782_min_gold_value
					}
					always = yes
				}
				# Then we really want to get people travelling if we can.
				modifier = {
					add = 250
					is_travelling = yes
				}
				# And anyone who _isn't_ a baron is a great target.
				modifier = {
					add = {
						value = highest_held_title_tier
						multiply = 100
					}
					is_ruler = yes
				}
				# Finally, hyper-prio other laamps, as that helps the world feel alive.
				modifier = {
					add = 1000
					is_landless_adventurer = yes
				}
			}
			save_scope_as = victim
			# Log them as someone we shouldn't rob again this contract.
			scope:task_contract = {
				add_to_variable_list = {
					name = previous_victims_list
					target = scope:victim
				}
			}
		}
		## If we managed to _not_ grab anyone, then generate someone as a fallback.
		if = {
			limit = {
				NOT = { exists = scope:victim }
			}
			create_character = {
				template = merchant_template
				culture = location.culture
				faith = location.faith
				location = root.location
				save_scope_as = victim
			}
		}
		hidden_effect = {
			scope:victim = {
				if = {
					limit = {
						gold < 50
					}
					add_gold = {
						value = {
							integer_range = {
								min = 50
								max = 200
							}
						}
					}
				}
			}
		}
		# Cool, now that we've got a victim, let's set up some scopes derived from them.
		## See what list they came from for the desc.
		scope:victim = {
			switch = {
				trigger = is_in_list
				is_pool_char_list = {
					save_scope_value_as = {
						name = victim_type
						value = flag:pool
					}
				}
				is_baron_char_list = {
					save_scope_value_as = {
						name = victim_type
						value = flag:baron
					}
				}
				is_travelling_char_list = {
					if = {
						limit = { is_ruler = yes }
						save_scope_value_as = {
							name = victim_type
							value = flag:travelling_ruler
						}
					}
					else = {
						save_scope_value_as = {
							name = victim_type
							value = flag:travelling_nobody
						}
					}
				}
				is_laamp_char_list = {
					save_scope_value_as = {
						name = victim_type
						value = flag:laamp
					}
				}
				fallback = {
					save_scope_value_as = {
						name = victim_type
						value = flag:fallback
					}
				}
			}
		}
		## Plus set up how much gold we might be able to purloin from them.
		save_scope_value_as = {
			name = haul
			value = {
				value = scope:victim.gold
				multiply = 0.2
				min = 50
				max = {
					value = scope:victim.highest_held_title_tier
					multiply = 100
					min = 100
				}
			}
		}
		save_scope_value_as = {
			name = haul_half
			value = {
				value = scope:haul
				multiply = 0.5
				ceiling = yes
			}
		}
		## And what our gallowbait gain would be.
		save_scope_value_as = {
			name = gallowsbait_xp_win
			value = {
				add = scope:victim.highest_held_title_tier
				add = 1
			}
		}
		save_scope_value_as = {
			name = gallowsbait_xp_lose
			value = {
				add = scope:gallowsbait_xp_win
				multiply = 0.5
				floor = yes
				min = 1
			}
		}
		## Finally, check our skills for the duel diffs.
		save_scope_value_as = {
			name = prowess_diff
			value = {
				add = scope:victim.prowess
				add = highest_held_title_tier
				min = high_skill_rating
			}
		}
		save_scope_value_as = {
			name = martial_diff
			value = {
				add = scope:victim.martial
				add = highest_held_title_tier
				min = high_skill_rating
			}
		}
		save_scope_value_as = {
			name = intrigue_diff
			value = {
				add = scope:victim.intrigue
				add = highest_held_title_tier
				min = decent_skill_rating
			}
		}
	}

	# Prowess duel — default.
	option = {
		name = laamp_base_contract_schemes.1782.a
		skill = prowess

		loaa_laamp_base_contract_schemes_1782_roll_duel_effect = {
			SKILL = prowess
			DIFF = scope:prowess_diff
			WIN_CHANCE = 50
			LOSE_CHANCE = 50
			OPTION = a
			GOLD = scope:haul
		}

		stress_impact = {
			arbitrary = miniscule_stress_impact_loss
			just = minor_stress_impact_gain
		}
		ai_chance = {
			base = 1
			modifier = {
				add = {
					value = prowess
					subtract = scope:victim.prowess
					multiply = 5
				}
				always = yes
			}
		}
	}

	# Martial duel — default.
	option = {
		name = laamp_base_contract_schemes.1782.b
		skill = martial

		loaa_laamp_base_contract_schemes_1782_roll_duel_effect = {
			SKILL = martial
			DIFF = scope:martial_diff
			WIN_CHANCE = 50
			LOSE_CHANCE = 50
			OPTION = b
			GOLD = scope:haul
		}

		stress_impact = {
			arbitrary = miniscule_stress_impact_loss
			just = minor_stress_impact_gain
		}
		ai_chance = {
			base = 1
			modifier = {
				add = {
					value = martial
					subtract = scope:victim.martial
					multiply = 5
				}
				always = yes
			}
		}
	}

	# Intrigue duel — easier, but lower returns.
	option = {
		name = laamp_base_contract_schemes.1782.c
		skill = intrigue

		custom_tooltip = laamp_base_contract_schemes.1782.c.tt.easier_against_most_but_less_rewards
		loaa_laamp_base_contract_schemes_1782_roll_duel_effect = {
			SKILL = intrigue
			DIFF = scope:intrigue_diff
			WIN_CHANCE = 60
			LOSE_CHANCE = 40
			OPTION = c
			GOLD = scope:haul_half
		}

		stress_impact = {
			arbitrary = miniscule_stress_impact_loss
			just = minor_stress_impact_gain
		}
		ai_chance = {
			base = 1
			modifier = {
				add = {
					value = intrigue
					subtract = scope:victim.intrigue
					multiply = 5
				}
				always = yes
			}
			ai_value_modifier = { ai_greed = -0.2 }
		}
	}

	# Leave this one alone.
	option = {
		name = laamp_base_contract_schemes.1782.d

		custom_tooltip = laamp_base_contract_schemes.1782.d.tt
		reverse_add_opinion = {
			target = scope:victim
			modifier = friendly_face_on_the_road_opinion
			opinion = 10
		}

		stress_impact = {
			just = miniscule_stress_impact_loss
			arbitrary = minor_stress_impact_gain
		}
		ai_chance = {
			base = 1
			ai_value_modifier = { ai_honor = 1 }
		}
	}
}

#   You stole at least some money.
loaa_laamp_base_contract_schemes.1783 = {
	type = character_event
	window = scheme_successful_event
	title = laamp_base_contract_schemes.1783.t
	desc = laamp_base_contract_schemes.1783.desc
	theme = martial
	left_portrait = {
		character = root
		animation = steward
	}
	override_background = { reference = throne_room }

	immediate = {
		save_scope_value_as = {
			name = suppress_gold_warning
			value = yes
		}
		var:laamp_base_1041_travel_plan_contract_storage = { complete_task_contract = success_standard }
		current_travel_plan ?= { remove_variable = loaa_activate_laamp_base_1041_logic }
	}

	# Ayyy we're the best.
	option = {
		name = laamp_base_contract_schemes.1783.a

		custom_tooltip = laamp_base_contract_schemes.0000.f.contract_concluded

		# No stress, no AI.
	}
}

#   You managed to steal zero money.
loaa_laamp_base_contract_schemes.1784 = {
	type = character_event
	window = scheme_failed_event
	title = laamp_base_contract_schemes.1784.t
	desc = laamp_base_contract_schemes.1784.desc
	theme = martial
	left_portrait = {
		character = root
		animation = stress
	}
	override_background = { reference = throne_room }

	immediate = {
		save_scope_value_as = {
			name = suppress_gold_warning
			value = yes
		}
		var:laamp_base_1041_travel_plan_contract_storage = { complete_task_contract = failure_standard }
		current_travel_plan ?= { remove_variable = loaa_activate_laamp_base_1041_logic }
	}

	# Christ we suck.
	option = {
		name = laamp_base_contract_schemes.1784.a

		custom_tooltip = laamp_base_contract_schemes.0000.f.contract_concluded

		# No stress, no AI.
	}
}

##################################################
# Collect fake taxes (setup)
# by Ewan Cowhig Croft
##################################################

scripted_effect laamp_base_contract_schemes_2044_organise_travel_6_destinations_effect = {
	start_travel_plan = {
		destination = scope:destination_1.title_province
		destination = scope:destination_2.title_province
		destination = scope:destination_3.title_province
		destination = scope:destination_4.title_province
		destination = scope:destination_5.title_province
		destination = scope:destination_6.title_province
		on_arrival_event = loaa_laamp_base_contract_schemes.2781
		travel_with_domicile = $DOMICILE$
		return_trip = $RETURN$
		on_travel_planner_cancel_event = loaa_laamp_base_contract_schemes.2045
		players_use_planner = no
		on_arrival_destinations = $EVENT_FIRE$
	}
}

scripted_effect laamp_base_contract_schemes_2044_organise_travel_5_destinations_effect = {
	start_travel_plan = {
		destination = scope:destination_1.title_province
		destination = scope:destination_2.title_province
		destination = scope:destination_3.title_province
		destination = scope:destination_4.title_province
		destination = scope:destination_5.title_province
		on_arrival_event = loaa_laamp_base_contract_schemes.2781
		travel_with_domicile = $DOMICILE$
		return_trip = $RETURN$
		on_travel_planner_cancel_event = loaa_laamp_base_contract_schemes.2045
		players_use_planner = no
		on_arrival_destinations = $EVENT_FIRE$
	}
}

scripted_effect laamp_base_contract_schemes_2044_organise_travel_4_destinations_effect = {
	start_travel_plan = {
		destination = scope:destination_1.title_province
		destination = scope:destination_2.title_province
		destination = scope:destination_3.title_province
		destination = scope:destination_4.title_province
		on_arrival_event = loaa_laamp_base_contract_schemes.2781
		travel_with_domicile = $DOMICILE$
		return_trip = $RETURN$
		on_travel_planner_cancel_event = loaa_laamp_base_contract_schemes.2045
		players_use_planner = no
		on_arrival_destinations = $EVENT_FIRE$
	}
}

scripted_effect laamp_base_contract_schemes_2044_organise_travel_3_destinations_effect = {
	start_travel_plan = {
		destination = scope:destination_1.title_province
		destination = scope:destination_2.title_province
		destination = scope:destination_3.title_province
		on_arrival_event = loaa_laamp_base_contract_schemes.2781
		travel_with_domicile = $DOMICILE$
		return_trip = $RETURN$
		on_travel_planner_cancel_event = loaa_laamp_base_contract_schemes.2045
		players_use_planner = no
		on_arrival_destinations = $EVENT_FIRE$
	}
}

#	Travel set-up event.
loaa_laamp_base_contract_schemes.2044 = {
	type = character_event
	title = laamp_base_contract_schemes.2044.t
	desc = laamp_base_contract_schemes.2044.desc
	theme = stewardship
	left_portrait = {
		character = root
		animation = steward
	}
	right_portrait = {
		character = scope:employer
		animation = disbelief
	}
	override_background = { reference = wilderness }

	immediate = {
		scope:employer = {
			# First, sort out valid counties.
			ordered_sub_realm_county = {
				limit = {
					NOT = { this = scope:employer.capital_county }
				}
				order_by = development_level
				max = laamp_base_2041_num_counties_to_rob_sans_capital_value
				check_range_bounds = no
				add_to_list = preferable_counties_list
			}
			# Then, we organise them for the route.
			ordered_in_list = {
				list = preferable_counties_list
				order_by = {
					title_province = { value = "squared_distance(root.location)" }
					multiply = -1
				}
				max = "list_size(preferable_counties_list)"
				check_range_bounds = no
				if = {
					limit = {
						NOT = { exists = scope:destination_1 }
					}
					save_scope_as = destination_1
				}
				else_if = {
					limit = {
						NOT = {
							this = scope:destination_1
							exists = scope:destination_2
						}
					}
					save_scope_as = destination_2
				}
				else_if = {
					limit = {
						NOT = {
							this = scope:destination_1
							this = scope:destination_2
							exists = scope:destination_3
						}
					}
					save_scope_as = destination_3
				}
				else_if = {
					limit = {
						"list_size(preferable_counties_list)" >= 4
						NOT = {
							this = scope:destination_1
							this = scope:destination_2
							this = scope:destination_3
							exists = scope:destination_4
						}
					}
					save_scope_as = destination_4
				}
				else_if = {
					limit = {
						"list_size(preferable_counties_list)" >= 5
						NOT = {
							this = scope:destination_1
							this = scope:destination_2
							this = scope:destination_3
							this = scope:destination_4
							exists = scope:destination_5
						}
					}
					save_scope_as = destination_5
				}
				else_if = {
					limit = {
						"list_size(preferable_counties_list)" >= 6
						NOT = {
							this = scope:destination_1
							this = scope:destination_2
							this = scope:destination_3
							this = scope:destination_4
							this = scope:destination_5
							exists = scope:destination_6
						}
					}
					save_scope_as = destination_6
				}
			}
		}
	}

	# Travel without domicile.
	option = {
		name = laamp_base_contract_schemes.2044.a

		custom_tooltip = travel.stationary_domicile.tt
		switch = {
			trigger = exists
			scope:destination_6 = { custom_tooltip = laamp_base_contract_schemes.2044.tt.destination_list.6_destinations }
			scope:destination_5 = { custom_tooltip = laamp_base_contract_schemes.2044.tt.destination_list.5_destinations }
			scope:destination_4 = { custom_tooltip = laamp_base_contract_schemes.2044.tt.destination_list.4_destinations }
			fallback = { custom_tooltip = laamp_base_contract_schemes.2044.tt.destination_list.3_destinations }
		}
		custom_tooltip = laamp_base_contract_schemes.2044.tt.explanation
		switch = {
			trigger = exists
			scope:destination_6 = {
				laamp_base_contract_schemes_2044_organise_travel_6_destinations_effect = {
					DOMICILE = no
					RETURN = yes
					EVENT_FIRE = all_but_last
				}
			}
			scope:destination_5 = {
				laamp_base_contract_schemes_2044_organise_travel_5_destinations_effect = {
					DOMICILE = no
					RETURN = yes
					EVENT_FIRE = all_but_last
				}
			}
			scope:destination_4 = {
				laamp_base_contract_schemes_2044_organise_travel_4_destinations_effect = {
					DOMICILE = no
					RETURN = yes
					EVENT_FIRE = all_but_last
				}
			}
			fallback = {
				laamp_base_contract_schemes_2044_organise_travel_3_destinations_effect = {
					DOMICILE = no
					RETURN = yes
					EVENT_FIRE = all_but_last
				}
			}
		}

		# No stress here.
		# The AI should only choose to travel without their domicile.
		ai_chance = { base = 1000 }
	}

	# Travel with domicile.
	option = {
		name = laamp_base_contract_schemes.2044.b

		custom_tooltip = travel.mobile_domicile.tt
		switch = {
			trigger = exists
			scope:destination_6 = { custom_tooltip = laamp_base_contract_schemes.2044.tt.destination_list.6_destinations }
			scope:destination_5 = { custom_tooltip = laamp_base_contract_schemes.2044.tt.destination_list.5_destinations }
			scope:destination_4 = { custom_tooltip = laamp_base_contract_schemes.2044.tt.destination_list.4_destinations }
			fallback = { custom_tooltip = laamp_base_contract_schemes.2044.tt.destination_list.3_destinations }
		}
		custom_tooltip = laamp_base_contract_schemes.2044.tt.explanation
		switch = {
			trigger = exists
			scope:destination_6 = {
				laamp_base_contract_schemes_2044_organise_travel_6_destinations_effect = {
					DOMICILE = yes
					RETURN = no
					EVENT_FIRE = all
				}
			}
			scope:destination_5 = {
				laamp_base_contract_schemes_2044_organise_travel_5_destinations_effect = {
					DOMICILE = yes
					RETURN = no
					EVENT_FIRE = all
				}
			}
			scope:destination_4 = {
				laamp_base_contract_schemes_2044_organise_travel_4_destinations_effect = {
					DOMICILE = yes
					RETURN = no
					EVENT_FIRE = all
				}
			}
			fallback = {
				laamp_base_contract_schemes_2044_organise_travel_3_destinations_effect = {
					DOMICILE = yes
					RETURN = no
					EVENT_FIRE = all
				}
			}
		}

		# No stress here.
		# The AI should only choose to travel without their domicile.
		ai_chance = { base = 0 }
	}
}

#	Travel invalidation event.
loaa_laamp_base_contract_schemes.2045 = {
	hidden = yes

	trigger = { is_alive = yes }

	immediate = {
		random_character_active_contract = {
			limit = { has_task_contract_type = loaa_laamp_base_2041 }
			save_scope_as = task_contract
		}
		send_interface_message = {
			title = contract_invalidated_title
			type = stewardship_contract_scheme_invalidated_message
			right_icon = scope:task_contract.task_contract_employer
			scope:task_contract = { complete_task_contract = failure_standard }
		}
	}
}

##################################################
# Collect fake taxes
# by Ewan Cowhig Croft
##################################################

scripted_effect loaa_laamp_base_contract_schemes_2781_show_score_effect = {
	if = {
		limit = { scope:task_contract.var:wins_tally < scope:task_contract.var:win_t1_threshold }
		custom_tooltip = laamp_base_contract_schemes.2781.tt.current_total.sub_t1
	}
	else_if = {
		limit = { scope:task_contract.var:wins_tally < scope:task_contract.var:win_t2_threshold }
		custom_tooltip = laamp_base_contract_schemes.2781.tt.current_total.sub_t2
	}
	else_if = {
		limit = { scope:task_contract.var:wins_tally < scope:task_contract.var:win_t3_threshold }
		custom_tooltip = laamp_base_contract_schemes.2781.tt.current_total.sub_t3
	}
}

scripted_effect loaa_laamp_base_contract_schemes_2781_adjust_difficulty_effect = {
	custom_tooltip = laamp_base_contract_schemes.2781.tt.boost_difficulty.$DIFF_SPIKE$
	# Don't buff the difficulty for the AI, or they'll really have problems making solid judgements.
	if = {
		limit = { is_ai = no }
		scope:task_contract = {
			increment_variable_effect = {
				VAR = stewardship_diff
				VAL = $STEWARDSHIP$
			}
			increment_variable_effect = {
				VAR = intrigue_diff
				VAL = $INTRIGUE$
			}
			increment_variable_effect = {
				VAR = bard_diff
				VAL = $BARD$
			}
			increment_variable_effect = {
				VAR = stress_charge
				VAL = $STRESS$
			}
		}
	}
}

scripted_effect loaa_laamp_base_contract_schemes_2781_success_effect = {
	scope:task_contract = {
		increment_variable_effect = {
			VAR = wins_tally
			VAL = 1
		}
	}
	custom_tooltip = laamp_base_contract_schemes.2781.tt.progress_towards_success
	trigger_event = laamp_base_contract_schemes.2782
	# Plus, let's lower the control here to make it feel tangible.
	location.county = {
		if = {
			limit = {
				# But don't hit unsuspecting players who haven't been informed of this.
				holder = { is_ai = yes }
			}
			change_county_control = major_county_control_loss
		}
	}
}

scripted_effect loaa_laamp_base_contract_schemes_2781_failure_effect = {
	scope:task_contract = {
		increment_variable_effect = {
			VAR = losses_tally
			VAL = 1
		}
	}
	if = {
		limit = { scope:task_contract.var:losses_tally <= 1 }
		custom_tooltip = laamp_base_contract_schemes.2781.tt.progress_towards_failure
	}
	else = { custom_tooltip = laamp_base_contract_schemes.2781.tt.contract_failed }
	trigger_event = loaa_laamp_base_contract_schemes.2783
}

scripted_effect loaa_laamp_base_contract_schemes_2781_duel_generic_effect = {
	duel = {
		skill = $SKILL$
		value = $DIFF$
		# Victory!
		50 = {
			compare_modifier = {
				value = scope:duel_value
				multiplier = 3.5
				min = -49
			}
			min = 5
			desc = laamp_base_contract_schemes.2781.$SKILL$.tt.success
			loaa_laamp_base_contract_schemes_2781_success_effect = yes
		}
		# Defeat!
		50 = {
			compare_modifier = {
				value = scope:duel_value
				multiplier = -3.5
				min = -49
			}
			min = 5
			desc = laamp_base_contract_schemes.2781.$SKILL$.tt.failure
			loaa_laamp_base_contract_schemes_2781_failure_effect = yes
		}
	}
}


#	Arrival at one of your marked targets.
loaa_laamp_base_contract_schemes.2781 = {
	type = character_event
	title = laamp_base_contract_schemes.2781.t
	desc = {
		# Surroundings.
		first_valid = {
			triggered_desc = {
				trigger = { scope:background = flag:alley_day }
				desc = laamp_base_contract_schemes.2781.desc.surroundings.alley_day
			}
			triggered_desc = {
				trigger = { scope:background = flag:alley_night }
				desc = laamp_base_contract_schemes.2781.desc.surroundings.alley_night
			}
			triggered_desc = {
				trigger = { scope:background = flag:tavern }
				desc = laamp_base_contract_schemes.2781.desc.surroundings.tavern
			}
			triggered_desc = {
				trigger = { scope:background = flag:docks }
				desc = laamp_base_contract_schemes.2781.desc.surroundings.docks
			}
			triggered_desc = {
				trigger = { scope:background = flag:condemned_village }
				desc = laamp_base_contract_schemes.2781.desc.surroundings.condemned_village
			}
		}
		desc = boilerplate.paragraph
		# Local mood.
		first_valid = {
			triggered_desc = {
				trigger = { scope:local_mood = flag:disapproval }
				desc = laamp_base_contract_schemes.2781.desc.local_mood.disapproval
			}
			triggered_desc = {
				trigger = { scope:local_mood = flag:anger }
				desc = laamp_base_contract_schemes.2781.desc.local_mood.anger
			}
			triggered_desc = {
				trigger = { scope:local_mood = flag:admiration }
				desc = laamp_base_contract_schemes.2781.desc.local_mood.admiration
			}
			triggered_desc = {
				trigger = { scope:local_mood = flag:dismissal }
				desc = laamp_base_contract_schemes.2781.desc.local_mood.dismissal
			}
			triggered_desc = {
				trigger = { scope:local_mood = flag:thinking }
				desc = laamp_base_contract_schemes.2781.desc.local_mood.thinking
			}
		}
		desc = laamp_base_contract_schemes.2781.desc.outro
	}
	theme = stewardship
	left_portrait = {
		character = root
		animation = steward
	}
	right_portrait = {
		character = scope:local_char
		animation = disapproval
		triggered_animation = {
			trigger = { scope:local_mood = flag:disapproval }
			animation = disapproval
		}
		triggered_animation = {
			trigger = { scope:local_mood = flag:anger }
			animation = anger
		}
		triggered_animation = {
			trigger = { scope:local_mood = flag:admiration }
			animation = admiration
		}
		triggered_animation = {
			trigger = { scope:local_mood = flag:dismissal }
			animation = dismissal
		}
		triggered_animation = {
			trigger = { scope:local_mood = flag:thinking }
			animation = thinking
		}
		hide_info = yes
	}
	lower_left_portrait = scope:bard
	# Backgrounds indented +1 for easier folding.
		override_background = {
			trigger = { scope:background = flag:alley_day }
			reference = alley_day
		}
		override_background = {
			trigger = { scope:background = flag:alley_night }
			reference = alley_night
		}
		override_background = {
			trigger = { scope:background = flag:tavern }
			reference = tavern
		}
		override_background = {
			trigger = { scope:background = flag:docks }
			reference = docks
		}
		override_background = {
			trigger = { scope:background = flag:condemned_village }
			reference = ce1_condemned_village
		}

	immediate = {
		# Roll our background tombola.
		random_list = {
			100 = {
				save_scope_value_as = {
					name = background
					value = flag:alley_day
				}
			}
			100 = {
				save_scope_value_as = {
					name = background
					value = flag:alley_night
				}
			}
			100 = {
				save_scope_value_as = {
					name = background
					value = flag:tavern
				}
			}
			100 = {
				trigger = {
					location = { is_coastal = yes }
				}
				save_scope_value_as = {
					name = background
					value = flag:docks
				}
			}
			100 = {
				trigger = {
					location = {
						any_province_epidemic = { count >= 1 }
					}
				}
				save_scope_value_as = {
					name = background
					value = flag:condemned_village
				}
			}
		}
		# And our local mood tombola.
		random_list = {
			100 = {
				save_scope_value_as = {
					name = local_mood
					value = flag:disapproval
				}
			}
			100 = {
				save_scope_value_as = {
					name = local_mood
					value = flag:anger
				}
			}
			100 = {
				save_scope_value_as = {
					name = local_mood
					value = flag:admiration
				}
			}
			100 = {
				save_scope_value_as = {
					name = local_mood
					value = flag:dismissal
				}
			}
			100 = {
				save_scope_value_as = {
					name = local_mood
					value = flag:thinking
				}
			}
		}
		# If we have a suitable bard, grab them.
		court_position:master_bard_camp_officer ?= {
			if = {
				limit = {
					is_available_allow_travelling = yes
					location = root.location
				}
				save_scope_as = bard
			}
		}
		# Generate a local to use.
		create_character = {
			template = merchant_template
			location = root.location
			culture = root.location.culture
			faith = root.location.faith
			save_scope_as = local_char
		}
		# Plus, stop us whilst we're here.
		hidden_effect = {
			current_travel_plan = { pause_travel_plan = yes }
		}
		# Finally, tell us where our total is at.
		loaa_laamp_base_contract_schemes_2781_show_score_effect = yes
	}

	# Stewardship.
	option = {
		name = laamp_base_contract_schemes.2781.a
		skill = stewardship

		loaa_laamp_base_contract_schemes_2781_duel_generic_effect = {
			SKILL = stewardship
			DIFF = scope:task_contract.var:stewardship_diff
		}

		loaa_laamp_base_contract_schemes_2781_adjust_difficulty_effect = {
			DIFF_SPIKE = stewardship
			STEWARDSHIP = 3
			INTRIGUE = 2
			BARD = 5
			STRESS = 5
		}

		# No stress here.
		ai_chance = {
			base = 1
			modifier = {
				add = stewardship
				always = yes
			}
		}
	}

	# Intrigue.
	option = {
		name = laamp_base_contract_schemes.2781.b
		skill = intrigue

		loaa_laamp_base_contract_schemes_2781_duel_generic_effect = {
			SKILL = intrigue
			DIFF = scope:task_contract.var:intrigue_diff
		}

		loaa_laamp_base_contract_schemes_2781_adjust_difficulty_effect = {
			DIFF_SPIKE = intrigue
			STEWARDSHIP = 2
			INTRIGUE = 3
			BARD = 5
			STRESS = 5
		}

		# No stress here.
		ai_chance = {
			base = 1
			modifier = {
				add = intrigue
				always = yes
			}
		}
	}

	# Bard.
	option = {
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = { exists = scope:bard }
						desc = laamp_base_contract_schemes.2781.c.bard_exists
					}
					desc = laamp_base_contract_schemes.2781.c.bard_dnae_exist
				}
			}
		}
		trigger = { employs_court_position = master_bard_camp_officer }
		show_as_unavailable = { always = yes }
		reason = have_master_bard

		custom_tooltip = option_boilerplate.tt.officer_aptitude
		# Extra exists check because otherwise show_as_unavailable'll cause errors.
		if = {
			limit = { exists = scope:bard }
			random_list = {
				0 = {
					desc = option_boilerplate.tt.officer_aptitude.success
					send_interface_toast = {
						type = event_generic_good
						title = option_boilerplate.tt.officer_aptitude.success
						left_icon = scope:bard
						loaa_laamp_base_contract_schemes_2781_success_effect = yes
					}
					# Raw aptitude.
					modifier = {
						add = {
							scope:bard ?= { add = "aptitude(master_bard_camp_officer)" }
							multiply = 20
							min = 5
							max = 95
						}
						always = yes
					}
					# Adjusted for difficulty.
					modifier = {
						add = {
							value = scope:task_contract.var:bard_diff
							multiply = -1
						}
						always = yes
					}
				}
				0 = {
					desc = option_boilerplate.tt.officer_aptitude.failure
					send_interface_toast = {
						type = event_generic_bad
						title = option_boilerplate.tt.officer_aptitude.failure
						left_icon = scope:bard
						loaa_laamp_base_contract_schemes_2781_failure_effect = yes
					}
					# Raw aptitude.
					modifier = {
						add = {
							scope:bard ?= { add = "aptitude(master_bard_camp_officer)" }
							multiply = -20
							min = 5
							max = 95
						}
						always = yes
					}
					# Adjusted for difficulty.
					modifier = {
						add = scope:task_contract.var:bard_diff
						always = yes
					}
				}
			}
		}

		loaa_laamp_base_contract_schemes_2781_adjust_difficulty_effect = {
			DIFF_SPIKE = bard
			STEWARDSHIP = 2
			INTRIGUE = 2
			BARD = 15
			STRESS = 5
		}

		# No stress here.
		ai_chance = {
			base = 1
			modifier = {
				add = {
					scope:bard = { add = "aptitude(master_bard_camp_officer)" }
					multiply = 3
				}
				exists = scope:bard
			}
		}
	}

	# Stress.
	option = {
		name = laamp_base_contract_schemes.2781.d

		add_stress = scope:task_contract.var:stress_charge
		loaa_laamp_base_contract_schemes_2781_success_effect = yes

		loaa_laamp_base_contract_schemes_2781_adjust_difficulty_effect = {
			DIFF_SPIKE = stress
			STEWARDSHIP = 2
			INTRIGUE = 2
			BARD = 5
			STRESS = 15
		}

		# The AI always plays it risky.
		ai_chance = { base = 0 }
	}
}

scripted_trigger loaa_laamp_base_contract_schemes_2782_middle_options_trigger = {
	scope:task_contract.var:wins_tally < scope:task_contract.var:win_t3_threshold
	trigger_if = {
		limit = { scope:task_contract.var:wins_tally >= scope:task_contract.var:win_t1_threshold }
		scope:task_contract.var:losses_tally = 0
	}
}

#	We bow out with what we currently have
scripted_effect loaa_laamp_base_contract_schemes_2782_bug_out_effect = {
	scope:task_contract = {
		# What should our result be?
		## Back out failure.
		if = {
			limit = { var:wins_tally < var:win_t1_threshold }
			scope:task_contract = { complete_task_contract = failure_qualified }
		}
		## Partial success.
		else_if = {
			limit = { var:wins_tally < var:win_t2_threshold }
			scope:task_contract = { complete_task_contract = success_qualified }
		}
		## Success.
		else = {
			scope:task_contract = { complete_task_contract = success_standard }
		}
	}
	# Remove our travel plan.
	hidden_effect = {
		return_home = yes
	}
}

#	Successful duel at a marked target.
loaa_laamp_base_contract_schemes.2782 = {
	type = character_event
	title = laamp_base_contract_schemes.2782.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:task_contract.var:wins_tally >= scope:task_contract.var:win_t3_threshold }
				desc = laamp_base_contract_schemes.2782.desc.success_critical
			}
			triggered_desc = {
				trigger = { scope:task_contract.var:wins_tally >= scope:task_contract.var:win_t2_threshold }
				desc = laamp_base_contract_schemes.2782.desc.success_standard
			}
			triggered_desc = {
				trigger = { scope:task_contract.var:wins_tally >= scope:task_contract.var:win_t1_threshold }
				desc = laamp_base_contract_schemes.2782.desc.success_qualified
			}
			desc = laamp_base_contract_schemes.2782.desc.nothing_yet
		}
	}
	theme = stewardship
	left_portrait = {
		character = root
		animation = personality_bold
	}
	override_background = { reference = wilderness }

	immediate = {
		# Show our current score.
		loaa_laamp_base_contract_schemes_2781_show_score_effect = yes
	}

	# Full success!
	option = {
		name = laamp_base_contract_schemes.2782.a
		trigger = { scope:task_contract.var:wins_tally >= scope:task_contract.var:win_t3_threshold }

		scope:task_contract = { complete_task_contract = success_critical }
		# Remove our travel plan.
		hidden_effect = {
			return_home = yes
		}

		# No stress here.
		# Only option, so no AI chance either.
	}

	# Keep going.
	option = {
		name = laamp_base_contract_schemes.2782.b
		trigger = { loaa_laamp_base_contract_schemes_2782_middle_options_trigger = yes }

		custom_tooltip = laamp_base_contract_schemes.2782.b.tt.travel_onwards
		current_travel_plan = { resume_travel_plan = yes }

		# No stress here.
		ai_chance = {
			# The AI keeps going till it wins or it loses a toss.
			base = 1000
		}
	}

	# Bug out with whatever you've got.
	option = {
		name = laamp_base_contract_schemes.2782.c
		trigger = { loaa_laamp_base_contract_schemes_2782_middle_options_trigger = yes }

		loaa_laamp_base_contract_schemes_2782_bug_out_effect = yes

		# No stress here.
		# No AI chance either — the AI won't bug out whilst it's on a hot streak.
	}

	# Can't achieve exceptional success any more, but we're above t2, so restrict to that.
	option = {
		name = laamp_base_contract_schemes.2782.d
		trigger = {
			scope:task_contract.var:wins_tally < scope:task_contract.var:win_t3_threshold
			scope:task_contract.var:wins_tally >= scope:task_contract.var:win_t2_threshold
			scope:task_contract.var:losses_tally = 1
		}

		custom_tooltip = laamp_base_contract_schemes.2782.d.tt
		loaa_laamp_base_contract_schemes_2782_bug_out_effect = yes

		# No stress here.
		# Only option given, so no AI chance.
	}

	after = {
		# Clean up our local.
		hidden_effect = {
			scope:local_char = { silent_disappearance_effect = yes }
		}
	}
}

#	Failed duel at a marked target.
loaa_laamp_base_contract_schemes.2783 = {
	type = character_event
	title = laamp_base_contract_schemes.2783.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:task_contract.var:losses_tally = 2 }
				desc = laamp_base_contract_schemes.2783.desc.lost
			}
			desc = laamp_base_contract_schemes.2783.desc.losing
		}
	}
	theme = stewardship
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = { scope:task_contract.var:losses_tally = 1 }
			animation = stress
		}
		triggered_animation = {
			trigger = { scope:task_contract.var:losses_tally = 2 }
			animation = shock
		}
	}
	override_background = { reference = wilderness }

	immediate = {
		# Show our current score — _if_ we could still cut and run.
		if = {
			limit = { scope:task_contract.var:losses_tally = 1 }
			loaa_laamp_base_contract_schemes_2781_show_score_effect = yes
		}
	}

	# You have lost.
	option = {
		name = laamp_base_contract_schemes.2783.a
		trigger = { scope:task_contract.var:losses_tally = 2 }

		scope:scheme.task_contract = { complete_task_contract = failure_standard }

		# No stress here.
		# Only option, so no AI chance either.
	}

	# Well, only one loss so far.
	option = {
		name = laamp_base_contract_schemes.2783.b
		trigger = {
			scope:task_contract.var:losses_tally = 1
			scope:task_contract.var:wins_tally < scope:task_contract.var:win_t2_threshold
		}

		custom_tooltip = laamp_base_contract_schemes.2783.b.tt.travel_onwards
		current_travel_plan = { resume_travel_plan = yes }

		# No stress here.
		# AI-chance not needed, if the AI goofs, it should early out.
	}

	# Bug out with whatever you've got.
	option = {
		name = laamp_base_contract_schemes.2783.c
		trigger = {
			scope:task_contract.var:losses_tally = 1
			scope:task_contract.var:wins_tally < scope:task_contract.var:win_t2_threshold
		}

		loaa_laamp_base_contract_schemes_2782_bug_out_effect = yes

		# No stress here.
		ai_chance = {
			# If the AI has the chance, then they should bug out.
			base = 1000
		}
	}

	# Forced bug out.
	option = {
		name = laamp_base_contract_schemes.2783.d
		trigger = {
			scope:task_contract.var:losses_tally = 1
			scope:task_contract.var:wins_tally >= scope:task_contract.var:win_t2_threshold
		}

		custom_tooltip = laamp_base_contract_schemes.2783.d.tt
		loaa_laamp_base_contract_schemes_2782_bug_out_effect = yes

		# No stress here.
		ai_chance = {
			# If the AI has the chance, then they should bug out.
			base = 1000
		}
	}

	after = {
		# Clean up our local.
		hidden_effect = {
			scope:local_char = { silent_disappearance_effect = yes }
		}
	}
}

##################################################
# Heist from a ruler's treasury (setup)
# by Ewan Cowhig Croft
##################################################

#	Intro event.
loaa_laamp_base_contract_schemes.3041 = {
	type = character_event
	title = laamp_base_contract_schemes.3041.t
	desc = laamp_base_contract_schemes.3041.desc
	theme = intrigue
	left_portrait = {
		character = root
		animation = spymaster
	}
	right_portrait = {
		character = scope:employer
		animation = steward
	}
	override_background = { reference = alley_night }
	widget = {
		gui = "event_window_widget_scheme"
		container = "custom_widgets_container"
	}

	immediate = {
		scope:task_contract.task_contract_employer = {
			save_scope_as = employer
			save_scope_as = bg_override_char
		}
	}

	# Go for a balanced agent mix.
	option = {
		name = laamp_base_contract_schemes.3041.d
		reason = give_me_balanced_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_BALANCED

		scope:scheme = {
			# Success.
			add_agent_slot = agent_thief
			add_agent_slot = agent_thief
			add_agent_slot = agent_scout
			# Speed.
			add_agent_slot = agent_infiltrator
			add_agent_slot = agent_footpad
		}

		# No stress, we're just selecting our starter batch.
		# AI always selects balanced agents.
		ai_chance = { base = 1000 }
	}

	# Focus on success chance agents.
	option = {
		name = laamp_base_contract_schemes.3041.a
		reason = give_me_success_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_SUCCESS

		scope:scheme = {
			# Success.
			add_agent_slot = agent_thief
			add_agent_slot = agent_thief
			add_agent_slot = agent_thug
			add_agent_slot = agent_scout
			# Speed.
			add_agent_slot = agent_infiltrator
		}

		# No stress, we're just selecting our starter batch.
		# AI always picks the balanced config.
	}

	# Focus on speedy agents.
	option = {
		name = laamp_base_contract_schemes.3041.b
		reason = give_me_speed_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_SPEED

		scope:scheme = {
			# Success.
			add_agent_slot = agent_thief
			# Speed.
			add_agent_slot = agent_infiltrator
			add_agent_slot = agent_infiltrator
			add_agent_slot = agent_footpad
			add_agent_slot = agent_footpad
		}

		# No stress, we're just selecting our starter batch.
		# AI always picks the balanced config.
	}

	# Focus on secrecy agents.
	#option = {
		#name = laamp_base_contract_schemes.3021.c
		#reason = give_me_secrecy_agents
		#flavor = EVENT_WINDOW_OPTION_AGENTS_SECRECY

		#scope:scheme = {
			# Secrecy.
			#add_agent_slot = agent_lookout
			#add_agent_slot = agent_lookout
			#add_agent_slot = agent_decoy
			# Success.
			#add_agent_slot = agent_thief
			# Speed.
			#add_agent_slot = agent_infiltrator
		#}

		# No stress, we're just selecting our starter batch.
		# AI always picks the balanced config.
	#}

	# Now show us the panel.
	after = {
		open_view = {
			view = intrigue_window
			player = root
		}
	}
}

#	Success event.
loaa_laamp_base_contract_schemes.3042 = {
	type = character_event
	window = scheme_successful_event
	title = laamp_base_contract_schemes.3042.t
	desc = laamp_base_contract_schemes.3042.desc
	theme = intrigue
	center_portrait = {
		character = root
		animation = random_weapon_coup_degrace
	}
	right_portrait = {
		character = scope:employer
		animation = fear
	}
	override_background = { reference = alley_night }

	immediate = {
		laamp_base_contract_schemes_set_up_outcome_immediate_effect = yes
		scope:employer = { save_scope_as = bg_override_char }
		# Compile all of our agents for the follow-up event, if we choose to go for it.
		scope:scheme = {
			every_scheme_agent_character = { add_to_list = former_agents_list }
		}
		# Aaaand check what our hauls would be.
		## First we remember root as a scope so that the tooltips won't have a little freak out at trying to do ROOT.Char.Var.
		save_scope_as = varcheck
		## Then sort our main variable.
		### First, our constituent values — we want to register these now as we're gonna use them in the success event chain.
		scope:employer = {
			save_scope_value_as = {
				name = contribution_gold
				value = {
					value = gold
					multiply = 0.5
					min = 0
				}
			}
			save_scope_value_as = {
				name = contribution_prestige
				value = {
					value = prestige
					multiply = 0.25
					min = 0
				}
			}
			save_scope_value_as = {
				name = contribution_piety
				value = {
					value = piety
					multiply = 0.25
					min = 0
				}
			}
		}
		### Now the variable itself.
		set_variable = {
			name = haul_possible
			value = {
				add = scope:contribution_gold
				add = scope:contribution_prestige
				add = scope:contribution_piety
				min = {
					value = 50
					add = {
						value = scope:employer.highest_held_title_tier
						# Adjust back down for barons.
						add = -1
						# Now boost it a bit per tier.
						multiply = 25
					}
				}
				floor = yes
			}
		}
		## Plus our increments.
		if = {
			limit = { var:haul_possible >= 750 }
			set_variable = {
				name = haul_increment
				value = 100
			}
		}
		else_if = {
			limit = { var:haul_possible >= 500 }
			set_variable = {
				name = haul_increment
				value = 75
			}
		}
		else = {
			set_variable = {
				name = haul_increment
				value = 50
			}
		}
		scope:scheme.task_contract = {
			complete_task_contract = success_standard
		}
		save_scope_as = adventurer
		# Employer outcome.
		scope:employer = {
			add_character_modifier = {
				modifier = laamp_base_3041_success_employer_modifier
				years = 10
			}
		}
		# And wrap things up.
		scope:scheme ?= { end_scheme = yes }
	}

	# Acknowledge.
	option = {
		name = laamp_base_contract_schemes.3042.a
		flavor = laamp_base_contract_schemes.0000.f.contract_concluded
		scope:employer = { trigger_event = loaa_contract_event.3041 }
		loaa_laamp_base_contract_schemes_acknowledge_success_criminal_stress_effect = yes
		# If we're not using them, lose the variables.
		remove_variable = haul_possible
		remove_variable = haul_increment

		ai_chance = {
			ai_value_modifier = {
				ai_boldness = -2
				ai_greed = -2
			}
		}
	}

	# What if... we went back for more...
	option = {
		name = laamp_base_contract_schemes.3042.b
		skill = intrigue

		custom_tooltip = laamp_base_contract_schemes.3042.b.tt.possible_haul
		custom_tooltip = laamp_base_contract_schemes.3042.b.tt.explanation
		custom_tooltip = laamp_base_contract_schemes.3042.b.tt.current_earnings
		custom_tooltip = laamp_base_contract_schemes.3042.b.tt.you_go_back_for_more

		loaa_laamp_base_contract_schemes_acknowledge_success_criminal_stress_effect = yes

		# Our tracking variables.
		## The actual variables.
		set_variable = {
			name = haul_actual
			value = 0
		}
		set_variable = {
			name = loaa_heist_failures
			value = 0
		}
		# And finally, launch into the bonus heist.
		trigger_event = loaa_laamp_base_contract_schemes.3781

		ai_chance = {
			ai_value_modifier = {
				ai_boldness = 2
				ai_greed = 2
			}
		}
	}
}

#	Failure event.
loaa_laamp_base_contract_schemes.3043 = {
	type = character_event
	window = scheme_failed_event
	title = laamp_base_contract_schemes.3043.t
	desc = laamp_base_contract_schemes.3043.desc
	theme = intrigue
	center_portrait = {
		character = root
		animation = fear
	}
	right_portrait = {
		character = scope:employer
		animation = rage
	}
	override_background = { reference = alley_night }

	immediate = {
		laamp_base_contract_schemes_set_up_outcome_immediate_effect = yes
		scope:scheme.task_contract = { complete_task_contract = failure_standard }
		# Employer outcome.
		scope:employer = {
			add_character_modifier = {
				modifier = laamp_base_3041_failure_employer_modifier
				years = 10
			}
		}
		# And wrap things up.
		scope:scheme ?= { end_scheme = yes }
	}

	# Acknowledge.
	option = {
		name = laamp_base_contract_schemes.3043.a
		flavor = laamp_base_contract_schemes.0000.f.contract_concluded

		loaa_laamp_base_contract_schemes_acknowledge_failure_criminal_stress_effect = yes
	}
}

##################################################
# Heist from a ruler's treasury
# by Ewan Cowhig Croft
##################################################

scripted_effect loaa_laamp_base_contract_schemes_3781_note_old_rollee_duel_effect = {
	if = {
		limit = { scope:secondary_roll = flag:agent_prowess }
		save_scope_value_as = {
			name = old_secondary_roll
			value = flag:agent_prowess
		}
	}
	else_if = {
		limit = { scope:secondary_roll = flag:agent_intrigue }
		save_scope_value_as = {
			name = old_secondary_roll
			value = flag:agent_intrigue
		}
	}
}

scripted_effect loaa_laamp_base_contract_schemes_3781_roll_duel_effect = {
	duel = {
		skill = $SKILL$
		target = scope:employer
		# Victory!
		50 = {
			compare_modifier = {
				value = scope:duel_value
				multiplier = 3.5
				min = -49
			}
			min = 5
			desc = laamp_base_contract_schemes.3781.tt.duel_success.$TYPE$
			root = {
				loaa_laamp_base_contract_schemes_3781_duel_success_effect = yes
				trigger_event = loaa_laamp_base_contract_schemes.3781
			}
		}
		# Defeat.
		50 = {
			compare_modifier = {
				value = scope:duel_value
				multiplier = -3.5
				min = -49
			}
			# Cap out our max a bit earlier than we usually would so that there's still some risk for the hyper-skilled.
			min = 10
			desc = laamp_base_contract_schemes.3781.tt.duel_failure.$TYPE$
			root = {
				loaa_laamp_base_contract_schemes_3781_duel_failure_effect = yes
				trigger_event = loaa_laamp_base_contract_schemes.3781
			}
		}
	}
}

scripted_effect loaa_laamp_base_contract_schemes_3781_roll_camp_officer_effect = {
	scope:rollee = {
		stress_impact = {
			base = medium_stress_gain
			diligent = minor_stress_impact_loss
			lazy = medium_stress_impact_gain
		}
	}
	custom_tooltip = option_boilerplate.tt.officer_aptitude
	random_list = {
		0 = {
			desc = option_boilerplate.tt.officer_aptitude.success
			loaa_laamp_base_contract_schemes_3781_duel_success_effect = yes
			trigger_event = laamp_base_contract_schemes.3781
			# Raw aptitude.
			modifier = {
				add = {
					scope:rollee ?= { add = add_camp_officer_aptitude_value }
					multiply = 20
					min = 5
					max = 95
				}
				always = yes
			}
		}
		0 = {
			desc = option_boilerplate.tt.officer_aptitude.failure
			loaa_laamp_base_contract_schemes_3781_duel_failure_effect = yes
			trigger_event = laamp_base_contract_schemes.3781
			# Raw aptitude.
			modifier = {
				add = {
					scope:rollee ?= { add = add_camp_officer_aptitude_value }
					multiply = -20
					min = 5
					max = 95
				}
				always = yes
			}
		}
	}
}

scripted_effect loaa_laamp_base_contract_schemes_3781_duel_success_effect = {
	# How much wealth have we purloined?
	## Boost our haul.
	increment_variable_effect = {
		VAR = haul_actual
		VAL = var:haul_increment
	}
	## Make sure we cap out out.
	if = {
		limit = { var:haul_actual > var:haul_possible }
		set_variable = {
			name = haul_actual
			value = var:haul_possible
		}
	}
	## Flag all of this to the player.
	custom_tooltip = laamp_base_contract_schemes.3781.tt.increment_haul
	save_scope_value_as = {
		name = result
		value = flag:success
	}
}

scripted_effect loaa_laamp_base_contract_schemes_3781_duel_failure_effect = {
	if = {
		limit = { var:loaa_heist_failures = 0 }
		custom_tooltip = laamp_base_contract_schemes.3781.tt.foul_warning.increment
	}
	else = {
		show_as_tooltip = {
			rightfully_imprison_character_less_verbose_effect = {
				TARGET = root
				IMPRISONER = scope:employer
			}
		}
		custom_tooltip = laamp_base_contract_schemes.3781.tt.foul_warning.pot_lost
	}
	increment_variable_effect = {
		VAR = loaa_heist_failures
		VAL = 1
	}
	save_scope_value_as = {
		name = result
		value = flag:failure
	}
}

#	Looping heist event.
loaa_laamp_base_contract_schemes.3781 = {
	type = character_event
	title = laamp_base_contract_schemes.3781.t
	window = visit_settlement_window
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { var:haul_actual >= var:haul_possible }
				desc = laamp_base_contract_schemes.3781.desc.ending
			}
			desc = {
				first_valid = {
					triggered_desc = {
						trigger = { scope:play_intro = flag:roll_clip }
						desc = laamp_base_contract_schemes.3781.desc.intro.yes
					}
				}
				triggered_desc = {
					trigger = { scope:result = flag:success }
					desc = {
						first_valid = {
							triggered_desc = {
								trigger = { scope:method = flag:intrigue }
								desc = laamp_base_contract_schemes.3781.desc.success.method.intrigue
							}
							triggered_desc = {
								trigger = { scope:method = flag:prowess }
								desc = laamp_base_contract_schemes.3781.desc.success.method.prowess
							}
							triggered_desc = {
								trigger = { scope:method = flag:martial }
								desc = laamp_base_contract_schemes.3781.desc.success.method.martial
							}
							triggered_desc = {
								trigger = { scope:method = flag:stewardship }
								desc = laamp_base_contract_schemes.3781.desc.success.method.stewardship
							}
							triggered_desc = {
								trigger = { scope:method = flag:agent_intrigue }
								desc = laamp_base_contract_schemes.3781.desc.success.method.agent_intrigue
							}
							triggered_desc = {
								trigger = { scope:method = flag:agent_prowess }
								desc = laamp_base_contract_schemes.3781.desc.success.method.agent_prowess
							}
							triggered_desc = {
								trigger = { scope:method = flag:master_thief }
								desc = laamp_base_contract_schemes.3781.desc.success.method.master_thief
							}
							triggered_desc = {
								trigger = { scope:method = flag:mos }
								desc = laamp_base_contract_schemes.3781.desc.success.method.mos
							}
							triggered_desc = {
								trigger = { scope:method = flag:stress }
								desc = laamp_base_contract_schemes.3781.desc.success.method.stress
							}
						}
						desc = laamp_base_contract_schemes.3781.desc.cta
					}
				}
				triggered_desc = {
					trigger = { scope:result = flag:failure }
					desc = {
						first_valid = {
							triggered_desc = {
								trigger = { scope:method = flag:intrigue }
								desc = laamp_base_contract_schemes.3781.desc.failure.method.intrigue
							}
							triggered_desc = {
								trigger = { scope:method = flag:prowess }
								desc = laamp_base_contract_schemes.3781.desc.failure.method.prowess
							}
							triggered_desc = {
								trigger = { scope:method = flag:martial }
								desc = laamp_base_contract_schemes.3781.desc.failure.method.martial
							}
							triggered_desc = {
								trigger = { scope:method = flag:stewardship }
								desc = laamp_base_contract_schemes.3781.desc.failure.method.stewardship
							}
							triggered_desc = {
								trigger = { scope:method = flag:agent_intrigue }
								desc = laamp_base_contract_schemes.3781.desc.failure.method.agent_intrigue
							}
							triggered_desc = {
								trigger = { scope:method = flag:agent_prowess }
								desc = laamp_base_contract_schemes.3781.desc.failure.method.agent_prowess
							}
							triggered_desc = {
								trigger = { scope:method = flag:master_thief }
								desc = laamp_base_contract_schemes.3781.desc.failure.method.master_thief
							}
							triggered_desc = {
								trigger = { scope:method = flag:mos }
								desc = laamp_base_contract_schemes.3781.desc.failure.method.mos
							}
							# No stress desc, as that can't fail.
						}
						desc = laamp_base_contract_schemes.3781.desc.cta
					}
				}
			}
		}
	}
	theme = intrigue
	center_portrait = {
		character = root
		triggered_animation = {
			trigger = { scope:result = flag:failure }
			animation = stress
		}
		animation = schadenfreude
	}
	right_portrait = {
		character = scope:employer
		triggered_animation = {
			trigger = { scope:result = flag:failure }
			animation = rage
		}
		animation = shock
	}
	#TODO_CD_EP3; refactor this so that the old rollee + their scope:secondary_roll flag is shown here, so that the portrait matches up with the loc, and we only show the next rollee as a small portrait instead.
	left_portrait = {
		character = scope:old_rollee
		triggered_animation = {
			trigger = { scope:old_secondary_roll = flag:agent_prowess }
			animation = marshal
		}
		animation = spymaster
	}
	lower_left_portrait = scope:rollee
	override_background = { reference = corridor_night }

	trigger = {
		var:loaa_heist_failures < 2
		has_variable = haul_actual
	}

	on_trigger_fail = { trigger_event = loaa_laamp_base_contract_schemes.3783 }

	immediate = {
		debug_log = "Triggered 3781"
		# Check whether this is our first go-round on the event.
		if = {
			limit = {
				NOT = { exists = scope:play_intro }
			}
			save_scope_value_as = {
				name = play_intro
				value = flag:roll_clip
			}
			# Plus register our tally.
			save_scope_value_as = {
				name = haul_actual
				value = 0
			}
		}
		else = {
			save_scope_value_as = {
				name = play_intro
				value = flag:clip_rolled
			}
			# Error suppress.
			if = {
				limit = { scope:play_intro = flag:clip_rolled }
				# Do nuthin'.
			}
		}
		# Roll our secondary skill.
		## Remove scope:rollee, so that they're not hanging around inappropriately.
		### Which means first flagging them for loc.
		scope:rollee ?= { save_scope_as = old_rollee }
		### Then voiding them to remove their portrait.
		clear_saved_scope = rollee
		## Now roll.
		random_list = {
			# Prowess.
			100 = {
				save_scope_value_as = {
					name = secondary_roll
					value = flag:prowess
				}
				modifier = {
					add = {
						value = prowess
						multiply = 10
					}
					always = yes
				}
				modifier = {
					factor = 0.01
					exists = scope:secondary_roll
					scope:secondary_roll = flag:prowess
				}
			}
			# Martial.
			100 = {
				save_scope_value_as = {
					name = secondary_roll
					value = flag:martial
				}
				modifier = {
					add = {
						value = martial
						multiply = 10
					}
					always = yes
				}
				modifier = {
					factor = 0.01
					exists = scope:secondary_roll
					scope:secondary_roll = flag:martial
				}
			}
			# Stewardship.
			100 = {
				save_scope_value_as = {
					name = secondary_roll
					value = flag:stewardship
				}
				modifier = {
					add = {
						value = stewardship
						multiply = 10
					}
					always = yes
				}
				modifier = {
					factor = 0.01
					exists = scope:secondary_roll
					scope:secondary_roll = flag:stewardship
				}
			}
			# Agent intrigue.
			100 = {
				trigger = { "list_size(former_agents_list)" >= 1 }
				loaa_laamp_base_contract_schemes_3781_note_old_rollee_duel_effect = yes
				save_scope_value_as = {
					name = secondary_roll
					value = flag:agent_intrigue
				}
				ordered_in_list = {
					list = former_agents_list
					order_by = {
						value = intrigue
						multiply = 100
						# Weight down anyone we've just rolled.
						if = {
							limit = { scope:old_rollee ?= this }
							multiply = 0.01
						}
					}
					save_scope_as = rollee
				}
				modifier = {
					add = {
						every_in_list = {
							list = former_agents_list
							add = intrigue
						}
						multiply = 2.5
					}
					always = yes
				}
				modifier = {
					factor = 0.01
					exists = scope:secondary_roll
					scope:secondary_roll = flag:agent_intrigue
				}
			}
			# Agent prowess.
			100 = {
				trigger = { "list_size(former_agents_list)" >= 1 }
				loaa_laamp_base_contract_schemes_3781_note_old_rollee_duel_effect = yes
				save_scope_value_as = {
					name = secondary_roll
					value = flag:agent_prowess
				}
				ordered_in_list = {
					list = former_agents_list
					order_by = {
						value = prowess
						multiply = 100
						# Weight down anyone we've just rolled.
						if = {
							limit = { scope:old_rollee ?= this }
							multiply = 0.01
						}
					}
					save_scope_as = rollee
				}
				modifier = {
					add = {
						every_in_list = {
							list = former_agents_list
							add = prowess
						}
						multiply = 2.5
					}
					always = yes
				}
				modifier = {
					factor = 0.01
					exists = scope:secondary_roll
					scope:secondary_roll = flag:agent_prowess
				}
			}
			# Master Thief.
			100 = {
				trigger = {
					court_position:master_thief_camp_officer ?= {
						location = root.location
						is_available_allow_travelling = yes
					}
				}
				save_scope_value_as = {
					name = secondary_roll
					value = flag:master_thief
				}
				court_position:master_thief_camp_officer ?= { save_scope_as = rollee }
				modifier = {
					add = {
						court_position:master_thief_camp_officer ?= { add = "aptitude(master_thief_camp_officer)" }
						multiply = 20
						min = 5
						max = 95
					}
					always = yes
				}
				modifier = {
					factor = 0.01
					exists = scope:secondary_roll
					scope:secondary_roll = flag:master_thief
				}
			}
			# Master of Spoils.
			100 = {
				trigger = {
					court_position:master_of_spoils_camp_officer ?= {
						location = root.location
						is_available_allow_travelling = yes
					}
				}
				save_scope_value_as = {
					name = secondary_roll
					value = flag:master_of_spoils
				}
				court_position:master_of_spoils_camp_officer ?= { save_scope_as = rollee }
				modifier = {
					add = {
						court_position:master_of_spoils_camp_officer ?= { add = "aptitude(master_of_spoils_camp_officer)" }
						multiply = 20
						min = 5
						max = 95
					}
					always = yes
				}
				modifier = {
					factor = 0.01
					exists = scope:secondary_roll
					scope:secondary_roll = flag:master_of_spoils
				}
			}
		}
		# Status report tooltips.
		custom_tooltip = laamp_base_contract_schemes.3781.tt.haul_details
		custom_tooltip = laamp_base_contract_schemes.3781.tt.fouls_remaining
	}

	# Intrigue duel.
	option = {
		name = laamp_base_contract_schemes.3781.a
		trigger = { var:haul_actual < var:haul_possible }
		skill = intrigue

		save_scope_value_as = {
			name = method
			value = flag:intrigue
		}
		loaa_laamp_base_contract_schemes_3781_roll_duel_effect = {
			SKILL = intrigue
			TYPE = skill
		}

		# No stress here.
		ai_chance = {
			base = 0
			modifier = {
				add = intrigue
				always = yes
			}
		}
	}

	# Prowess duel
	option = {
		name = laamp_base_contract_schemes.3781.b
		trigger = {
			var:haul_actual < var:haul_possible
			scope:secondary_roll = flag:prowess
		}
		skill = prowess

		save_scope_value_as = {
			name = method
			value = flag:prowess
		}
		loaa_laamp_base_contract_schemes_3781_roll_duel_effect = {
			SKILL = prowess
			TYPE = skill
		}

		# No stress here.
		ai_chance = {
			base = 0
			modifier = {
				add = prowess
				always = yes
			}
		}
	}

	# Martial duel.
	option = {
		name = laamp_base_contract_schemes.3781.c
		trigger = {
			var:haul_actual < var:haul_possible
			scope:secondary_roll = flag:martial
		}
		skill = martial

		save_scope_value_as = {
			name = method
			value = flag:martial
		}
		loaa_laamp_base_contract_schemes_3781_roll_duel_effect = {
			SKILL = martial
			TYPE = skill
		}

		# No stress here.
		ai_chance = {
			base = 0
			modifier = {
				add = martial
				always = yes
			}
		}
	}

	# Stewardship duel.
	option = {
		name = laamp_base_contract_schemes.3781.d
		trigger = {
			var:haul_actual < var:haul_possible
			scope:secondary_roll = flag:stewardship
		}
		skill = stewardship

		save_scope_value_as = {
			name = method
			value = flag:stewardship
		}
		loaa_laamp_base_contract_schemes_3781_roll_duel_effect = {
			SKILL = stewardship
			TYPE = skill
		}

		# No stress here.
		ai_chance = {
			base = 0
			modifier = {
				add = stewardship
				always = yes
			}
		}
	}

	# Agent intrigue duel.
	option = {
		name = laamp_base_contract_schemes.3781.e
		trigger = {
			var:haul_actual < var:haul_possible
			scope:secondary_roll = flag:agent_intrigue
		}
		skill = intrigue

		save_scope_value_as = {
			name = method
			value = flag:agent_intrigue
		}
		scope:rollee = {
			stress_impact = {
				base = medium_stress_gain
				diligent = minor_stress_impact_loss
				lazy = medium_stress_impact_gain
			}
			loaa_laamp_base_contract_schemes_3781_roll_duel_effect = {
				SKILL = intrigue
				TYPE = agent
			}
		}

		# No stress here.
		ai_chance = {
			base = 0
			modifier = {
				add = scope:rollee.intrigue
				always = yes
			}
		}
	}

	# Agent prowess duel.
	option = {
		name = laamp_base_contract_schemes.3781.f
		trigger = {
			var:haul_actual < var:haul_possible
			scope:secondary_roll = flag:agent_prowess
		}
		skill = prowess

		save_scope_value_as = {
			name = method
			value = flag:agent_prowess
		}
		scope:rollee = {
			stress_impact = {
				base = medium_stress_gain
				diligent = minor_stress_impact_loss
				lazy = medium_stress_impact_gain
			}
			loaa_laamp_base_contract_schemes_3781_roll_duel_effect = {
				SKILL = prowess
				TYPE = agent
			}
		}

		# No stress here.
		ai_chance = {
			base = 0
			modifier = {
				add = scope:rollee.prowess
				always = yes
			}
		}
	}

	# Master Thief aptitude.
	option = {
		name = laamp_base_contract_schemes.3781.g
		trigger = {
			var:haul_actual < var:haul_possible
			scope:secondary_roll = flag:master_thief
		}
		reason = have_master_thief

		save_scope_value_as = {
			name = method
			value = flag:master_thief
		}
		loaa_laamp_base_contract_schemes_3781_roll_camp_officer_effect = yes

		# No stress here.
		ai_chance = {
			base = 0
			modifier = {
				add = {
					value = "aptitude(master_thief_camp_officer)"
					multiply = 4
				}
				always = yes
			}
		}
	}

	# Master of Spoils aptitude.
	option = {
		name = laamp_base_contract_schemes.3781.h
		trigger = {
			var:haul_actual < var:haul_possible
			scope:secondary_roll = flag:master_of_spoils
		}
		reason = have_master_of_spoils

		save_scope_value_as = {
			name = method
			value = flag:mos
		}
		loaa_laamp_base_contract_schemes_3781_roll_camp_officer_effect = yes

		# No stress here.
		ai_chance = {
			base = 0
			modifier = {
				add = {
					value = "aptitude(master_of_spoils_camp_officer)"
					multiply = 4
				}
				always = yes
			}
		}
	}

	# Stress auto-success.
	option = {
		name = laamp_base_contract_schemes.3781.i
		trigger = { var:haul_actual < var:haul_possible }

		save_scope_value_as = {
			name = method
			value = flag:stress
		}
		loaa_laamp_base_contract_schemes_3781_duel_success_effect = yes
		trigger_event = loaa_laamp_base_contract_schemes.3782

		stress_impact = {
			base = major_stress_gain
			diligent = minor_stress_impact_loss
			lazy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 0
			# Low value mods to sync with the low AI weights from other values given above.
			ai_value_modifier = { ai_energy = 0.2 }
		}
	}

	# Tap out.
	option = {
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = { var:haul_actual >= var:haul_possible }
						desc = laamp_base_contract_schemes.3781.j.stole_everything
					}
					desc = laamp_base_contract_schemes.3781.j
				}
			}
		}

		custom_tooltip = laamp_base_contract_schemes.3781.j.tt.flee_with_earnings
		trigger_event = loaa_laamp_base_contract_schemes.3782

		# Only apply stress if we've not got our money's worth by this point.
		if = {
			limit = {
				var:haul_actual <= {
					value = var:haul_possible
					multiply = 0.75
				}
			}
			stress_impact = {
				craven = minor_stress_impact_loss
				brave = medium_stress_impact_gain
			}
		}
		ai_chance = {
			base = 0
			# Low value mods to sync with the low AI weights from other values given above.
			ai_value_modifier = { ai_energy = -0.2 }
			# If you haven't got anything, then you should keep trying.
			modifier = {
				add = -1000
				var:haul_actual <= 0
			}
		}
	}
}

scripted_effect loaa_laamp_base_contract_schemes_3782_clean_variables_effect = {
	remove_variable = haul_possible
	remove_variable = haul_increment
	remove_variable = haul_actual
	remove_variable = loaa_heist_failures
}

#	You've tapped out with your extra gains.
loaa_laamp_base_contract_schemes.3782 = {
	type = character_event
	title = laamp_base_contract_schemes.3782.t
	desc = {
		desc = laamp_base_contract_schemes.3782.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = { scope:haul_percentage <= -1 }
				desc = laamp_base_contract_schemes.3782.desc.haul_amount.grabbed_everything
			}
			triggered_desc = {
				trigger = { scope:haul_percentage <= -0.6 }
				desc = laamp_base_contract_schemes.3782.desc.haul_amount.grabbed_most
			}
			triggered_desc = {
				trigger = { scope:haul_percentage <= -0.3 }
				desc = laamp_base_contract_schemes.3782.desc.haul_amount.grabbed_lots
			}
			triggered_desc = {
				trigger = { scope:haul_actual = 0 }
				desc = laamp_base_contract_schemes.3782.desc.haul_amount.grabbed_nothing
			}
			desc = laamp_base_contract_schemes.3782.desc.haul_amount.grabbed_some
		}
		triggered_desc = {
			trigger = { scope:haul_actual != 0 }
			desc = laamp_base_contract_schemes.3782.desc.outro
		}
	}
	theme = intrigue
	left_portrait = {
		character = root
		animation = steward
	}
	right_portrait = {
		character = scope:employer
		animation = rage
	}
	override_background = { reference = corridor_night }

	immediate = {
		# Pay out our winnings.
		if = {
			limit = { var:haul_actual > 0 }
			scope:employer = {
				# First root's gold.
				pay_short_term_gold = {
					target = root
					gold = root.var:haul_actual
				}
				## Whilst reimbursing it, as we'll take a portion of it in a sec.
				hidden_effect = { add_gold = root.var:haul_actual }
				# Now, we do our damage to scope:employer.
				## Ok, how much of our total did we actually nab?
				save_scope_value_as = {
					name = haul_percentage
					value = {
						value = root.var:haul_actual
						divide = root.var:haul_possible
						multiply = -1
					}
				}
				## Deduct our earnings.
				if = {
					limit = { scope:contribution_gold != 0 }
					hidden_effect = {
						remove_short_term_gold = {
							value = scope:contribution_gold
							multiply = scope:haul_percentage
						}
					}
				}
				# Saving actual gold to show to employer - #LOAA
				save_scope_value_as = {
					name = actual_stolen_gold
					value = {
						value = root.var:haul_actual
						add = {
							value = {
								value = scope:contribution_gold
								multiply = scope:haul_percentage
								multiply = -1
							}
						}
					}
				}

				if = {
					limit = { scope:contribution_prestige != 0 }
					add_prestige = {
						value = scope:contribution_prestige
						multiply = scope:haul_percentage
						# Slightly devalued vs. actual gold, so we up this a bit.
						multiply = 2
					}
				}
				if = {
					limit = { scope:contribution_piety != 0 }
					add_piety = {
						value = scope:contribution_piety
						multiply = scope:haul_percentage
						# Slightly devalued vs. actual gold, so we up this a bit.
						multiply = 2
					}
				}
			}
		}
		# Serve up your gallowsbait.
		save_scope_value_as = {
			name = gallowsbait_xp
			value = {
				value = var:haul_actual
				divide = 25
				ceiling = yes
			}
		}
		laamp_rewards_apply_criminal_xp_effect = {
			TRACK = thief
			XP_MAX = scope:gallowsbait_xp
			XP_MIN = scope:gallowsbait_xp
		}
	}

	# Heh, now let's sell this loot...
	option = {
		name = laamp_base_contract_schemes.3782.a
		scope:employer = { trigger_event = loaa_contract_event.3041 }
		custom_tooltip = laamp_base_contract_schemes.0000.f.contract_concluded

		# No stress, no AI.
	}

	# Clean up our variables.
	after = {
		save_scope_as = adventurer
		loaa_laamp_base_contract_schemes_3782_clean_variables_effect = yes
	}
}

#	You are caught, and your gains are lost.
loaa_laamp_base_contract_schemes.3783 = {
	type = character_event
	title = laamp_base_contract_schemes.3783.t
	desc = {
		desc = laamp_base_contract_schemes.3783.desc.intro
		first_valid = {
			triggered_desc = {
				# We're a little looser with this trigger than in the success event since, if you have literally everything, you cannot then fail the rest of the chain.
				trigger = { scope:haul_percentage <= -0.95 }
				desc = laamp_base_contract_schemes.3783.desc.haul_amount.grabbed_everything
			}
			triggered_desc = {
				trigger = { scope:haul_percentage <= -0.6 }
				desc = laamp_base_contract_schemes.3783.desc.haul_amount.grabbed_most
			}
			triggered_desc = {
				trigger = { scope:haul_percentage <= -0.3 }
				desc = laamp_base_contract_schemes.3783.desc.haul_amount.grabbed_lots
			}
			triggered_desc = {
				trigger = { scope:haul_actual = 0 }
				desc = laamp_base_contract_schemes.3783.desc.haul_amount.grabbed_nothing
			}
			desc = laamp_base_contract_schemes.3783.desc.haul_amount.grabbed_some
		}
		desc = laamp_base_contract_schemes.3783.desc.outro
	}
	theme = intrigue
	left_portrait = {
		character = root
		animation = prisondungeon
	}
	right_portrait = {
		character = scope:employer
		animation = spymaster
	}
	override_background = { reference = corridor_night }

	immediate = {
		debug_log = "Triggered 3783"
		rightfully_imprison_character_less_verbose_effect = {
			TARGET = root
			IMPRISONER = scope:employer
		}
		if = {
			limit = { scope:haul_actual != 0 }
			custom_tooltip = laamp_base_contract_schemes.3783.tt.haul_lost
		}
		laamp_rewards_apply_criminal_xp_effect = {
			TRACK = thief
			XP_MAX = gallowsbait_xp_medium_gain
			XP_MIN = gallowsbait_xp_medium_gain
		}
		# Also, so is everyone who was helping you.
		every_in_list = {
			list = former_agents_list
			save_scope_as = char_temp
			rightfully_imprison_character_less_verbose_effect = {
				TARGET = scope:char_temp
				IMPRISONER = scope:employer
			}
			hidden_effect = {
				reverse_add_opinion = {
					target = scope:employer
					modifier = gallowsbait_scum_opinion
					opinion = -50
				}
			}
		}
		scope:employer = {
			trigger_event = loaa_contract_event.3042
		}
	}

	# Damn and blast these infernal walls!
	option = {
		name = laamp_base_contract_schemes.3783.a
		custom_tooltip = laamp_base_contract_schemes.3783.a.tt.a_cold_cell_awaits
		save_scope_as = adventurer
		stress_impact = { base = medium_stress_gain }
		# No AI here.
	}

	# Clean up our variables.
	after = {
		loaa_laamp_base_contract_schemes_3782_clean_variables_effect = yes
	}
}

##################################################
# Go rustling (setup)
# by Ewan Cowhig Croft
##################################################

scripted_effect loaa_laamp_base_contract_schemes_5034_organise_travel_destinations_2_effect = {
	start_travel_plan = {
		destination = scope:destination_1.title_province
		destination = scope:destination_2.title_province
		on_arrival_event = laamp_base_contract_schemes.5661
		travel_with_domicile = $DOMICILE$
		return_trip = $RETURN$
		on_travel_planner_cancel_event = laamp_base_contract_schemes.5035
		players_use_planner = no
		on_arrival_destinations = $EVENT_FIRE$
	}
}

scripted_effect loaa_laamp_base_contract_schemes_5034_organise_travel_destinations_3_effect = {
	start_travel_plan = {
		destination = scope:destination_1.title_province
		destination = scope:destination_2.title_province
		destination = scope:destination_3.title_province
		on_arrival_event = laamp_base_contract_schemes.5661
		travel_with_domicile = $DOMICILE$
		return_trip = $RETURN$
		on_travel_planner_cancel_event = laamp_base_contract_schemes.5035
		players_use_planner = no
		on_arrival_destinations = $EVENT_FIRE$
	}
}

scripted_effect loaa_laamp_base_contract_schemes_5034_organise_travel_destinations_4_effect = {
	start_travel_plan = {
		destination = scope:destination_1.title_province
		destination = scope:destination_2.title_province
		destination = scope:destination_3.title_province
		destination = scope:destination_4.title_province
		on_arrival_event = laamp_base_contract_schemes.5661
		travel_with_domicile = $DOMICILE$
		return_trip = $RETURN$
		on_travel_planner_cancel_event = laamp_base_contract_schemes.5035
		players_use_planner = no
		on_arrival_destinations = $EVENT_FIRE$
	}
}

scripted_effect loaa_laamp_base_contract_schemes_5034_organise_travel_destinations_5_effect = {
	start_travel_plan = {
		destination = scope:destination_1.title_province
		destination = scope:destination_2.title_province
		destination = scope:destination_3.title_province
		destination = scope:destination_4.title_province
		destination = scope:destination_5.title_province
		on_arrival_event = laamp_base_contract_schemes.5661
		travel_with_domicile = $DOMICILE$
		return_trip = $RETURN$
		on_travel_planner_cancel_event = laamp_base_contract_schemes.5035
		players_use_planner = no
		on_arrival_destinations = $EVENT_FIRE$
	}
}

scripted_effect loaa_laamp_base_contract_schemes_5034_append_fresh_destination_effect = {
	ordered_sub_realm_county = {
		order_by = development_level
		limit = {
			trigger_if = {
				# The AI can go w/e, but make sure we get a rational distance for the player.
				limit = {
					root = { is_ai = no }
				}
				NOT = { is_in_list = destinations_list }
				save_temporary_scope_as = destination_temp
				any_in_list = {
					list = destinations_list
					title_province = { "squared_distance(scope:destination_temp.title_province)" <= squared_distance_medium }
				}
			}
			trigger_else = {
				NOT = { is_in_list = destinations_list }
			}
		}
		alternative_limit = {
			NOT = { is_in_list = destinations_list }
		}
		add_to_list = destinations_list
	}
}

#	Travel set-up event.
loaa_laamp_base_contract_schemes.5034 = {
	type = character_event
	title = laamp_base_contract_schemes.5034.t
	desc = laamp_base_contract_schemes.5034.desc
	theme = martial
	left_portrait = {
		character = root
		animation = personality_bold
	}
	right_portrait = {
		character = scope:employer
		animation = shock
	}
	override_background = { reference = bedchamber }

	immediate = {
		# Pick our destinations.
		## First just assemble a bunch of 'em.
		scope:employer = {
			ordered_sub_realm_county = {
				order_by = development_level
				limit = { holder = scope:employer }
				add_to_list = destinations_list
				save_scope_as = destination_1
			}
			scope:task_contract ?= {
				set_variable = {
					name = crime_location
					value = scope:destination_1
				}
			}
			# Counts get +1.
			if = {
				limit = { highest_held_title_tier >= tier_county }
				loaa_laamp_base_contract_schemes_5034_append_fresh_destination_effect = yes
			}
			# Dukes get +2.
			if = {
				limit = {
					highest_held_title_tier >= tier_duchy
					sub_realm_size >= 3
				}
				loaa_laamp_base_contract_schemes_5034_append_fresh_destination_effect = yes
			}
			# Kings get +3.
			if = {
				limit = {
					highest_held_title_tier >= tier_kingdom
					sub_realm_size >= 4
				}
				loaa_laamp_base_contract_schemes_5034_append_fresh_destination_effect = yes
			}
			# Emperors get +4.
			if = {
				limit = {
					highest_held_title_tier >= tier_empire
					sub_realm_size >= 5
				}
				loaa_laamp_base_contract_schemes_5034_append_fresh_destination_effect = yes
			}
		}
		## Then assemble them as actual destinations.
		ordered_in_list = {
			list = destinations_list
			order_by = {
				title_province = { value = "squared_distance(root.location)" }
				multiply = -1
			}
			max = "list_size(destinations_list)"
			check_range_bounds = no
			if = {
				limit = {
					NOT = { exists = scope:destination_1 }
				}
				save_scope_as = destination_1
				scope:task_contract = {
					increment_variable_effect = {
						VAR = encounter_max
						VAL = 1
					}
				}
			}
			else_if = {
				limit = {
					NOT = {
						this = scope:destination_1
						exists = scope:destination_2
					}
				}
				save_scope_as = destination_2
				scope:task_contract = {
					increment_variable_effect = {
						VAR = encounter_max
						VAL = 1
					}
				}
			}
			else_if = {
				limit = {
					"list_size(preferable_counties_list)" >= 3
					NOT = {
						this = scope:destination_1
						this = scope:destination_2
						exists = scope:destination_3
					}
				}
				save_scope_as = destination_3
				scope:task_contract = {
					increment_variable_effect = {
						VAR = encounter_max
						VAL = 1
					}
				}
			}
			else_if = {
				limit = {
					"list_size(preferable_counties_list)" >= 4
					NOT = {
						this = scope:destination_1
						this = scope:destination_2
						this = scope:destination_3
						exists = scope:destination_4
					}
				}
				save_scope_as = destination_4
				scope:task_contract = {
					increment_variable_effect = {
						VAR = encounter_max
						VAL = 1
					}
				}
			}
			else_if = {
				limit = {
					"list_size(preferable_counties_list)" >= 5
					NOT = {
						this = scope:destination_1
						this = scope:destination_2
						this = scope:destination_3
						this = scope:destination_4
						exists = scope:destination_5
					}
				}
				save_scope_as = destination_5
				scope:task_contract = {
					increment_variable_effect = {
						VAR = encounter_max
						VAL = 1
					}
				}
			}
		}
	}

	# Travel without domicile.
	option = {
		name = laamp_base_contract_schemes.5034.a

		custom_tooltip = travel.stationary_domicile.tt
		switch = {
			trigger = exists
			scope:destination_5 = {
				custom_tooltip = laamp_base_contract_schemes.5034.tt.destination_list.5
				loaa_laamp_base_contract_schemes_5034_organise_travel_destinations_5_effect = {
					DOMICILE = no
					RETURN = yes
					EVENT_FIRE = all_but_last
				}
			}
			scope:destination_4 = {
				custom_tooltip = laamp_base_contract_schemes.5034.tt.destination_list.4
				loaa_laamp_base_contract_schemes_5034_organise_travel_destinations_4_effect = {
					DOMICILE = no
					RETURN = yes
					EVENT_FIRE = all_but_last
				}
			}
			scope:destination_3 = {
				custom_tooltip = laamp_base_contract_schemes.5034.tt.destination_list.3
				loaa_laamp_base_contract_schemes_5034_organise_travel_destinations_3_effect = {
					DOMICILE = no
					RETURN = yes
					EVENT_FIRE = all_but_last
				}
			}
			scope:destination_2 = {
				custom_tooltip = laamp_base_contract_schemes.5034.tt.destination_list.2
				loaa_laamp_base_contract_schemes_5034_organise_travel_destinations_2_effect = {
					DOMICILE = no
					RETURN = yes
					EVENT_FIRE = all_but_last
				}
			}
		}
		custom_tooltip = laamp_base_contract_schemes.5034.tt.explanation

		# No stress here.
		# The AI should only choose to travel without their domicile.
		ai_chance = { base = 1000 }
	}

	# Travel with domicile.
	option = {
		name = laamp_base_contract_schemes.5034.b

		custom_tooltip = travel.mobile_domicile.tt
		custom_tooltip = laamp_base_contract_schemes.5034.tt.explanation
		switch = {
			trigger = exists
			scope:destination_5 = {
				custom_tooltip = laamp_base_contract_schemes.5034.tt.destination_list.5
				loaa_laamp_base_contract_schemes_5034_organise_travel_destinations_5_effect = {
					DOMICILE = yes
					RETURN = no
					EVENT_FIRE = all
				}
			}
			scope:destination_4 = {
				custom_tooltip = laamp_base_contract_schemes.5034.tt.destination_list.4
				loaa_laamp_base_contract_schemes_5034_organise_travel_destinations_4_effect = {
					DOMICILE = yes
					RETURN = no
					EVENT_FIRE = all
				}
			}
			scope:destination_3 = {
				custom_tooltip = laamp_base_contract_schemes.5034.tt.destination_list.3
				loaa_laamp_base_contract_schemes_5034_organise_travel_destinations_3_effect = {
					DOMICILE = yes
					RETURN = no
					EVENT_FIRE = all
				}
			}
			scope:destination_2 = {
				custom_tooltip = laamp_base_contract_schemes.5034.tt.destination_list.2
				loaa_laamp_base_contract_schemes_5034_organise_travel_destinations_2_effect = {
					DOMICILE = yes
					RETURN = no
					EVENT_FIRE = all
				}
			}
		}

		# No stress here.
		# The AI should only choose to travel without their domicile.
		ai_chance = { base = 0 }
	}
}

#	Travel invalidation event.
loaa_laamp_base_contract_schemes.5035 = {
	hidden = yes

	trigger = { is_alive = yes }

	immediate = {
		random_character_active_contract = {
			limit = { has_task_contract_type = laamp_base_2001 }
			save_scope_as = task_contract
		}
		send_interface_message = {
			title = contract_invalidated_title
			type = stewardship_contract_scheme_invalidated_message
			right_icon = scope:task_contract.task_contract_employer
			scope:task_contract = { complete_task_contract = failure_standard }
		}
	}
}

##################################################
# EXTRA — PROWESS

##################################################
# Go rustling
# by Ewan Cowhig Croft
##################################################

scripted_effect loaa_laamp_base_contract_schemes_5661_duel_win_effect = {
	custom_tooltip = laamp_base_contract_schemes.5661.tt.score_gained
	scope:task_contract = {
		increment_variable_effect = {
			VAR = wins_tally
			VAL = 1
		}
	}
	scope:county_owner = {
		add_opinion = {
			target = root
			modifier = gallowsbait_scum_opinion
			opinion = -40
		}
		if = {
			limit = {
				NOT = { this = scope:employer }
			}
			add_opinion = {
				target = scope:employer
				modifier = respect_opinion
				opinion = -25
			}
		}
	}
	scope:current_county = { change_county_control = major_county_control_loss }
}

scripted_effect loaa_laamp_base_contract_schemes_5661_duel_loss_effect = {
	custom_tooltip = laamp_base_contract_schemes.5661.tt.no_score_gain
	reverse_add_opinion = {
		target = scope:county_owner
		modifier = gallowsbait_scum_opinion
		opinion = -20
	}
}

scripted_effect loaa_laamp_base_contract_schemes_5661_roll_duel_effect = {
	duel = {
		skill = $SKILL$
		value = scope:duel_diff
		# Victory!
		50 = {
			compare_modifier = {
				value = scope:duel_value
				multiplier = 3.5
				min = -49
			}
			min = 5
			desc = laamp_base_contract_schemes.5661.$OPTION$.tt.success
			send_interface_toast = {
				type = event_generic_good
				title = laamp_base_contract_schemes.5661.$OPTION$.tt.success
				left_icon = scope:county_owner
				loaa_laamp_base_contract_schemes_5661_duel_win_effect = yes
			}
		}
		# Defeat.
		50 = {
			compare_modifier = {
				value = scope:duel_value
				multiplier = -3.5
				min = -49
			}
			min = 5
			desc = laamp_base_contract_schemes.5661.$OPTION$.tt.failure
			send_interface_toast = {
				type = event_generic_bad
				title = laamp_base_contract_schemes.5661.$OPTION$.tt.failure
				left_icon = scope:county_owner
				loaa_laamp_base_contract_schemes_5661_duel_loss_effect = yes
			}
		}
	}
}

scripted_effect loaa_laamp_base_contract_schemes_5661_officer_aptitude_duel_effect = {
	scope:officer = {
		stress_impact = {
			base = medium_stress_gain
			diligent = minor_stress_impact_loss
			lazy = medium_stress_impact_gain
		}
	}
	custom_tooltip = option_boilerplate.tt.officer_aptitude
	random_list = {
		0 = {
			desc = option_boilerplate.tt.officer_aptitude.success
			loaa_laamp_base_contract_schemes_5661_duel_win_effect = yes
			# Raw aptitude.
			modifier = {
				add = {
					scope:officer ?= { add = add_camp_officer_aptitude_value }
					multiply = 20
					min = 5
					max = 95
				}
				always = yes
			}
		}
		0 = {
			desc = option_boilerplate.tt.officer_aptitude.failure
			loaa_laamp_base_contract_schemes_5661_duel_loss_effect = yes
			# Raw aptitude.
			modifier = {
				add = {
					scope:officer ?= { add = add_camp_officer_aptitude_value }
					multiply = -20
					min = 5
					max = 95
				}
				always = yes
			}
		}
	}
}

#	You arrive at a rustling target.
loaa_laamp_base_contract_schemes.5661 = {
	type = character_event
	title = laamp_base_contract_schemes.5661.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					NOT = { exists = global_var:AGOT_is_loaded }
					scope:current_county = title:c_byzantion
				}
				desc = laamp_base_contract_schemes.5661.desc.intro.constantinople
			}
			triggered_desc = {
				trigger = {
					location = { terrain = plains }
				}
				desc = laamp_base_contract_schemes.5661.desc.intro.plains
			}
			triggered_desc = {
				trigger = {
					location = { terrain = farmlands }
				}
				desc = laamp_base_contract_schemes.5661.desc.intro.farmlands
			}
			triggered_desc = {
				trigger = {
					location = { terrain = hills }
				}
				desc = laamp_base_contract_schemes.5661.desc.intro.hills
			}
			triggered_desc = {
				trigger = {
					location = { terrain = mountains }
				}
				desc = laamp_base_contract_schemes.5661.desc.intro.mountains
			}
			triggered_desc = {
				trigger = {
					location = { terrain = desert }
				}
				desc = laamp_base_contract_schemes.5661.desc.intro.desert
			}
			triggered_desc = {
				trigger = {
					location = { terrain = desert_mountains }
				}
				desc = laamp_base_contract_schemes.5661.desc.intro.desert_mountains
			}
			triggered_desc = {
				trigger = {
					location = { terrain = oasis }
				}
				desc = laamp_base_contract_schemes.5661.desc.intro.oasis
			}
			triggered_desc = {
				trigger = {
					location = { terrain = jungle }
				}
				desc = laamp_base_contract_schemes.5661.desc.intro.jungle
			}
			triggered_desc = {
				trigger = {
					location = { terrain = forest }
				}
				desc = laamp_base_contract_schemes.5661.desc.intro.forest
			}
			triggered_desc = {
				trigger = {
					location = { terrain = taiga }
				}
				desc = laamp_base_contract_schemes.5661.desc.intro.taiga
			}
			triggered_desc = {
				trigger = {
					location = { terrain = wetlands }
				}
				desc = laamp_base_contract_schemes.5661.desc.intro.wetlands
			}
			triggered_desc = {
				trigger = {
					location = { terrain = steppe }
				}
				desc = laamp_base_contract_schemes.5661.desc.intro.steppe
			}
			triggered_desc = {
				trigger = {
					location = { terrain = floodplains }
				}
				desc = laamp_base_contract_schemes.5661.desc.intro.floodplains
			}
			triggered_desc = {
				trigger = {
					location = { terrain = drylands }
				}
				desc = laamp_base_contract_schemes.5661.desc.intro.drylands
			}
		}
		desc = laamp_base_contract_schemes.5661.desc.intro.postamble
		desc = boilerplate.paragraph
		random_valid = {
			desc = laamp_base_contract_schemes.5661.desc.opportunity.01
			desc = laamp_base_contract_schemes.5661.desc.opportunity.02
			desc = laamp_base_contract_schemes.5661.desc.opportunity.03
			desc = laamp_base_contract_schemes.5661.desc.opportunity.04
			desc = laamp_base_contract_schemes.5661.desc.opportunity.05
			desc = laamp_base_contract_schemes.5661.desc.opportunity.06
		}
		desc = laamp_base_contract_schemes.5661.desc.outro
	}
	theme = martial
	left_portrait = {
		character = root
		animation = marshal
	}
	right_portrait = {
		character = scope:county_owner
		animation = fear
	}
	lower_left_portrait = scope:officer
	override_background = { reference = wilderness }

	immediate = {
		select_local_farm_animal_effect = yes
		# Increment our encounter tally.
		scope:task_contract = {
			increment_variable_effect = {
				VAR = encounter_tally
				VAL = 1
			}
		}
		# Update on our successes.
		custom_tooltip = laamp_base_contract_schemes.5661.tt.encounter_tally
		custom_tooltip = laamp_base_contract_schemes.5661.tt.current_successes
		# Nab some scopes for loc'n'effects.
		location.county = {
			save_scope_as = current_county
			holder = { save_scope_as = county_owner }
		}
		# Try to nab a valid officer.
		## First assembling potential candidates.
		court_position:head_groom_camp_officer ?= {
			if = {
				limit = { is_available = yes }
				add_to_list = available_officers_list
			}
		}
		court_position:huntperson_camp_officer ?= {
			if = {
				limit = { is_available = yes }
				add_to_list = available_officers_list
			}
		}
		court_position:kennelperson_camp_officer ?= {
			if = {
				limit = { is_available = yes }
				add_to_list = available_officers_list
			}
		}
		court_position:master_of_spoils_camp_officer ?= {
			if = {
				limit = { is_available = yes }
				add_to_list = available_officers_list
			}
		}
		## Then getting whoever does their job best.
		ordered_in_list = {
			list = available_officers_list
			order_by = add_camp_officer_aptitude_value
			save_scope_as = officer
		}
		# Remember to set up our duel difficulty!
		save_scope_value_as = {
			name = duel_diff
			value = {
				value = mediocre_skill_rating
				add = scope:employer.highest_held_title_tier
			}
		}
	}

	# Prowess duel.
	option = {
		name = laamp_base_contract_schemes.5661.a
		skill = prowess

		loaa_laamp_base_contract_schemes_5661_roll_duel_effect = {
			SKILL = prowess
			OPTION = a
		}

		# No stress here.
		ai_chance = {
			base = 1
			modifier = {
				add = {
					value = prowess
					subtract = scope:duel_diff
					multiply = 5
				}
				always = yes
			}
		}
	}

	# Martial duel.
	option = {
		name = laamp_base_contract_schemes.5661.b
		trigger = { martial >= stewardship }

		loaa_laamp_base_contract_schemes_5661_roll_duel_effect = {
			SKILL = martial
			OPTION = b
		}

		# No stress here.
		ai_chance = {
			base = 1
			modifier = {
				add = {
					value = martial
					subtract = scope:duel_diff
					multiply = 5
				}
				always = yes
			}
		}
	}

	# Stewardship duel.
	option = {
		name = laamp_base_contract_schemes.5661.c
		trigger = { stewardship > martial }

		loaa_laamp_base_contract_schemes_5661_roll_duel_effect = {
			SKILL = stewardship
			OPTION = c
		}

		# No stress here.
		ai_chance = {
			base = 1
			modifier = {
				add = {
					value = stewardship
					subtract = scope:duel_diff
					multiply = 5
				}
				always = yes
			}
		}
	}

	# Officer: groom.
	option = {
		name = laamp_base_contract_schemes.5661.d
		trigger = {
			scope:officer ?= { has_court_position = head_groom_camp_officer }
		}
		reason = have_head_groom

		loaa_laamp_base_contract_schemes_5661_officer_aptitude_duel_effect = yes

		stress_impact = {
			lazy = miniscule_stress_impact_loss
			diligent = minor_stress_impact_gain
		}
		ai_chance = {
			base = 1
			modifier = {
				add = {
					scope:officer ?= { add = "aptitude(head_groom_camp_officer)" }
					multiply = 5
				}
				always = yes
			}
		}
	}

	# Officer: hunter.
	option = {
		name = laamp_base_contract_schemes.5661.e
		trigger = {
			scope:officer ?= { has_court_position = huntperson_camp_officer }
		}
		reason = have_huntperson

		loaa_laamp_base_contract_schemes_5661_officer_aptitude_duel_effect = yes

		stress_impact = {
			lazy = miniscule_stress_impact_loss
			diligent = minor_stress_impact_gain
		}
		ai_chance = {
			base = 1
			modifier = {
				add = {
					scope:officer ?= { add = "aptitude(huntperson_camp_officer)" }
					multiply = 5
				}
				always = yes
			}
		}
	}

	# Officer: kenneler.
	option = {
		name = laamp_base_contract_schemes.5661.f
		trigger = {
			scope:officer ?= { has_court_position = kennelperson_camp_officer }
		}
		reason = have_kennelperson

		loaa_laamp_base_contract_schemes_5661_officer_aptitude_duel_effect = yes

		stress_impact = {
			lazy = miniscule_stress_impact_loss
			diligent = minor_stress_impact_gain
		}
		ai_chance = {
			base = 1
			modifier = {
				add = {
					scope:officer ?= { add = "aptitude(kennelperson_camp_officer)" }
					multiply = 5
				}
				always = yes
			}
		}
	}

	# Officer: spoiler.
	option = {
		name = laamp_base_contract_schemes.5661.g
		trigger = {
			scope:officer ?= { has_court_position = master_of_spoils_camp_officer }
		}
		reason = have_master_of_spoils

		loaa_laamp_base_contract_schemes_5661_officer_aptitude_duel_effect = yes

		stress_impact = {
			lazy = miniscule_stress_impact_loss
			diligent = minor_stress_impact_gain
		}
		ai_chance = {
			base = 1
			modifier = {
				add = {
					scope:officer ?= { add = "aptitude(master_of_spoils_camp_officer)" }
					multiply = 5
				}
				always = yes
			}
		}
	}

	# You have no valid officers.
	option = {
		name = laamp_base_contract_schemes.5661.h
		trigger = {
			custom_tooltip = {
				text = laamp_base_contract_schemes.5661.h.tt.need_groom_hunter_kenneler_or_spoiler
				always = no
			}
		}
		show_as_unavailable = {
			NOT = { exists = scope:officer }
		}

		# Dummy option to let you know how you _could_ have had an extra option.
	}

	# Stress your way through it.
	option = {
		name = laamp_base_contract_schemes.5661.i

		loaa_laamp_base_contract_schemes_5661_duel_win_effect = yes

		stress_impact = {
			base = major_stress_gain
			diligent = minor_stress_loss
			lazy = medium_stress_gain
		}
		ai_chance = {
			base = 1
			# Only take this if we're an over-achiever.
			ai_value_modifier = { ai_energy = 2 }
		}
	}

	after = {
		if = {
			limit = { scope:task_contract.var:encounter_tally >= scope:task_contract.var:encounter_max }
			# Did we do good?
			if = {
				limit = { scope:task_contract.var:wins_tally >= 1 }
				trigger_event = loaa_laamp_base_contract_schemes.5662
			}
			# Otherwise, we did bad.
			else = { trigger_event = loaa_laamp_base_contract_schemes.5663 }
		}
	}
}

#	You have rustled sufficiently.
loaa_laamp_base_contract_schemes.5662 = {
	type = character_event
	window = scheme_successful_event
	title = laamp_base_contract_schemes.5662.t
	desc = laamp_base_contract_schemes.5662.desc
	theme = martial
	left_portrait = {
		character = root
		animation = schadenfreude
	}
	right_portrait = {
		character = scope:employer
		animation = rage
	}
	override_background = { reference = throne_room }

	immediate = {
		scope:task_contract = {
			# Did you earn a crit success?
			if = {
				limit = { var:wins_tally >= var:encounter_max }
				complete_task_contract = success_critical
			}
			# Failing that, earn a regular success
			else = {
				complete_task_contract = success_standard
			}
		}
	}

	# Acknowledged.
	option = {
		name = laamp_base_contract_schemes.5662.a

		custom_tooltip = laamp_base_contract_schemes.0000.f.contract_concluded

		# No stress, no AI.
	}
}

#	Your rustling leaves something to be desired.
loaa_laamp_base_contract_schemes.5663 = {
	type = character_event
	window = scheme_failed_event
	title = laamp_base_contract_schemes.5663.t
	desc = laamp_base_contract_schemes.5663.desc
	theme = martial
	left_portrait = {
		character = root
		animation = stress
	}
	right_portrait = {
		character = scope:employer
		animation = dismissal
	}
	override_background = { reference = throne_room }

	immediate = {
		scope:task_contract = { complete_task_contract = failure_standard }
	}

	# Acknowledged.
	option = {
		name = laamp_base_contract_schemes.5663.a

		custom_tooltip = laamp_base_contract_schemes.0000.f.contract_concluded

		# No stress, no AI.
	}
}