﻿# Protect domain
loaa_protect_domain = {
	group = laamp_contracts_war_group
	icon = "gfx/interface/icons/trait_level_tracks/mercenary.dds"

	travel = yes
	use_diplomatic_range = no

	weight = {
		# Standard weights.
		value = task_contract_weight_default_value
		add = laamp_contracts_weight_up_martial_value
		add = laamp_contracts_weight_up_martial_slight_value
		# Employer weights.
		scope:employer = {
			add = {
				# Weight up.
				## Traits that care about defence.
				### We don't check paranoid because they're already filtered out due to this being relative strangers.
				if = {
					limit = { has_trait = stubborn }
					add = task_contract_weight_bonus_employer_has_associated_traits_value
				}
				if = {
					limit = { has_trait = greedy }
					add = task_contract_weight_bonus_employer_has_associated_traits_value
				}
				# Weight down.
				## Traits that think their defences are definitely fiiiiiine.
				if = {
					limit = { has_trait = arrogant }
					add = task_contract_weight_malus_employer_has_associated_traits_value
				}
				if = {
					limit = { has_trait = trusting }
					add = task_contract_weight_malus_employer_has_associated_traits_value
				}
				if = {
					limit = { has_trait = fickle }
					add = task_contract_weight_malus_employer_has_associated_traits_value
				}
				# Restrictions.
				min = task_contract_weight_employer_associated_traits_min_value
				max = task_contract_weight_employer_associated_traits_max_value
			}
			multiply = task_contract_weight_by_tier_value
			# This weight is an override, so make sure it's placed at the bottom.
			add = task_contract_weight_employer_contact_list_value
		}
	}

	# Validity Triggers
	valid_to_create = {
		always = no
	}
	valid_to_accept = {
		# Standard triggers.
		valid_laamp_basic_accept_only_trigger = yes
		loaa_valid_laamp_basic_trigger = {
			EMPLOYER = scope:employer
			LAAMP = root
		}
		scope:employer = { is_landed = yes }
	}
	valid_to_continue = {
		# Standard triggers.
		loaa_valid_laamp_basic_trigger = {
			EMPLOYER = root.task_contract_employer
			LAAMP = root.task_contract_taker
		}
		task_contract_employer = { is_landed = yes }
	}
	valid_to_keep = {
		# Standard triggers.
		loaa_valid_laamp_basic_trigger = {
			EMPLOYER = root.task_contract_employer
			LAAMP = root.task_contract_taker
		}
		task_contract_employer = { is_landed = yes }
	}

	on_invalidated = {
		if = {
			limit = {
				root.task_contract_taker = {
					any_character_active_contract = {
						this = root
					}
				}
			}
			save_scope_as = task_contract
			task_contract_taker = {
				save_scope_as = task_contract_taker
			}
			task_contract_employer = {
				save_scope_as = task_contract_employer
			}
			save_scope_value_as = {
				name = task_contract_tier
				value = root.task_contract_tier
			}
			var:task_contract_destination = {
				save_scope_as = task_contract_destination
			}
			var:task_contract_target = {
				save_scope_as = task_contract_target
			}
			task_contract_taker = {
				set_variable = {
					name = invalidated_task_contract_type
					value = flag:loaa_protect_domain
				}
				save_scope_as = task_contract_taker
			}
			if = {
				limit = { scope:task_contract = { has_variable = task_contract_voluntary_invalidation } }
				scope:task_contract_employer = { loaa_contract_invalidation_penalty_effect = yes }
			}
			if = {
				limit = {
					task_contract_employer = {
						is_alive = no
					}
				}
				task_contract_employer.primary_title.holder ?= {
					save_scope_as = employer_heir
				}
				task_contract_taker = {
					save_scope_value_as = {
						name = task_contract_invalidation_reason
						value = flag:employer_dead
					}
					trigger_event = ep3_contract_event.0012

				}
			}
			else_if = {
				limit = {
					scope:task_contract_target = {
						is_alive = no
					}
				}
				task_contract_taker = {
					save_scope_value_as = {
						name = task_contract_invalidation_reason
						value = flag:target_dead
					}
					trigger_event = ep3_contract_event.0012
				}
			}
			scope:task_contract_taker = {
				if = {
					limit = {
						has_variable_list = protect_domain_wars
					}
					clear_variable_list = protect_domain_wars
					remove_variable = protect_domain_wars
				}
			}
			scope:task_contract_target = {
				remove_opinion = {
					modifier = event_negotiated_alliance_opinion
					target = scope:task_contract_taker
				}
				remove_variable = protect_domain_adventurer
			}
			scope:task_contract_employer = {
				remove_variable = offered_contract
				hidden_effect = {
					increment_variable_effect = {
						VAR = employed_adventurers_num
						VAL = -1
					}
					send_interface_toast = {
						type = event_contract_invalidated
						title = event_contract_invalidated_tt
						desc = event_contract_invalidated_desc
						custom_tooltip = { text = event_contract_invalidated_desc }
						left_icon = this
						right_icon = scope:task_contract_taker
					}
				}
				remove_variable = protect_domain_adventurer
			}
		}
	}

	on_create = {
		scope:contract = {
			save_scope_as = task_contract
			task_contract_target = {
				save_scope_as = task_contract_target
			}
            task_contract_taker = {
                save_scope_as = task_contract_taker
            }
			task_contract_employer = {
				save_scope_as = task_contract_employer

				if = {
					limit = {
						NOT = { exists = scope:task_contract.task_contract_destination }
					}
					scope:task_contract_target = {
						capital_province = {
							save_scope_as = task_contract_destination
						}
					}
				}
			}
			set_variable = {
				name = task_contract_employer
				value = scope:task_contract_employer
			}
			set_variable = {
				name = task_contract_target
				value = scope:task_contract_target
			}
			set_variable = {
				name = task_contract_destination
				value = scope:task_contract_destination
			}
			set_variable = {
				name = loaa_total_warscore
				value = 0
			}
			set_variable = {
				name = loaa_finished_wars
				value = 0
			}
			set_variable = {
				name = gold_success_standard
				value = loaa_protect_domain_final_payment_value
			}
		}
	}

	# On_actions
	on_accepted = {
		task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_accept_contract" }
		save_scope_as = task_contract
		set_variable = {
			name = contract_type
			value = flag:war
		}
		# For the intro event.
		task_contract_taker ?= {
			save_scope_as = adventurer
			trigger_event = loaa_contract_event.9000
		}
		# set_variable = {
		# 	name = task_contract_taker
		# 	value = scope:adventurer
		# }
		task_contract_employer = {
			employer_contract_accepted_info_effect = yes
		}
	}

	# Rewards
	task_contract_reward = {
		success_standard = {
			should_print_on_complete = yes
			effect = {
				task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_success_on_contract" }
				save_scope_value_as = { name = extra_reward value = flag:no }
				save_scope_as = task_contract
				save_temporary_scope_value_as = {
					name = end_reward
					value = scope:task_contract.var:gold_success_standard
				}
				# Standard Rewards.
				loaa_laamp_rewards_disburse_ordinary_currency_effect = {
					GOLD = scope:task_contract.var:gold_success_standard
					PRESTIGE = 0
					PIETY = 0
					PROVISIONS = task_contract_success_provisions_gain_major_value
					OPINION = task_contract_opinion_standard_reward_value
					OPINION_TYPE = succeeded_task_contract_opinion
					CONTACT = yes
					CONTACT_HOOK = no
					EXTRA_REWARD = scope:extra_reward
				}
				task_contract_taker = {
					save_scope_as = task_contract_taker
					loaa_target_task_successful_noncrim_contract_count_effect = yes
					war_contracts_completed_tracker_effect = yes
					save_scope_as = adventurer
				}
				task_contract_target = {
					save_scope_as = task_contract_target
					save_scope_as = contract_target
				}
				save_scope_as = task_contract
				save_scope_as = protection_contract
				hidden_effect = {
					if = {
						limit = {
							exists = scope:task_contract.var:loaa_total_warscore
							scope:task_contract.var:loaa_total_warscore ?= {
								this > 0
							}
						}
						task_contract_employer = {
							contract_target_reaction_effect = yes
						}
					}
				}

				# Update Knight-Errant score.
				task_contract_taker = {
					save_scope_as = task_contract_taker
					laamp_rewards_apply_knight_errant_xp_effect = {
						XP_MAX = knight_errant_xp_minor_gain
						XP_MIN = knight_errant_xp_minor_gain
					}
					loaa_target_task_contract_justicar_contract_tracker_effect = yes
				}
				task_contract_employer = {
					employer_contract_completed_info_effect = yes
				}
			}
		}
		failure_standard = {
			positive = no
			should_print_on_complete = yes
			effect = {
				task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_failure_on_contract" }
				save_scope_value_as = { name = extra_reward value = flag:no }
				# Standard Penalties.
				loaa_laamp_rewards_disburse_ordinary_currency_effect = {
					GOLD = 0
					PRESTIGE = task_contract_failure_prestige_loss_full_value
					PIETY = 0
					PROVISIONS = task_contract_failure_provisions_gain_minor_value
					OPINION = task_contract_opinion_standard_failure_value
					OPINION_TYPE = failed_task_contract_opinion
					CONTACT = no
					CONTACT_HOOK = no
					EXTRA_REWARD = scope:extra_reward
				}
				save_scope_value_as = {
					name = task_contract_outcome
					value = flag:failure
				}
				task_contract_target = {
					save_temporary_scope_as = contract_target
				}
				task_contract_taker = {
					save_scope_as = adventurer
				}
				task_contract_employer = {
					employer_contract_failed_info_effect = yes
				}
			}
		}
	}
}

# Raid for Captives
loaa_laamp_raid_contract = {
	group = laamp_contracts_war_group
	icon = "gfx/interface/icons/casus_bellis/request_mercenary.dds"
	travel = no
	use_diplomatic_range = no

	# Validity Triggers
	valid_to_create = {
		always = no
	}
	valid_to_accept = {
		# Standard triggers.
		valid_laamp_basic_accept_only_trigger = yes
		loaa_valid_laamp_basic_trigger = {
			EMPLOYER = scope:employer
			LAAMP = root
		}
	}
	valid_to_continue = {
		# Standard triggers.
		loaa_valid_laamp_basic_trigger = {
			EMPLOYER = root.task_contract_employer
			LAAMP = root.task_contract_taker
		}
	}
	valid_to_keep = {
		# Standard triggers.
		loaa_valid_laamp_basic_trigger = {
			EMPLOYER = root.task_contract_employer
			LAAMP = root.task_contract_taker
		}
	}

	weight = {
		# Standard weights.
		value = task_contract_weight_interesting_somewhat_rare_value
		add = laamp_contracts_weight_up_mercenary_value
		add = laamp_contracts_weight_up_martial_slight_value
		add = task_contract_weight_employer_contact_list_value
		scope:employer = { multiply = task_contract_weight_by_tier_value }
	}

	on_create = {
		scope:contract = {
			save_scope_as = task_contract
            task_contract_taker = {
                save_scope_as = task_contract_taker
            }
			task_contract_target = {
				save_scope_as = task_contract_target
			}
			task_contract_employer = {
				save_scope_as = task_contract_employer

				if = {
					limit = {
						NOT = { exists = scope:task_contract.task_contract_destination }
					}
					scope:task_contract_target = {
						capital_province = {
							save_scope_as = task_contract_destination
						}
					}
				}
			}
			set_variable = {
				name = task_contract_employer
				value = scope:task_contract_employer
			}
			set_variable = {
				name = task_contract_target
				value = scope:task_contract_target
			}
			set_variable = {
				name = task_contract_destination
				value = scope:task_contract_destination
			}
		}
	}
	# On_Actions
	on_accepted = {
		task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_accept_contract" }
		save_scope_as = task_contract
		set_variable = {
			name = contract_type
			value = flag:war
		}
		task_contract_taker = {
			trigger_event = { id = loaa_contract_event.0003 delayed = yes }
			save_scope_as = adventurer
		}
		task_contract_employer = {
			employer_contract_accepted_info_effect = yes
		}
	}

	on_invalidated = {
		if = {
			limit = {
				root.task_contract_taker = {
					any_character_active_contract = {
						this = root
					}
				}
			}
			save_scope_as = task_contract
			task_contract_employer = {
				save_scope_as = task_contract_employer
			}
			save_scope_value_as = {
				name = task_contract_tier
				value = root.task_contract_tier
			}
			var:task_contract_destination = {
				save_scope_as = task_contract_destination
			}
			var:task_contract_target = {
				save_scope_as = task_contract_target
			}
			task_contract_taker = {
				set_variable = {
					name = invalidated_task_contract_type
					value = flag:laamp_raid_contract
				}
				save_scope_as = task_contract_taker
			}
			if = {
				limit = { scope:task_contract = { has_variable = task_contract_voluntary_invalidation } }
				scope:task_contract_employer = { loaa_contract_invalidation_penalty_effect = yes }
			}
			if = {
				limit = {
					task_contract_employer = {
						is_alive = no
					}
				}
				task_contract_employer.primary_title.holder ?= {
					save_scope_as = employer_heir
				}
				task_contract_taker = {
					save_scope_value_as = {
						name = task_contract_invalidation_reason
						value = flag:employer_dead
					}
					trigger_event = ep3_contract_event.0012

				}
			}
			else_if = {
				limit = {
					scope:task_contract_target = {
						is_alive = no
					}
				}
				task_contract_taker = {
					save_scope_value_as = {
						name = task_contract_invalidation_reason
						value = flag:target_dead
					}
					trigger_event = ep3_contract_event.0012
				}
			}
			scope:task_contract_employer = {
				hidden_effect = {
					remove_variable = offered_contract
					increment_variable_effect = {
						VAR = employed_adventurers_num
						VAL = -1
					}
					send_interface_toast = {
						type = event_contract_invalidated
						title = event_contract_invalidated_tt
						desc = event_contract_invalidated_desc
						custom_tooltip = { text = event_contract_invalidated_desc }
						left_icon = this
						right_icon = scope:task_contract_taker
					}
				}
			}
		}
	}

	# Rewards
	task_contract_reward = {
		success_standard = {
			effect = {
				task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_success_on_contract" }
				save_scope_as = task_contract
				task_contract_taker = {
					save_scope_as = adventurer
					scope:task_contract.var:task_contract_employer = {
						save_scope_as = task_contract_employer
					}
					#saving scopes for custom tooltip
					save_scope_as = attacker
					scope:task_contract.var:task_contract_target = {
						save_scope_as = defender
					}
					custom_tooltip = ep3_laamp_raid_contract_cb_prisoners.tt_attacker
					custom_tooltip = ep3_laamp_raid_contract_cb_prisoners.tt_gold
					trigger_event = loaa_contract_event.0004
					show_as_tooltip = {
						if = {
							limit = {
								faith != scope:defender.faith
							}
							add_piety = minor_piety_gain
						}
					}
					# Huck 'em into our contact list.
					add_contact = scope:task_contract_employer
					# Give hook as well as contact
					add_hook_if_possible_default_length_effect = {
						TARGET = scope:task_contract_employer
						TYPE = contact_list_weak_hook
					}
					war_contracts_completed_tracker_effect = yes
				}
			}
		}
		failure_standard = {
			positive = no
			effect = {
				task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_failure_on_contract" }
				save_scope_as = task_contract
				task_contract_taker = {
					scope:task_contract.task_contract_employer = {
						save_scope_as = task_contract_employer
					}
					save_scope_value_as = {
						name = task_contract_outcome
						value = flag:failure
					}
					save_scope_value_as = {
						name = task_contract_tier
						value = scope:task_contract.task_contract_tier
					}
					trigger_event = ep3_contract_event.0004
				}
				show_as_tooltip = {
					task_contract_taker = {
						add_prestige = task_contract_failure_prestige_loss_full_value
						reverse_add_opinion = {
							opinion = -50
							modifier = failed_task_contract_opinion
							target = scope:task_contract.task_contract_employer
						}
					}
				}
				task_contract_employer = { employer_contract_failed_info_effect = yes }
			}
		}
	}
}

# Pillaging Raid
loaa_pillage_contract = {
	group = laamp_contracts_war_group
	icon = "gfx/interface/icons/casus_bellis/request_mercenary.dds"
	#is_criminal = yes
	travel = no
	use_diplomatic_range = no

	# Validity Triggers
	valid_to_create = {
		always = no
	}
	valid_to_accept = {
		# Standard triggers.
		valid_laamp_basic_accept_only_trigger = yes
		loaa_valid_laamp_basic_trigger = {
			EMPLOYER = scope:employer
			LAAMP = root
		}
	}
	valid_to_continue = {
		# Standard triggers.
		loaa_valid_laamp_basic_trigger = {
			EMPLOYER = root.task_contract_employer
			LAAMP = root.task_contract_taker
		}
	}
	valid_to_keep = {
		# Standard triggers.
		loaa_valid_laamp_basic_trigger = {
			EMPLOYER = root.task_contract_employer
			LAAMP = root.task_contract_taker
		}
	}

	weight = {
		# Standard weights.
		value = task_contract_weight_interesting_somewhat_rare_value
		add = laamp_contracts_weight_up_mercenary_value
		add = laamp_contracts_weight_up_martial_slight_value
		add = task_contract_weight_employer_contact_list_value
		scope:employer = { multiply = task_contract_weight_by_tier_value }
	}

	on_create = {
		scope:contract = {
			save_scope_as = task_contract
            task_contract_taker = {
                save_scope_as = task_contract_taker
            }
			task_contract_target = {
				save_scope_as = task_contract_target
			}
			task_contract_employer = {
				save_scope_as = task_contract_employer

				if = {
					limit = {
						NOT = { exists = scope:task_contract.task_contract_destination }
					}
					scope:task_contract_target = {
						capital_province = {
							save_scope_as = task_contract_destination
						}
					}
				}
			}
			set_variable = {
				name = task_contract_employer
				value = scope:task_contract_employer
			}
			set_variable = {
				name = task_contract_target
				value = scope:task_contract_target
			}
			set_variable = {
				name = task_contract_destination
				value = scope:task_contract_destination
			}
		}
	}
	# On_Actions
	on_accepted = {
		task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_accept_contract" }
		save_scope_as = task_contract
		task_contract_taker = {
			save_scope_as = adventurer
		}
		task_contract_target = {
			save_scope_as = task_contract_target
		}
		task_contract_employer = {
			employer_contract_accepted_info_effect = yes
		}
		task_contract_taker = {
			trigger_event = loaa_contract_event.9100
		}
	}

	on_invalidated = {
		if = {
			limit = {
				root.task_contract_taker = {
					any_character_active_contract = {
						this = root
					}
				}
			}
			save_scope_as = task_contract
			task_contract_employer = {
				save_scope_as = task_contract_employer
			}
			save_scope_value_as = {
				name = task_contract_tier
				value = root.task_contract_tier
			}
			var:task_contract_destination = {
				save_scope_as = task_contract_destination
			}
			var:task_contract_target = {
				save_scope_as = task_contract_target
			}
			task_contract_taker = {
				set_variable = {
					name = invalidated_task_contract_type
					value = flag:loaa_pillage_contract
				}
				save_scope_as = task_contract_taker
			}
			if = {
				limit = { scope:task_contract = { has_variable = task_contract_voluntary_invalidation } }
				scope:task_contract_employer = { loaa_contract_invalidation_penalty_effect = yes }
			}
			if = {
				limit = {
					task_contract_employer = {
						is_alive = no
					}
				}
				task_contract_employer.primary_title.holder ?= {
					save_scope_as = employer_heir
				}
				task_contract_taker = {
					save_scope_value_as = {
						name = task_contract_invalidation_reason
						value = flag:employer_dead
					}
					trigger_event = ep3_contract_event.0012

				}
			}
			else_if = {
				limit = {
					scope:task_contract_target = {
						is_alive = no
					}
				}
				task_contract_taker = {
					save_scope_value_as = {
						name = task_contract_invalidation_reason
						value = flag:target_dead
					}
					trigger_event = ep3_contract_event.0012
				}
			}
			scope:task_contract_employer = {
				hidden_effect = {
					remove_variable = offered_contract
					increment_variable_effect = {
						VAR = employed_adventurers_num
						VAL = -1
					}
					send_interface_toast = {
						type = event_contract_invalidated
						title = event_contract_invalidated_tt
						desc = event_contract_invalidated_desc
						custom_tooltip = { text = event_contract_invalidated_desc }
						left_icon = this
						right_icon = scope:task_contract_taker
					}
				}
			}
		}
	}

	# Rewards
	task_contract_reward = {
		success_standard = {
			effect = {
				task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_success_on_contract" }
				task_contract_taker = { save_scope_as = adventurer }
				save_scope_as = task_contract
				task_contract_taker = {
					scope:task_contract.var:task_contract_employer = {
						save_scope_as = task_contract_employer
					}
					#saving scopes for custom tooltip
					save_scope_as = attacker
					scope:task_contract.var:task_contract_target = {
						save_scope_as = defender
					}
					custom_tooltip = loaa_pillage_contract_cb.tt_gold
					trigger_event = loaa_contract_event.9101
					show_as_tooltip = {
						if = {
							limit = {
								faith != scope:defender.faith
							}
							add_piety = minor_piety_gain
						}
					}
					# Huck 'em into our contact list.
					add_contact = scope:task_contract_employer
					# Give hook as well as contact
					add_hook_if_possible_default_length_effect = {
						TARGET = scope:task_contract_employer
						TYPE = contact_list_weak_hook
					}

					war_contracts_completed_tracker_effect = yes
				}
				task_contract_employer = {
					employer_contract_completed_info_effect = yes
				}
			}
		}
		failure_standard = {
			positive = no
			effect = {
				task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_failure_on_contract" }
				save_scope_as = task_contract
				task_contract_taker = {
					scope:task_contract.task_contract_employer = {
						save_scope_as = task_contract_employer
					}
					save_scope_value_as = {
						name = task_contract_outcome
						value = flag:failure
					}
					save_scope_value_as = {
						name = task_contract_tier
						value = scope:task_contract.task_contract_tier
					}
					trigger_event = loaa_contract_event.9101
				}
				show_as_tooltip = {
					task_contract_taker = {
						add_prestige = task_contract_failure_prestige_loss_full_value
						reverse_add_opinion = {
							opinion = -50
							modifier = failed_task_contract_opinion
							target = scope:task_contract.task_contract_employer
						}
					}
				}
				task_contract_employer = { employer_contract_failed_info_effect = yes }
			}

		}
	}
}

# Improve ruler's reputation
loaa_laamp_base_0011 = {
	group = laamp_contracts_diplomacy_group
	icon = "gfx/interface/icons/scheme_types/diplomacy.dds"

	travel = yes
	use_diplomatic_range = no

	weight = {
		# Standard weights.
		value = task_contract_weight_default_value
		add = laamp_contracts_weight_up_diplomacy_value
		add = laamp_contracts_weight_up_diplomacy_slight_value
		# Employer weights.
		scope:employer = {
			add = {
				# Weight up.
				## Traits most likely to suffer from reputational damage generally.
				if = {
					limit = { has_trait = shy }
					add = task_contract_weight_bonus_employer_has_associated_traits_value
				}
				if = {
					limit = { has_trait = callous }
					add = task_contract_weight_bonus_employer_has_associated_traits_value
				}
				if = {
					limit = { has_trait = sadistic }
					add = task_contract_weight_bonus_employer_has_associated_traits_value
				}
				# Weight down.
				## Traits that don't acknowledge fault.
				if = {
					limit = { has_trait = arrogant }
					add = task_contract_weight_malus_employer_has_associated_traits_value
				}
				# Restrictions.
				min = task_contract_weight_employer_associated_traits_min_value
				max = task_contract_weight_employer_associated_traits_max_value
			}
			multiply = task_contract_weight_by_tier_value
			# This weight is an override, so make sure it's placed at the bottom.
			add = task_contract_weight_employer_contact_list_value
		}
	}

	# Validity Triggers
	valid_to_create = {
		always = no
	}
	valid_to_accept = {
		# Standard triggers.
		valid_laamp_basic_accept_only_trigger = yes
		loaa_valid_laamp_basic_trigger = {
			EMPLOYER = scope:employer
			LAAMP = root
		}
		scope:employer = { is_landed = yes }
	}
	valid_to_continue = {
		# Standard triggers.
        #always = yes
		loaa_valid_laamp_basic_trigger = {
			EMPLOYER = root.task_contract_employer
			LAAMP = root.task_contract_taker
		}
		task_contract_employer = { is_landed = yes }
	}
	valid_to_keep = {
		# Standard triggers.
        #always = yes
		loaa_valid_laamp_basic_trigger = {
			EMPLOYER = root.task_contract_employer
			LAAMP = root.task_contract_taker
		}
		task_contract_employer = { is_landed = yes }
	}

	# On_actions
	on_accepted = {
		task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_accept_contract" }
		# For the intro event.
		save_scope_as = task_contract
		set_variable = {
			name = contract_type
			value = flag:diplomacy
		}
		task_contract_target = {
			save_scope_as = task_contract_target
		}
		# Then we start the scheme.
		task_contract_taker ?= {
			start_scheme = {
				type = loaa_laamp_base_0011_contract_scheme
				contract = root
				target_character = scope:task_contract_target
			}
			# Make a note of what the scheme even is; we'll need this for the event too.
			scope:task_contract.scheme = { save_scope_as = scheme }
			trigger_event = laamp_base_contract_schemes.0011
			save_scope_as = adventurer
		}
		task_contract_employer = {
			employer_contract_accepted_info_effect = yes
		}
	}
	on_create = {
		scope:contract = {
			# Make our gold rewards static.
			grab_gold_fuzz_number_effect = yes
			save_scope_as = task_contract
			set_variable = {
				name = gold_success_standard
				value = task_contract_taker.loaa_task_contract_success_gold_gain_full_value
			}
			# Make sure critical values are a bit higher.
			save_scope_value_as = { name = gold_safety_margin value = flag:yes }
			set_variable = {
				name = gold_success_critical
				value = task_contract_taker.loaa_task_contract_success_gold_gain_full_value
			}
		}
	}


	on_invalidated = {
		if = {
			limit = {
				root.task_contract_taker = {
					any_character_active_contract = {
						this = root
					}
				}
			}
			save_scope_as = task_contract
			task_contract_employer = {
				save_scope_as = task_contract_employer
			}
			save_scope_value_as = {
				name = task_contract_tier
				value = root.task_contract_tier
			}
			var:task_contract_destination = {
				save_scope_as = task_contract_destination
			}
			var:task_contract_target = {
				save_scope_as = task_contract_target
			}
			task_contract_taker = {
				set_variable = {
					name = invalidated_task_contract_type
					value = flag:loaa_laamp_base_0011
				}
				save_scope_as = task_contract_taker
			}
			if = {
				limit = { scope:task_contract = { has_variable = task_contract_voluntary_invalidation } }
				scope:task_contract_employer = { loaa_contract_invalidation_penalty_effect = yes }
			}
			if = {
				limit = {
					task_contract_employer = {
						is_alive = no
					}
				}
				task_contract_employer.primary_title.holder ?= {
					save_scope_as = employer_heir
				}
				task_contract_taker = {
					save_scope_value_as = {
						name = task_contract_invalidation_reason
						value = flag:employer_dead
					}
					trigger_event = ep3_contract_event.0012
				}
			}
			else_if = {
				limit = {
					scope:task_contract_target = {
						is_alive = no
					}
				}
				task_contract_taker = {
					save_scope_value_as = {
						name = task_contract_invalidation_reason
						value = flag:target_dead
					}
					trigger_event = ep3_contract_event.0012
				}
			}
			scope:task_contract_employer = {
				remove_variable = offered_contract
				hidden_effect = {
					increment_variable_effect = {
						VAR = employed_adventurers_num
						VAL = -1
					}
					send_interface_toast = {
						type = event_contract_invalidated
						title = event_contract_invalidated_tt
						desc = event_contract_invalidated_desc
						custom_tooltip = { text = event_contract_invalidated_desc }
						left_icon = this
						right_icon = scope:task_contract_taker
					}
				}
			}
		}
	}

	# Rewards
	task_contract_reward = {
		success_standard = {
			should_print_on_complete = yes
			effect = {
				task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_success_on_contract" }
				save_scope_value_as = { name = extra_reward value = flag:no }
				# Standard Rewards.
				loaa_laamp_rewards_disburse_ordinary_currency_effect = {
					GOLD = scope:task_contract.var:gold_success_standard
					PRESTIGE = task_contract_success_prestige_gain_half_value
					PIETY = 0
					PROVISIONS = task_contract_success_provisions_gain_minor_value
					OPINION = task_contract_opinion_standard_reward_value
					OPINION_TYPE = succeeded_task_contract_opinion
					CONTACT = yes
					CONTACT_HOOK = no
					EXTRA_REWARD = scope:extra_reward
				}
				task_contract_taker = {
					save_scope_as = task_contract_taker
					loaa_target_task_successful_noncrim_contract_count_effect = yes
					save_scope_as = adventurer
				}
				task_contract_target = {
					save_scope_as = task_contract_target
					add_character_modifier = {
						modifier = loaa_reputation_success_employer_modifier
						years = 5
					}
				}
				save_scope_as = task_contract
				save_scope_as = reputation_contract
				task_contract_employer = {
					trigger_event = loaa_contract_event.0050
					employer_contract_completed_info_effect = yes
					contract_target_reaction_effect = yes
				}
			}
		}
		failure_standard = {
			positive = no
			should_print_on_complete = yes
			effect = {
				task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_failure_on_contract" }
				save_scope_value_as = { name = extra_reward value = flag:no }
				# Standard Penalties.
				loaa_laamp_rewards_disburse_ordinary_currency_effect = {
					GOLD = 0
					PRESTIGE = task_contract_failure_prestige_loss_full_value
					PIETY = 0
					PROVISIONS = task_contract_failure_provisions_gain_minor_value
					OPINION = task_contract_opinion_standard_failure_value
					OPINION_TYPE = failed_task_contract_opinion
					CONTACT = no
					CONTACT_HOOK = no
					EXTRA_REWARD = scope:extra_reward
				}
				task_contract_target = {
					save_scope_as = task_contract_target
					save_scope_as = adventurer
					save_temporary_scope_as = contract_target
				}
				save_scope_value_as = {
					name = task_contract_outcome
					value = flag:failure
				}
				save_scope_as = task_contract
				task_contract_employer = {
					employer_contract_failed_info_effect = yes
					save_scope_as = reputation_contract
					contract_target_reaction_effect = yes
				}
			}
		}
	}
}

# Perform a Census
loaa_laamp_base_2011 = {
	group = laamp_contracts_stewardship_group
	icon = "gfx/interface/icons/scheme_types/stewardship.dds"

	travel = no
	use_diplomatic_range = no

	weight = {
		# Standard weights.
		value = task_contract_weight_default_value
		add = laamp_contracts_weight_up_stewardship_value
		# Employer weights.
		scope:employer = {
			add = {
				# Weight up.
				## Traits that care especially for rules and documentation.
				### A.k.a: the good kind of designer.
				if = {
					limit = { has_trait = diligent }
					add = task_contract_weight_bonus_employer_has_associated_traits_value
				}
				if = {
					limit = { has_trait = just }
					add = task_contract_weight_bonus_employer_has_associated_traits_value
				}
				if = {
					limit = { has_trait = greedy }
					add = task_contract_weight_bonus_employer_has_associated_traits_value
				}
				# Weight down.
				## Traits that don't much care for paperwork, preferring vibes.
				### A.k.a: the bad kind of designer.
				if = {
					limit = { has_trait = lazy }
					add = task_contract_weight_malus_employer_has_associated_traits_value
				}
				if = {
					limit = { has_trait = arbitrary }
					add = task_contract_weight_malus_employer_has_associated_traits_value
				}
				# Restrictions.
				min = task_contract_weight_employer_associated_traits_min_value
				max = task_contract_weight_employer_associated_traits_max_value
			}
			multiply = task_contract_weight_by_tier_value
			# This weight is an override, so make sure it's placed at the bottom.
			add = task_contract_weight_employer_contact_list_value
		}
	}

	# Validity Triggers
	valid_to_create = {
		always = no
	}

	valid_to_accept = {
		# Standard triggers.
		valid_laamp_basic_accept_only_trigger = yes
		loaa_valid_laamp_basic_trigger = {
			EMPLOYER = scope:employer
			LAAMP = root
		}
		scope:employer = { is_landed = yes }
	}

	valid_to_continue = {
		# Standard triggers.
		loaa_valid_laamp_basic_trigger = {
			EMPLOYER = root.task_contract_employer
			LAAMP = root.task_contract_taker
		}
		task_contract_employer = { is_landed = yes }
	}
	valid_to_keep = {
		# Standard triggers.
		loaa_valid_laamp_basic_trigger = {
			EMPLOYER = root.task_contract_employer
			LAAMP = root.task_contract_taker
		}
		task_contract_employer = { is_landed = yes }
	}


	on_invalidated = {
		if = {
			limit = {
				root.task_contract_taker = {
					any_character_active_contract = {
						this = root
					}
				}
			}
			save_scope_as = task_contract
			task_contract_employer = {
				save_scope_as = task_contract_employer
			}
			save_scope_value_as = {
				name = task_contract_tier
				value = root.task_contract_tier
			}
			var:task_contract_destination = {
				save_scope_as = task_contract_destination
			}
			var:task_contract_target = {
				save_scope_as = task_contract_target
			}
			task_contract_taker = {
				set_variable = {
					name = invalidated_task_contract_type
					value = flag:loaa_laamp_base_2011
				}
				save_scope_as = task_contract_taker
			}
			if = {
				limit = { scope:task_contract = { has_variable = task_contract_voluntary_invalidation } }
				scope:task_contract_employer = { loaa_contract_invalidation_penalty_effect = yes }
			}
			if = {
				limit = {
					task_contract_employer = {
						is_alive = no
					}
				}
				task_contract_employer.primary_title.holder ?= {
					save_scope_as = employer_heir
				}
				task_contract_taker = {
					save_scope_value_as = {
						name = task_contract_invalidation_reason
						value = flag:employer_dead
					}
					trigger_event = ep3_contract_event.0012

				}
			}
			else_if = {
				limit = {
					scope:task_contract_target = {
						is_alive = no
					}
				}
				task_contract_taker = {
					save_scope_value_as = {
						name = task_contract_invalidation_reason
						value = flag:target_dead
					}
					trigger_event = ep3_contract_event.0012
				}
			}
			task_contract_taker = {
				current_travel_plan = { cancel_travel_plan = yes }
			}
			scope:task_contract_employer = {
				remove_variable = offered_contract
				hidden_effect = {
					increment_variable_effect = {
						VAR = employed_adventurers_num
						VAL = -1
					}
					send_interface_toast = {
						type = event_contract_invalidated
						title = event_contract_invalidated_tt
						desc = event_contract_invalidated_desc
						custom_tooltip = { text = event_contract_invalidated_desc }
						left_icon = this
						right_icon = scope:task_contract_taker
					}
				}
			}
		}
	}

	# On_actions
	on_accepted = {
		task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_accept_contract" }
		# For the intro event.
		save_scope_as = task_contract
		set_variable = {
			name = contract_type
			value = flag:conduct_census
		}
		task_contract_employer = { save_scope_as = employer }
		task_contract_taker = { save_scope_as = adventurer }
		task_contract_employer = {
			employer_contract_accepted_info_effect = yes
		}
		# Then we start the travel.
		task_contract_taker ?= { trigger_event = laamp_base_contract_schemes.2014 }
		# Track our score.
		increment_variable_effect = {
			VAR = destinations_processed
			VAL = 0
		}
		# Plus our methods.
		increment_variable_effect = {
			VAR = destinations_processed_legit_success
			VAL = 0
		}
		increment_variable_effect = {
			VAR = destinations_processed_quartermaster_success
			VAL = 0
		}
		increment_variable_effect = {
			VAR = destinations_processed_lied_success
			VAL = 0
		}
		increment_variable_effect = {
			VAR = destinations_processed_guessed_success
			VAL = 0
		}
		increment_variable_effect = {
			VAR = destinations_processed_legit_failure
			VAL = 0
		}
		increment_variable_effect = {
			VAR = destinations_processed_quartermaster_failure
			VAL = 0
		}
		increment_variable_effect = {
			VAR = destinations_processed_lied_failure
			VAL = 0
		}
		increment_variable_effect = {
			VAR = destinations_processed_guessed_failure
			VAL = 0
		}
	}
	on_create = {
		scope:contract = {
			set_task_contract_target = task_contract_employer
			# Make our gold rewards static.
			grab_gold_fuzz_number_effect = yes
			save_scope_as = task_contract
			set_variable = {
				name = gold_success_standard
				value = task_contract_taker.loaa_task_contract_success_gold_gain_full_value
			}
			# Make sure critical values are a bit higher.
			save_scope_value_as = { name = gold_safety_margin value = flag:yes }
			set_variable = {
				name = gold_success_critical
				value = task_contract_taker.loaa_task_contract_success_gold_gain_full_value
			}
		}
	}

	# Rewards
	task_contract_reward = {
		success_standard = {
			should_print_on_complete = yes
			effect = {
				task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_success_on_contract" }
				# Camp building extra Stewardship Rewards: +50%.
				if = {
					limit = {
						task_contract_taker.domicile ?= { has_domicile_parameter = camp_improved_stewardship_contract_rewards }
					}
					save_scope_value_as = { name = extra_reward value = flag:yes }
				}
				# Standard Reward.
				else = {
					save_scope_value_as = { name = extra_reward value = flag:no }
				}
				loaa_laamp_rewards_disburse_ordinary_currency_effect = {
					GOLD = scope:task_contract.var:gold_success_standard
					PRESTIGE = 0
					PIETY = 0
					PROVISIONS = task_contract_success_provisions_gain_minor_value
					OPINION = task_contract_opinion_standard_reward_value
					OPINION_TYPE = succeeded_task_contract_opinion
					CONTACT = yes
					CONTACT_HOOK = no
					EXTRA_REWARD = scope:extra_reward
				}
				task_contract_taker = {
					save_scope_as = task_contract_taker
					loaa_target_task_successful_noncrim_contract_count_effect = yes
					save_scope_as = adventurer
				}
				task_contract_employer = {
					trigger_event = loaa_contract_event.0020
					employer_contract_completed_info_effect = yes
				}
			}
		}
		success_critical = {
			should_print_on_complete = yes
			effect = {
				task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_success_on_contract" }
				# Camp building extra Stewardship Rewards: +50%.
				if = {
					limit = {
						task_contract_taker.domicile ?= { has_domicile_parameter = camp_improved_stewardship_contract_rewards }
					}
					save_scope_value_as = { name = extra_reward value = flag:yes }
				}
				# Critical Reward.
				else = {
					save_scope_value_as = { name = extra_reward value = flag:no }
				}
				loaa_laamp_rewards_disburse_ordinary_currency_effect = {
					GOLD = scope:task_contract.var:gold_success_critical
					PRESTIGE = task_contract_success_prestige_gain_half_value
					PIETY = 0
					PROVISIONS = task_contract_success_provisions_gain_medium_value
					OPINION = task_contract_opinion_excelled_reward_value
					OPINION_TYPE = critically_succeeded_task_contract_opinion
					CONTACT = yes
					CONTACT_HOOK = yes
					EXTRA_REWARD = scope:extra_reward
				}
				task_contract_taker = {
					save_scope_as = task_contract_taker
					loaa_target_task_successful_noncrim_contract_count_effect = yes
					save_scope_as = adventurer
				}
				task_contract_employer = {
					trigger_event = loaa_contract_event.0020
					employer_contract_completed_info_effect = yes
				}
			}
		}
		failure_standard = {
			positive = no
			should_print_on_complete = yes
			effect = {
				task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_failure_on_contract" }
				save_scope_value_as = { name = extra_reward value = flag:no }
				# Standard Penalties.
				loaa_laamp_rewards_disburse_ordinary_currency_effect = {
					GOLD = 0
					PRESTIGE = task_contract_failure_prestige_loss_full_value
					PIETY = 0
					PROVISIONS = task_contract_failure_provisions_gain_minor_value
					OPINION = task_contract_opinion_standard_failure_value
					OPINION_TYPE = failed_task_contract_opinion
					CONTACT = no
					CONTACT_HOOK = no
					EXTRA_REWARD = scope:extra_reward
				}
				task_contract_taker = {
					save_scope_as = adventurer
				}
				task_contract_target = {
					save_scope_as = contract_target
				}
				task_contract_employer = {
					employer_contract_failed_info_effect = yes
				}
			}
		}
		failure_critical = {
			positive = no
			effect = {
				task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_failure_on_contract" }
				save_scope_value_as = { name = extra_reward value = flag:no }
				# Standard Penalties.
				loaa_laamp_rewards_disburse_ordinary_currency_effect = {
					GOLD = 0
					PRESTIGE = -300
					PIETY = 0
					PROVISIONS = task_contract_failure_provisions_gain_minor_value
					OPINION = task_contract_opinion_critical_failure_value
					OPINION_TYPE = failed_task_contract_opinion
					CONTACT = no
					CONTACT_HOOK = no
					EXTRA_REWARD = scope:extra_reward
				}
				task_contract_taker = {
					save_scope_as = adventurer
				}
				task_contract_target = {
					save_scope_as = contract_target
				}
				task_contract_employer = {
					employer_contract_failed_info_effect = yes
				}
			}
		}
	}
}

# Murder someone
loaa_laamp_base_3011 = {
	group = laamp_contracts_criminal_group
	icon = "gfx/interface/icons/scheme_types/intrigue.dds"

	travel = yes
	is_criminal = yes
	use_diplomatic_range = no

	weight = {
		# Standard weights.
		value = task_contract_weight_default_value
		add = laamp_contracts_weight_up_intrigue_value
		add = laamp_contracts_weight_up_criminal_value
		# Employer weights.
		scope:employer = {
			add = {
				# Weight up.
				## Traits that want someone killed and don't much care how.
				if = {
					limit = { has_trait = wrathful }
					add = task_contract_weight_bonus_employer_has_associated_traits_value
				}
				if = {
					limit = { has_trait = callous }
					add = task_contract_weight_bonus_employer_has_associated_traits_value
				}
				if = {
					limit = { has_trait = sadistic }
					add = task_contract_weight_bonus_employer_has_associated_traits_value
				}
				if = {
					limit = { has_trait = arbitrary }
					add = task_contract_weight_bonus_employer_has_associated_traits_value
				}
				# Weight down.
				## Traits that won't hire thugs to solve their problems just on principle.
				if = {
					limit = { has_trait = calm }
					add = task_contract_weight_malus_employer_has_associated_traits_value
				}
				if = {
					limit = { has_trait = just }
					add = task_contract_weight_malus_employer_has_associated_traits_value
				}
				# Restrictions.
				min = task_contract_weight_employer_associated_traits_min_value
				max = task_contract_weight_employer_associated_traits_max_value
			}
			multiply = task_contract_weight_by_tier_value
			# This weight is an override, so make sure it's placed at the bottom.
			add = task_contract_weight_employer_contact_list_value
		}
	}

	# Validity Triggers
	valid_to_create = {
		always = no
	}
	valid_to_accept = {
		# Standard triggers.
		valid_laamp_basic_accept_only_trigger = yes
		loaa_valid_laamp_basic_trigger = {
			EMPLOYER = scope:employer
			LAAMP = root
		}
		NOT = {
			house = {
				has_house_modifier = legacy_adventurer_house_modifier
			}
		}
		scope:employer = { is_landed = yes }
	}
	valid_to_continue = {
		# Standard triggers.
		loaa_valid_laamp_basic_trigger = {
			EMPLOYER = root.task_contract_employer
			LAAMP = root.task_contract_taker
		}
		root.task_contract_taker = {
			NOT = {
				house = {
					has_house_modifier = legacy_adventurer_house_modifier
				}
			}
		}
		task_contract_employer = { is_landed = yes }
	}
	valid_to_keep = {
		# Standard triggers.
		loaa_valid_laamp_basic_trigger = {
			EMPLOYER = root.task_contract_employer
			LAAMP = root.task_contract_taker
		}
		task_contract_employer = { is_landed = yes }
	}

	# On_actions
	on_accepted = {
		task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_accept_contract" }
		# For the intro event.
		save_scope_as = task_contract
		set_variable = {
			name = contract_type
			value = flag:intrigue
		}
		# Now, nab us a suitable target.
		task_contract_taker = {
			save_scope_as = task_contract_taker
			save_scope_as = adventurer
		}
		task_contract_employer = {
			employer_contract_accepted_info_effect = yes
		}
		task_contract_target = {
			save_scope_as = task_contract_target
		}
		set_variable = {
			name = target
			value = scope:task_contract_target
		}
		# Then we start the scheme.
		task_contract_taker ?= {
			start_scheme = {
				type = loaa_laamp_base_3011_contract_scheme
				contract = root
				target_character = scope:task_contract_target
			}
			# Make a note of what the scheme even is; we'll need this for the event too.
			scope:task_contract.scheme = { save_scope_as = scheme }

			trigger_event = laamp_base_contract_schemes.3011
		}

	}
	on_create = {
		scope:contract = {
			set_variable = {
				name = animation
				value = 1
			}
			# Make our gold rewards static.
			grab_gold_fuzz_number_effect = yes
			save_scope_as = task_contract
			set_variable = {
				name = gold_success_standard
				value = task_contract_taker.loaa_task_contract_success_gold_gain_crime_value
			}
		}
	}


	on_invalidated = {
		if = {
			limit = {
				root.task_contract_taker = {
					any_character_active_contract = {
						this = root
					}
				}
			}
			save_scope_as = task_contract
			task_contract_employer = {
				save_scope_as = task_contract_employer
			}
			save_scope_value_as = {
				name = task_contract_tier
				value = root.task_contract_tier
			}
			var:task_contract_destination = {
				save_scope_as = task_contract_destination
			}
			var:task_contract_target = {
				save_scope_as = task_contract_target
			}
			task_contract_taker = {
				save_scope_as = task_contract_taker
				set_variable = {
					name = invalidated_task_contract_type
					value = flag:loaa_laamp_base_3011
				}
			}
			if = {
				limit = { scope:task_contract = { has_variable = task_contract_voluntary_invalidation } }
				scope:task_contract_employer = { loaa_contract_invalidation_penalty_effect = yes }
			}
			if = {
				limit = {
					task_contract_employer = {
						is_alive = no
					}
				}
				task_contract_employer.primary_title.holder ?= {
					save_scope_as = employer_heir
				}
				task_contract_taker = {
					save_scope_value_as = {
						name = task_contract_invalidation_reason
						value = flag:employer_dead
					}
					trigger_event = ep3_contract_event.0012

				}
			}
			else_if = {
				limit = {
					scope:task_contract_target = {
						is_alive = no
					}
				}
				task_contract_taker = {
					save_scope_value_as = {
						name = task_contract_invalidation_reason
						value = flag:target_dead
					}
					trigger_event = ep3_contract_event.0012
				}
			}
			scope:task_contract_employer = {
				hidden_effect = {
					remove_variable = offered_contract
					increment_variable_effect = {
						VAR = employed_adventurers_num
						VAL = -1
					}
					send_interface_toast = {
						type = event_contract_invalidated
						title = event_contract_invalidated_tt
						desc = event_contract_invalidated_desc
						custom_tooltip = { text = event_contract_invalidated_desc }
						left_icon = this
						right_icon = scope:task_contract_taker
					}
				}
			}
		}
	}

	# Rewards
	task_contract_reward = {
		success_standard = {
			should_print_on_complete = yes
			effect = {
				task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_success_on_contract" }
				save_scope_value_as = { name = extra_reward value = flag:no }
				# Standard Rewards.
				loaa_laamp_rewards_disburse_ordinary_currency_effect = {
					GOLD = scope:task_contract.var:gold_success_standard
					PRESTIGE = 0
					PIETY = 0
					PROVISIONS = task_contract_success_provisions_gain_minor_value
					OPINION = task_contract_opinion_standard_reward_value
					OPINION_TYPE = succeeded_task_contract_opinion
					CONTACT = yes
					CONTACT_HOOK = yes
					EXTRA_REWARD = scope:extra_reward
				}
				task_contract_taker = {
					save_scope_as = adventurer
				}
				# Update gallowsbait score.
				task_contract_taker = {
					laamp_rewards_apply_criminal_xp_effect = {
						TRACK = marauder
						XP_MAX = gallowsbait_xp_medium_gain
						XP_MIN = gallowsbait_xp_medium_gain
					}
					bandit_king_maa_spawn_effect = yes
				}
				task_contract_target = {
					save_scope_as = contract_target
				}
				task_contract_employer = {
					trigger_event = loaa_contract_event.0070
					employer_contract_completed_info_effect = yes
				}
			}
		}
		failure_standard = {
			positive = no
			should_print_on_complete = yes
			effect = {
				task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_failure_on_contract" }
				save_scope_value_as = { name = extra_reward value = flag:no }
				# Standard Penalties.
				loaa_laamp_rewards_disburse_ordinary_currency_effect = {
					GOLD = 0
					PRESTIGE = task_contract_failure_prestige_loss_crime_value
					PIETY = 0
					PROVISIONS = task_contract_failure_provisions_gain_minor_value
					OPINION = task_contract_opinion_standard_failure_value
					OPINION_TYPE = failed_task_contract_opinion
					CONTACT = no
					CONTACT_HOOK = no
					EXTRA_REWARD = scope:extra_reward
				}
				# Update gallowsbait score.
				task_contract_taker = {
					save_scope_as = adventurer
					laamp_rewards_apply_criminal_xp_effect = {
						TRACK = marauder
						XP_MAX = gallowsbait_xp_minor_gain
						XP_MIN = gallowsbait_xp_minor_gain
					}
					bandit_king_maa_spawn_effect = yes
				}
				task_contract_employer = {
					employer_contract_failed_info_effect = yes
				}
			}
		}
	}
}

# Abduct someone
loaa_laamp_base_3021 = {
	group = laamp_contracts_criminal_group
	icon = "gfx/interface/icons/scheme_types/intrigue.dds"

	travel = yes
	is_criminal = yes
	use_diplomatic_range = no

	weight = {
		# Standard weights.
		value = task_contract_weight_default_value
		add = laamp_contracts_weight_up_intrigue_value
		add = laamp_contracts_weight_up_criminal_value
		# Employer weights.
		scope:employer = {
			add = {
				# Weight up.
				## Traits that want someone killed and don't much care how.
				if = {
					limit = { has_trait = wrathful }
					add = task_contract_weight_bonus_employer_has_associated_traits_value
				}
				if = {
					limit = { has_trait = callous }
					add = task_contract_weight_bonus_employer_has_associated_traits_value
				}
				if = {
					limit = { has_trait = sadistic }
					add = task_contract_weight_bonus_employer_has_associated_traits_value
				}
				if = {
					limit = { has_trait = arbitrary }
					add = task_contract_weight_bonus_employer_has_associated_traits_value
				}
				# Weight down.
				## Traits that won't hire thugs to solve their problems just on principle.
				if = {
					limit = { has_trait = calm }
					add = task_contract_weight_malus_employer_has_associated_traits_value
				}
				if = {
					limit = { has_trait = just }
					add = task_contract_weight_malus_employer_has_associated_traits_value
				}
				# Restrictions.
				min = task_contract_weight_employer_associated_traits_min_value
				max = task_contract_weight_employer_associated_traits_max_value
			}
			multiply = task_contract_weight_by_tier_value
			# This weight is an override, so make sure it's placed at the bottom.
			add = task_contract_weight_employer_contact_list_value
		}
	}

	# Validity Triggers
	valid_to_create = {
		always = no
	}
	valid_to_accept = {
		# Standard triggers.
		valid_laamp_basic_accept_only_trigger = yes
		loaa_valid_laamp_basic_trigger = {
			EMPLOYER = scope:employer
			LAAMP = root
		}
		NOT = {
			house = {
				has_house_modifier = legacy_adventurer_house_modifier
			}
		}
		scope:employer = { is_landed = yes }
	}
	valid_to_continue = {
		# Standard triggers.
		loaa_valid_laamp_basic_trigger = {
			EMPLOYER = root.task_contract_employer
			LAAMP = root.task_contract_taker
		}
		root.task_contract_taker = {
			NOT = {
				house = {
					has_house_modifier = legacy_adventurer_house_modifier
				}
			}
		}
		task_contract_employer = { is_landed = yes }
	}
	valid_to_keep = {
		# Standard triggers.
		loaa_valid_laamp_basic_trigger = {
			EMPLOYER = root.task_contract_employer
			LAAMP = root.task_contract_taker
		}
		task_contract_employer = { is_landed = yes }
	}

	# On_actions
	on_accepted = {
		task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_accept_contract" }
		# For the intro event.
		save_scope_as = task_contract
		set_variable = {
			name = contract_type
			value = flag:intrigue
		}
		# Now, nab us a suitable target.
		#task_contract_employer = { laamp_contract_grab_suitable_rival_for_disposal_effect = yes }
		task_contract_taker = {
			save_scope_as = task_contract_taker
			save_scope_as = adventurer
		}
		task_contract_employer = {
			employer_contract_accepted_info_effect = yes
		}
		task_contract_target = {
			save_scope_as = task_contract_target
		}
		scope:task_contract = {
			set_variable = {
				name = target
				value = scope:task_contract_target
			}
		}
		# Then we start the scheme.
		task_contract_taker ?= {
			start_scheme = {
				type = loaa_laamp_base_3021_contract_scheme
				contract = root
				target_character = scope:task_contract_target
			}
			# Make a note of what the scheme even is; we'll need this for the event too.
			scope:task_contract.scheme = { save_scope_as = scheme }

			trigger_event = laamp_base_contract_schemes.3021
		}

	}
	on_create = {
		scope:contract = {
			set_variable = {
				name = animation
				value = 1
			}
			# Make our gold rewards static.
			grab_gold_fuzz_number_effect = yes
			save_scope_as = task_contract
			set_variable = {
				name = gold_success_standard
				value = task_contract_taker.loaa_task_contract_success_gold_gain_crime_value
			}
		}
	}


	on_invalidated = {
		if = {
			limit = {
				root.task_contract_taker = {
					any_character_active_contract = {
						this = root
					}
				}
			}
			save_scope_as = task_contract
			task_contract_employer = {
				save_scope_as = task_contract_employer
			}
			save_scope_value_as = {
				name = task_contract_tier
				value = root.task_contract_tier
			}
			var:task_contract_destination = {
				save_scope_as = task_contract_destination
			}
			var:task_contract_target = {
				save_scope_as = task_contract_target
			}
			task_contract_taker = {
				set_variable = {
					name = invalidated_task_contract_type
					value = flag:loaa_laamp_base_3021
				}
			}
			if = {
				limit = { scope:task_contract = { has_variable = task_contract_voluntary_invalidation } }
				scope:task_contract_employer = { loaa_contract_invalidation_penalty_effect = yes }
			}
			if = {
				limit = {
					task_contract_employer = {
						is_alive = no
					}
				}
				task_contract_employer.primary_title.holder ?= {
					save_scope_as = employer_heir
				}
				task_contract_taker = {
					save_scope_value_as = {
						name = task_contract_invalidation_reason
						value = flag:employer_dead
					}
					trigger_event = ep3_contract_event.0012

				}
			}
			else_if = {
				limit = {
					scope:task_contract_target = {
						is_alive = no
					}
				}
				task_contract_taker = {
					save_scope_value_as = {
						name = task_contract_invalidation_reason
						value = flag:target_dead
					}
					trigger_event = ep3_contract_event.0012
				}
			}
			scope:task_contract_employer = {
				hidden_effect = {
					remove_variable = offered_contract
					increment_variable_effect = {
						VAR = employed_adventurers_num
						VAL = -1
					}
					send_interface_toast = {
						type = event_contract_invalidated
						title = event_contract_invalidated_tt
						desc = event_contract_invalidated_desc
						custom_tooltip = { text = event_contract_invalidated_desc }
						left_icon = this
						right_icon = scope:task_contract_taker
					}
				}
			}
		}
	}

	# Rewards
	task_contract_reward = {
		success_standard = {
			should_print_on_complete = yes
			effect = {
				task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_success_on_contract" }
				save_scope_value_as = { name = extra_reward value = flag:no }
				# Standard Rewards.
				loaa_laamp_rewards_disburse_ordinary_currency_effect = {
					GOLD = scope:task_contract.var:gold_success_standard
					PRESTIGE = 0
					PIETY = 0
					PROVISIONS = task_contract_success_provisions_gain_minor_value
					OPINION = task_contract_opinion_standard_reward_value
					OPINION_TYPE = succeeded_task_contract_opinion
					CONTACT = yes
					CONTACT_HOOK = yes
					EXTRA_REWARD = scope:extra_reward
				}
				task_contract_taker = {
					save_scope_as = adventurer
				}
				# Update gallowsbait score.
				task_contract_taker = {
					laamp_rewards_apply_criminal_xp_effect = {
						TRACK = bandit
						XP_MAX = gallowsbait_xp_medium_gain
						XP_MIN = gallowsbait_xp_medium_gain
					}
					bandit_king_maa_spawn_effect = yes
				}
				task_contract_target = {
					save_scope_as = task_contract_target
				}
				task_contract_employer = {
					trigger_event = loaa_contract_event.0080
					employer_contract_completed_info_effect = yes
				}
			}
		}
		failure_standard = {
			positive = no
			should_print_on_complete = yes
			effect = {
				task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_failure_on_contract" }
				save_scope_value_as = { name = extra_reward value = flag:no }
				# Standard Penalties.
				loaa_laamp_rewards_disburse_ordinary_currency_effect = {
					GOLD = 0
					PRESTIGE = task_contract_failure_prestige_loss_crime_value
					PIETY = 0
					PROVISIONS = task_contract_failure_provisions_gain_minor_value
					OPINION = task_contract_opinion_standard_failure_value
					OPINION_TYPE = failed_task_contract_opinion
					CONTACT = no
					CONTACT_HOOK = no
					EXTRA_REWARD = scope:extra_reward
				}
				# Update gallowsbait score.
				task_contract_taker = {
					save_scope_as = adventurer
					laamp_rewards_apply_criminal_xp_effect = {
						TRACK = bandit
						XP_MAX = gallowsbait_xp_minor_gain
						XP_MIN = gallowsbait_xp_minor_gain
					}
					bandit_king_maa_spawn_effect = yes
				}
				task_contract_target = {
					save_scope_as = task_contract_target
				}
				task_contract_employer = {
					employer_contract_failed_info_effect = yes
				}
			}
		}
	}
}

# Sabotage
loaa_sabotage_contract = {
	group = laamp_contracts_criminal_group
	icon = "gfx/interface/icons/scheme_types/intrigue.dds"

	travel = yes
	is_criminal = yes
	use_diplomatic_range = no

	weight = {
		# Standard weights.
		value = task_contract_weight_default_value
		add = laamp_contracts_weight_up_intrigue_value
		add = laamp_contracts_weight_up_criminal_value
		# Employer weights.
		scope:employer = {
			add = {
				# Weight up.
				## Traits that want someone killed and don't much care how.
				if = {
					limit = { has_trait = wrathful }
					add = task_contract_weight_bonus_employer_has_associated_traits_value
				}
				if = {
					limit = { has_trait = callous }
					add = task_contract_weight_bonus_employer_has_associated_traits_value
				}
				if = {
					limit = { has_trait = sadistic }
					add = task_contract_weight_bonus_employer_has_associated_traits_value
				}
				if = {
					limit = { has_trait = arbitrary }
					add = task_contract_weight_bonus_employer_has_associated_traits_value
				}
				# Weight down.
				## Traits that won't hire thugs to solve their problems just on principle.
				if = {
					limit = { has_trait = calm }
					add = task_contract_weight_malus_employer_has_associated_traits_value
				}
				if = {
					limit = { has_trait = just }
					add = task_contract_weight_malus_employer_has_associated_traits_value
				}
				# Restrictions.
				min = task_contract_weight_employer_associated_traits_min_value
				max = task_contract_weight_employer_associated_traits_max_value
			}
			multiply = task_contract_weight_by_tier_value
			# This weight is an override, so make sure it's placed at the bottom.
			add = task_contract_weight_employer_contact_list_value
		}
	}

	# Validity Triggers
	valid_to_create = {
		always = no
	}
	valid_to_accept = {
		# Standard triggers.
		valid_laamp_basic_accept_only_trigger = yes
		loaa_valid_laamp_basic_trigger = {
			EMPLOYER = scope:employer
			LAAMP = root
		}
		NOT = {
			house = {
				has_house_modifier = legacy_adventurer_house_modifier
			}
		}
		scope:employer = { is_landed = yes }
	}
	valid_to_continue = {
		# Standard triggers.
		loaa_valid_laamp_basic_trigger = {
			EMPLOYER = root.task_contract_employer
			LAAMP = root.task_contract_taker
		}
		root.task_contract_taker = {
			NOT = {
				house = {
					has_house_modifier = legacy_adventurer_house_modifier
				}
			}
		}
		task_contract_employer = { is_landed = yes }
	}
	valid_to_keep = {
		# Standard triggers.
		loaa_valid_laamp_basic_trigger = {
			EMPLOYER = root.task_contract_employer
			LAAMP = root.task_contract_taker
		}
		task_contract_employer = { is_landed = yes }
	}

	# On_actions
	on_accepted = {
		task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_accept_contract" }
		# For the intro event.
		save_scope_as = task_contract
		set_variable = {
			name = contract_type
			value = flag:intrigue
		}
		task_contract_taker = {
			save_scope_as = task_contract_taker
			save_scope_as = adventurer
		}
		task_contract_target = {
			save_scope_as = task_contract_target
		}
		task_contract_employer = {
			save_scope_as = task_contract_employer
			employer_contract_accepted_info_effect = yes
			trigger_event = loaa_contract_event.0060
		}
		scope:task_contract = {
			set_variable = {
				name = target
				value = scope:task_contract_target
			}
		}
	}
	on_create = {
		scope:contract = {
			set_variable = {
				name = animation
				value = 1
			}
			# Make our gold rewards static.
			grab_gold_fuzz_number_effect = yes
			save_scope_as = task_contract
			task_contract_target = {
				save_scope_as = task_contract_target
			}
			set_variable = {
				name = task_contract_target
				value = scope:task_contract_target
			}
			set_variable = {
				name = gold_success_standard
				value = task_contract_taker.loaa_task_contract_success_gold_gain_crime_value
			}
		}
	}


	on_invalidated = {
		if = {
			limit = {
				root.task_contract_taker = {
					any_character_active_contract = {
						this = root
					}
				}
			}
			save_scope_as = task_contract
			task_contract_employer = {
				save_scope_as = task_contract_employer
			}
			task_contract_taker = {
				save_scope_as = task_contract_taker
			}
			save_scope_value_as = {
				name = task_contract_tier
				value = root.task_contract_tier
			}
			var:task_contract_destination = {
				save_scope_as = task_contract_destination
			}
			var:task_contract_target = {
				save_scope_as = task_contract_target
			}
			task_contract_taker = {
				set_variable = {
					name = invalidated_task_contract_type
					value = flag:loaa_sabotage_contract
				}
			}
			if = {
				limit = { scope:task_contract = { has_variable = task_contract_voluntary_invalidation } }
				scope:task_contract_employer = { loaa_contract_invalidation_penalty_effect = yes }
			}
			if = {
				limit = {
					task_contract_employer = {
						is_alive = no
					}
				}
				task_contract_employer.primary_title.holder ?= {
					save_scope_as = employer_heir
				}
				task_contract_taker = {
					save_scope_value_as = {
						name = task_contract_invalidation_reason
						value = flag:employer_dead
					}
					trigger_event = ep3_contract_event.0012

				}
			}
			else_if = {
				limit = {
					scope:task_contract_target = {
						is_alive = no
					}
				}
				task_contract_taker = {
					save_scope_value_as = {
						name = task_contract_invalidation_reason
						value = flag:target_dead
					}
					trigger_event = ep3_contract_event.0012
				}
			}
			scope:task_contract_employer = {
				hidden_effect = {
					remove_variable = offered_contract
					increment_variable_effect = {
						VAR = employed_adventurers_num
						VAL = -1
					}
					send_interface_toast = {
						type = event_contract_invalidated
						title = event_contract_invalidated_tt
						desc = event_contract_invalidated_desc
						custom_tooltip = { text = event_contract_invalidated_desc }
						left_icon = this
						right_icon = scope:task_contract_taker
					}
				}
			}
			scope:task_contract_taker = {
				current_travel_plan ?= { resume_travel_plan = yes }
			}
		}
	}

	# Rewards
	task_contract_reward = {
		success_standard = {
			should_print_on_complete = yes
			effect = {
				task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_success_on_contract" }
				save_scope_value_as = { name = extra_reward value = flag:no }
				# Standard Rewards.
				loaa_laamp_rewards_disburse_ordinary_currency_effect = {
					GOLD = scope:task_contract.var:gold_success_standard
					PRESTIGE = 0
					PIETY = 0
					PROVISIONS = task_contract_success_provisions_gain_minor_value
					OPINION = task_contract_opinion_standard_reward_value
					OPINION_TYPE = succeeded_task_contract_opinion
					CONTACT = yes
					CONTACT_HOOK = yes
					EXTRA_REWARD = scope:extra_reward
				}
				task_contract_taker = {
					save_scope_as = adventurer
				}
				# Update gallowsbait score.
				task_contract_taker = {
					laamp_rewards_apply_criminal_xp_effect = {
						TRACK = bandit
						XP_MAX = gallowsbait_xp_medium_gain
						XP_MIN = gallowsbait_xp_medium_gain
					}
					bandit_king_maa_spawn_effect = yes
				}
				task_contract_target = {
					save_scope_as = contract_target
				}
				task_contract_employer = {
					employer_contract_completed_info_effect = yes
				}
			}
		}
		failure_standard = {
			positive = no
			should_print_on_complete = yes
			effect = {
				task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_failure_on_contract" }
				save_scope_value_as = { name = extra_reward value = flag:no }
				# Standard Penalties.
				loaa_laamp_rewards_disburse_ordinary_currency_effect = {
					GOLD = 0
					PRESTIGE = task_contract_failure_prestige_loss_crime_value
					PIETY = 0
					PROVISIONS = task_contract_failure_provisions_gain_minor_value
					OPINION = task_contract_opinion_standard_failure_value
					OPINION_TYPE = failed_task_contract_opinion
					CONTACT = no
					CONTACT_HOOK = no
					EXTRA_REWARD = scope:extra_reward
				}
				# Update gallowsbait score.
				task_contract_taker = {
					save_scope_as = adventurer
					laamp_rewards_apply_criminal_xp_effect = {
						TRACK = bandit
						XP_MAX = gallowsbait_xp_minor_gain
						XP_MIN = gallowsbait_xp_minor_gain
					}
					bandit_king_maa_spawn_effect = yes
				}
				task_contract_target = {
					save_scope_as = contract_target
				}
				task_contract_employer = {
					employer_contract_failed_info_effect = yes
				}
			}
		}
	}
}

# Deliver Artifact
loaa_deliver_artifact_contract = {
	group = laamp_contracts_transport_group
	icon = "gfx/interface/icons/character_interactions/icon_contract_escort.dds"
	travel = no
	use_diplomatic_range = no

	# Validity Triggers
	valid_to_create = {
		always = no
	}
	valid_to_keep = {
		exists = root.var:escorted_artifact
	}
	valid_to_accept = {
		# Standard triggers.
		valid_laamp_basic_accept_only_trigger = yes
		loaa_valid_laamp_basic_trigger = {
			EMPLOYER = scope:employer
			LAAMP = root
		}
	}
	valid_to_continue = {
		var:escorted_artifact ?= {
			artifact_owner = {
				OR = {
					root.task_contract_taker = this
					root.task_contract_target = this
				}
			}
		}
		var:task_contract_target ?= {
			is_alive = yes
		}
	}

	weight = {
		# Standard weights.
		value = task_contract_weight_interesting_quite_rare_value
		add = laamp_contracts_weight_up_transport_value
		add = task_contract_weight_employer_contact_list_value
		scope:employer = { multiply = task_contract_weight_by_tier_value }
	}
	# On_Actions
	on_create = {
		scope:contract = {
			save_scope_as = task_contract
			set_variable = {
				name = task_contract_employer
				value = scope:task_contract.task_contract_employer
			}
			if = {
				limit = {
					exists = scope:task_contract.task_contract_target
				}
				set_variable = {
					name = task_contract_target
					value = scope:task_contract.task_contract_target
				}
			}
			else = {
				set_variable = {
					name = task_contract_target
					value = scope:task_contract_target
				}
				set_task_contract_target = scope:task_contract_target
			}
			task_contract_target = {
				capital_province = {
					save_scope_as = task_contract_destination
				}
			}
			set_variable = {
				name = task_contract_destination
				value = scope:task_contract_destination
			}
			task_contract_employer = {
				random_character_artifact = {
					save_scope_as = escorted_artifact
				}
			}
			set_variable = {
				name = escorted_artifact
				value = scope:escorted_artifact
			}
			# Make our gold rewards static.
			grab_gold_fuzz_number_effect = yes
			set_variable = {
				name = gold_success_critical
				value = task_contract_success_gold_gain_travel_value
			}
			set_variable = {
				name = gold_success_standard
				value = task_contract_success_gold_gain_travel_value
			}
		}
	}

	on_accepted = {
		task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_accept_contract" }
		save_scope_as = task_contract
		set_variable = {
			name = contract_type
			value = flag:transport
		}
		if = {
			limit = {
				OR = {
					var:contract_type = flag:transport
					var:contract_type = flag:conduct_census
				}
			}
		}
		task_contract_taker = {
			save_scope_as = adventurer
		}
		task_contract_target = {
			save_scope_as = task_contract_target
		}
		task_contract_employer = {
			employer_contract_accepted_info_effect = yes
			trigger_event = loaa_contract_event.0040
		}
	}

	on_invalidated = {
		if = {
			limit = {
				root.task_contract_taker = {
					any_character_active_contract = {
						this = root
					}
				}
			}
			save_scope_as = task_contract
			task_contract_taker = {
				save_scope_as = task_contract_taker
			}
			task_contract_employer = {
				save_scope_as = task_contract_employer
			}
			save_scope_value_as = {
				name = task_contract_tier
				value = root.task_contract_tier
			}
			task_contract_target = {
				save_scope_as = task_contract_target
			}
			var:task_contract_destination = {
				save_scope_as = task_contract_destination
			}
			var:escorted_artifact ?= {
				save_scope_as = escorted_artifact
			}

			if = {
				limit = { scope:task_contract = { has_variable = task_contract_voluntary_invalidation } }
				scope:task_contract_employer = { loaa_contract_invalidation_penalty_effect = yes }
			}

			if = {
				limit = {
					var:task_contract_object ?= {
						is_alive = yes
					}
				}
				var:task_contract_object = {
					return_to_court = yes
				}
			}
			task_contract_taker = {
				set_variable = {
					name = invalidated_task_contract_type
					value = flag:laamp_transport_artifact
				}
			}
			if = {
				limit = {
					var:task_contract_object ?= {
						is_alive = no
					}
				}
				task_contract_taker = {
					save_scope_value_as = {
						name = task_contract_invalidation_reason
						value = flag:escortee_dead
					}
					trigger_event = ep3_contract_event.0012
				}
			}
			else_if = {
				limit = {
					task_contract_employer = {
						is_alive = no
					}
				}
				task_contract_employer.primary_title.holder ?= {
					save_scope_as = employer_heir
				}
				task_contract_taker = {
					save_scope_value_as = {
						name = task_contract_invalidation_reason
						value = flag:employer_dead
					}
					trigger_event = ep3_contract_event.0012

				}
			}
			else_if = {
				limit = {
					var:task_contract_target = {
						is_alive = no
					}
				}
				var:task_contract_target ?= {
					save_scope_as = dead_target
				}
				task_contract_employer = {
					save_scope_as = task_contract_employer
				}
				task_contract_taker = {
					save_scope_value_as = {
						name = task_contract_invalidation_reason
						value = flag:target_dead
					}
					trigger_event = ep3_contract_event.0012
				}
			}
			if = {
				limit = {
					scope:escorted_artifact ?= {
						artifact_owner = scope:task_contract_taker
					}
				}
				scope:escorted_artifact = {
					set_owner = root.task_contract_employer
				}
			}
			scope:task_contract_employer = {
				hidden_effect = {
					remove_variable = offered_contract
					increment_variable_effect = {
						VAR = employed_adventurers_num
						VAL = -1
					}
					send_interface_toast = {
						type = event_contract_invalidated
						title = event_contract_invalidated_tt
						desc = event_contract_invalidated_desc
						custom_tooltip = { text = event_contract_invalidated_desc }
						left_icon = this
						right_icon = scope:task_contract_taker
					}
				}
			}
		}
	}

	# Rewards
	task_contract_reward = {
		success_critical = {
			effect = {
				task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_success_on_contract" }
				save_scope_value_as = { name = extra_reward value = flag:no }
				loaa_laamp_rewards_disburse_ordinary_currency_effect = {
					GOLD = scope:task_contract.var:gold_success_critical
					PRESTIGE = task_contract_success_prestige_gain_full_value
					PIETY = 0
					PROVISIONS = 0
					OPINION = task_contract_opinion_excelled_reward_value
					OPINION_TYPE = critically_succeeded_task_contract_opinion
					CONTACT = yes
					CONTACT_HOOK = yes
					EXTRA_REWARD = scope:extra_reward
				}
				task_contract_taker = {
					save_scope_as = task_contract_taker
					loaa_target_task_successful_noncrim_contract_count_effect = yes
					save_scope_as = adventurer
				}
				task_contract_employer = {
					employer_contract_completed_info_effect = yes
				}
			}
		}
		success_standard = {
			effect = {
				task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_success_on_contract" }
				save_scope_value_as = { name = extra_reward value = flag:no }
				loaa_laamp_rewards_disburse_ordinary_currency_effect = {
					GOLD = scope:task_contract.var:gold_success_standard
					PRESTIGE = task_contract_success_prestige_gain_full_value
					PIETY = 0
					PROVISIONS = 0
					OPINION = task_contract_opinion_standard_reward_value
					OPINION_TYPE = succeeded_task_contract_opinion
					CONTACT = yes
					CONTACT_HOOK = yes
					EXTRA_REWARD = scope:extra_reward
				}
				task_contract_taker = {
					save_scope_as = task_contract_taker
					loaa_target_task_successful_noncrim_contract_count_effect = yes
					save_scope_as = adventurer
				}
				task_contract_employer = {
					employer_contract_completed_info_effect = yes
				}

			}
		}
		transport_destroyed = {
			positive = no
			visible = no
			effect = {
				task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_failure_on_contract" }
				save_scope_as = task_contract
				task_contract_taker = {
					send_interface_toast = {
						type = event_toast_effect_bad
						title = laamp_transport_contract.transport_failed
						left_icon = root.task_contract_taker
						right_icon = root.task_contract_employer
						add_prestige = task_contract_failure_prestige_loss_full_value
						reverse_add_opinion = {
							modifier = failed_task_contract_opinion
							target = root.task_contract_employer
							opinion = -50
						}
					}
				}
			}
		}
		transport_stolen = {
			positive = no
			visible = no
			effect = {
				task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_failure_on_contract" }
				save_scope_as = task_contract
				task_contract_taker = {
					send_interface_toast = {
						type = event_toast_effect_bad
						title = laamp_transport_contract.transport_failed
						left_icon = root.task_contract_taker
						right_icon = root.task_contract_employer
						add_prestige = task_contract_failure_prestige_loss_full_value
						reverse_add_opinion = {
							modifier = failed_task_contract_opinion
							target = root.task_contract_employer
							opinion = -50
						}
					}
				}
			}
		}
		failure_standard = {
			positive = no
			effect = {
				task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_failure_on_contract" }
				save_scope_value_as = { name = extra_reward value = flag:no }
				loaa_laamp_rewards_disburse_ordinary_currency_effect = {
					GOLD = 0
					PRESTIGE = task_contract_failure_prestige_loss_full_value
					PIETY = 0
					PROVISIONS = task_contract_failure_provisions_gain_minor_value
					OPINION = task_contract_opinion_standard_failure_value
					OPINION_TYPE = failed_task_contract_opinion
					CONTACT = no
					CONTACT_HOOK = no
					EXTRA_REWARD = scope:extra_reward
				}
			}
		}
	}
}

# Support Faction
loaa_laamp_join_faction_contract = {
	group = laamp_contracts_war_group
	icon = "gfx/interface/icons/character_interactions/faction.dds"
	travel = no
	use_diplomatic_range = no

	# Validity Triggers
	valid_to_create = {
		always = no
	}
	valid_to_keep = {
		exists = root.var:task_contract_faction
		# Standard triggers.
		OR = {
			valid_laamp_basic_trigger = {
				EMPLOYER = root.task_contract_employer
				LAAMP = root.task_contract_taker
			}
			loaa_valid_laamp_basic_trigger = {
				EMPLOYER = root.task_contract_employer
				LAAMP = root.task_contract_taker
			}
		}
	}
	valid_to_accept = {
		# Standard triggers.
		valid_laamp_basic_accept_only_trigger = yes
		valid_laamp_basic_trigger = {
			EMPLOYER = scope:employer
			LAAMP = root
		}
		custom_tooltip = {
			text = NOT_FACTION_JOIN_CREATE_CONDITION_NOT_FACTION_MEMBER
			is_a_faction_member = no
		}
		#passes_faction_hard_block from 00_rules.txt
		scope:employer ?= {
			joined_faction ?= {
				faction_target ?= {
					save_temporary_scope_as = target
				}
			}
		}
		custom_description = {
			text = "FACTION_CANT_JOIN_CREATE_ADULT"
			is_adult = yes
		}
		custom_description = {
			text = "FACTION_CANT_JOIN_CREATE_ALLIED"
			trigger_if = {
				limit = { exists = scope:target }
				NOT = { is_allied_to = scope:target }
			}
		}
		custom_description = {
			text = "FACTION_CANT_JOIN_CREATE_HOOK"
			trigger_if = {
				limit = { exists = scope:target }
				scope:target = {
					NOT = { has_strong_hook = root }
				}
			}
		}
		custom_description = {
			text = "FACTION_CANT_JOIN_CREATE_IMPRISONED"
			trigger_if = {
				limit = {
					exists = joined_faction
					joined_faction = {
						faction_is_at_war = yes
					}
				}
			}
			trigger_else = {
				is_imprisoned = no
			}
		}
		custom_description = {
			text = "FACTION_CANT_JOIN_CREATE_INCAPABLE"
			NOT = { has_trait = incapable }
		}
		custom_description = {
			text = "character_blocked_from_joining"
			NOT = { has_character_flag = joining_faction_block }
		}
		custom_description = {
			text = "faction_relation_blocks_joining_friend"
			trigger_if = {
				limit = { exists = scope:target }
				NOT = {
					root = { has_relation_friend = scope:target }
				}
			}
		}
		custom_description = {
			text = "faction_relation_blocks_joining_lover"
			trigger_if = {
				limit = { exists = scope:target }
				NOR = {
					root = { has_relation_lover = scope:target }
					root = { has_secret_relation_lover = scope:target }
				}
			}
		}
	}
	valid_to_continue = {
		exists = root.var:task_contract_faction
		var:task_contract_faction = {
			any_faction_member = {
				this = root.task_contract_taker
			}
		}
		# Standard triggers.
		OR = {
			valid_laamp_basic_trigger = {
				EMPLOYER = root.task_contract_employer
				LAAMP = root.task_contract_taker
			}
			loaa_valid_laamp_basic_trigger = {
				EMPLOYER = root.task_contract_employer
				LAAMP = root.task_contract_taker
			}
		}

	}

	weight = {
		# Standard weights.
		value = task_contract_weight_interesting_almost_rare_value
		add = laamp_contracts_weight_up_mercenary_value
		add = laamp_contracts_weight_up_martial_slight_value
		add = task_contract_weight_employer_contact_list_value
		scope:employer = { multiply = task_contract_weight_by_tier_value }
	}

	on_create = {
		scope:contract = {
			save_scope_as = task_contract
			task_contract_employer = {
				save_scope_as = task_contract_employer
			}
			task_contract_target = {
				random_targeting_faction = {
					save_scope_as = task_contract_faction
				}
				#save_scope_as = faction_member
			}
			task_contract_target = {
				save_scope_as = task_contract_target
			}
			set_variable = {
				name = task_contract_faction
				value = scope:task_contract_faction
			}
			set_variable = {
				name = task_contract_employer
				value = scope:task_contract_employer
			}
			set_variable = {
				name = task_contract_target
				value = scope:task_contract_target
			}
		}
	}

	# On_Actions
	on_accepted = {
		task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_accept_contract" }
		save_scope_as = task_contract
		set_variable = {
			name = contract_type
			value = flag:war
		}
		task_contract_taker = { save_scope_as = adventurer }
		task_contract_employer = {
			trigger_event = loaa_contract_event.0030
			employer_contract_accepted_info_effect = yes
		}
	}

	on_invalidated = {
		if = {
			limit = {
				root.task_contract_taker = {
					any_character_active_contract = {
						this = root
					}
				}
			}
			save_scope_as = task_contract
			task_contract_employer = {
				save_scope_as = task_contract_employer
			}
			task_contract_taker = {
				save_scope_as = task_contract_taker
			}
			scope:task_contract_employer = {
				hidden_effect = {
					remove_variable = offered_contract
					increment_variable_effect = {
						VAR = employed_adventurers_num
						VAL = -1
					}
					send_interface_toast = {
						type = event_contract_invalidated
						title = event_contract_invalidated_tt
						desc = event_contract_invalidated_desc
						custom_tooltip = { text = event_contract_invalidated_desc }
						left_icon = this
						right_icon = scope:task_contract_taker
					}
				}
			}
			save_scope_value_as = {
				name = task_contract_tier
				value = root.task_contract_tier
			}
			var:task_contract_target = {
				save_scope_as = task_contract_target
			}
			task_contract_taker = {
				set_variable = {
					name = invalidated_task_contract_type
					value = flag:laamp_join_faction_contract
				}
			}
			if = {
				limit = { scope:task_contract = { has_variable = task_contract_voluntary_invalidation } }
				scope:task_contract_employer = { loaa_contract_invalidation_penalty_effect = yes }
			}

			if = {
				limit = {
					task_contract_employer = {
						is_alive = no
					}
				}
				task_contract_employer.primary_title.holder ?= {
					save_scope_as = employer_heir
				}
				task_contract_taker = {
					save_scope_value_as = {
						name = task_contract_invalidation_reason
						value = flag:employer_dead
					}
					trigger_event = ep3_contract_event.0012

				}
			}
			else_if = {
				limit = {
					scope:task_contract_target = {
						is_alive = no
					}
				}
				task_contract_taker = {
					save_scope_value_as = {
						name = task_contract_invalidation_reason
						value = flag:target_dead
					}
					trigger_event = ep3_contract_event.0012
				}
			}
			else_if = {
				limit = {
					NOT = {	exists = scope:task_contract_faction }
					NOT = { exists = var:suppress_invalidation_event }
				}
				task_contract_taker = {
					save_scope_value_as = {
						name = task_contract_invalidation_reason
						value = flag:faction_disbanded
					}
					trigger_event = ep3_contract_event.0012
				}
			}
		}
		task_contract_taker = {
			remove_variable = task_contract_faction
		}

	}

	task_contract_reward = {
		success_standard = {
			effect = {
				task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_success_on_contract" }
				save_scope_as = task_contract
				var:task_contract_faction = {
					save_scope_as = faction
				}
				task_contract_employer = {
					save_scope_as = task_contract_employer
					save_scope_as = attacker
				}
				task_contract_taker = {
					save_scope_as = adventurer
					save_scope_as = task_contract_taker
					save_scope_as = defender
					custom_tooltip = laamp_join_war_contract.contribution_based_reward_gold
					if = {
						limit = {
							faith != scope:task_contract.var:task_contract_target.faith
						}
						custom_tooltip = laamp_join_war_contract.contribution_based_reward_piety
					}
					save_scope_value_as = {
						name = task_contract_reward
						value = flag:success_standard
					}
					save_scope_value_as = {
						name = task_contract_tier
						value = scope:task_contract.task_contract_tier
					}
					war_contracts_completed_tracker_effect = yes
					send_interface_toast = {
						title = laamp_transport_contract.success
						left_icon = scope:task_contract.task_contract_taker
						right_icon = scope:task_contract.task_contract_employer
						# Huck 'em into our contact list.
						add_contact = scope:task_contract.task_contract_employer
						# Give hook as well as contact
						add_hook_if_possible_default_length_effect = {
							TARGET = scope:task_contract.task_contract_employer
							TYPE = contact_list_weak_hook
						}
						# if = {
						# 	limit = {
						# 		exists = scope:task_contract.var:task_contract_title
						# 	}
						# 	scope:attacker = {
						# 		save_scope_as = actor
						# 	}
						# 	save_scope_as = recipient
						# 	scope:task_contract.var:task_contract_title = {
						# 		add_to_list = offered_titles
						# 	}
						# 	negotiate_settlement_interaction_effect = yes
						# }
					}
				}
				task_contract_employer = {
					employer_contract_completed_info_effect = yes
				}
			}
		}
		failure_standard = {
			positive = no
			effect = {
				task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_failure_on_contract" }
				save_scope_as = task_contract
				var:task_contract_faction = {
					save_scope_as = faction
				}
				task_contract_employer = {
					save_scope_as = task_contract_employer
				}
				task_contract_taker = {
					save_scope_as = adventurer
					save_scope_value_as = {
						name = task_contract_reward
						value = flag:failure_standard
					}
					save_scope_value_as = {
						name = task_contract_tier
						value = scope:task_contract.task_contract_tier
					}
					send_interface_toast = {
						title = laamp_transport_contract.transport_failed
						left_icon = scope:task_contract.task_contract_taker
						right_icon = scope:task_contract.task_contract_employer
						add_prestige = task_contract_failure_prestige_loss_full_value
					}
				}
				task_contract_employer = {
					employer_contract_failed_info_effect = yes
				}
			}
		}
	}
}

## Criminal Contracts

# Heist from a ruler's treasury (player as "employer")
loaa_laamp_base_3041 = {
	group = laamp_contracts_criminal_group
	icon = "gfx/interface/icons/scheme_types/intrigue.dds"

	travel = yes
	is_criminal = yes
	use_diplomatic_range = no

	weight = {
		# Standard weights.
		value = task_contract_weight_default_value
		add = laamp_contracts_weight_up_intrigue_value
		add = laamp_contracts_weight_up_criminal_value
		# Employer weights.
		scope:employer = {
			add = laamp_contract_would_signpost_own_prosperity_value
			multiply = task_contract_weight_by_tier_value
		}
	}

	# Validity Triggers
	valid_to_create = {
		always = no
	}
	valid_to_accept = {
		# Standard triggers.
		valid_laamp_basic_accept_only_trigger = yes
		loaa_valid_laamp_basic_trigger = {
			EMPLOYER = scope:employer
			LAAMP = root
		}
		NOT = {
			house = {
				has_house_modifier = legacy_adventurer_house_modifier
			}
		}
		scope:employer = { is_landed = yes }
	}
	valid_to_continue = {
		# Standard triggers.
		loaa_valid_laamp_basic_trigger = {
			EMPLOYER = root.task_contract_employer
			LAAMP = root.task_contract_taker
		}
		root.task_contract_taker = {
			NOT = {
				house = {
					has_house_modifier = legacy_adventurer_house_modifier
				}
			}
		}
		task_contract_employer = { is_landed = yes }
	}
	valid_to_keep = {
		# Standard triggers.
		loaa_valid_laamp_basic_trigger = {
			EMPLOYER = root.task_contract_employer
			LAAMP = root.task_contract_taker
		}
		task_contract_employer = { is_landed = yes }
	}

	# On_actions
	on_accepted = {
		task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_accept_contract" }
		# For the intro event.
		save_scope_as = task_contract
		# Then we start the scheme.
		task_contract_taker ?= {
			start_scheme = {
				type = loaa_laamp_base_3041_contract_scheme
				contract = root
				target_character = root.task_contract_employer
			}
			# Make a note of what the scheme even is; we'll need this for the event too.
			scope:task_contract.scheme = { save_scope_as = scheme }
			trigger_event = loaa_laamp_base_contract_schemes.3041
		}
		task_contract_employer = {
			root = { set_variable = { name = employer value = prev } }
			add_character_flag = targeted_by_hostile_contract_heist
		}
	}
	on_create = {
		scope:contract = {
			set_variable = {
				name = animation
				value = 0
			}
			# Make our gold rewards static.
			grab_gold_fuzz_number_effect = yes
			save_scope_as = task_contract
			set_variable = {
				name = gold_success_standard
				value = task_contract_taker.task_contract_success_gold_gain_crime_value
			}
		}
	}

	on_invalidated = {
		if = {
			limit = {
				root.task_contract_taker = {
					any_character_active_contract = {
						this = root
					}
				}
			}
			save_scope_as = task_contract
			task_contract_employer = {
				remove_character_flag = targeted_by_hostile_contract_heist
			}
		}
	}

	# Rewards
	task_contract_reward = {
		success_standard = {
			should_print_on_complete = yes
			effect = {
				task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_success_on_contract" }
				save_scope_value_as = { name = extra_reward value = flag:no }
				save_scope_as = task_contract
				# Standard Rewards.
				loaa_laamp_rewards_disburse_ordinary_currency_effect = {
					GOLD = scope:task_contract.var:gold_success_standard
					PRESTIGE = 0
					PIETY = 0
					PROVISIONS = 0
					OPINION = task_contract_opinion_crime_success_value
					OPINION_TYPE = succeeded_criminal_contract_against_me_opinion
					CONTACT = no
					CONTACT_HOOK = no
					EXTRA_REWARD = scope:extra_reward
				}
				# Update gallowsbait score.
				task_contract_taker = {
					save_scope_as = adventurer
					laamp_rewards_apply_criminal_xp_effect = {
						TRACK = thief
						XP_MIN = gallowsbait_xp_medium_gain
						XP_MAX = gallowsbait_xp_medium_gain
					}
					bandit_king_maa_spawn_effect = yes
					trigger_event = loaa_contract_event.0100
				}
				task_contract_taker = {
					set_variable = {
						name = heist_contract_gold
						value = scope:gold
					}
					trigger_event = {
						id = loaa_contract_event.3043
						days = 5
					}
				}
				task_contract_employer = {
					remove_character_flag = targeted_by_hostile_contract_heist
				}
				custom_tooltip = laamp_base_3041.tt.chance_for_more
			}
		}
		failure_standard = {
			positive = no
			should_print_on_complete = yes
			effect = {
				task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_failure_on_contract" }
				save_scope_value_as = { name = extra_reward value = flag:no }
				task_contract_employer = {
					remove_character_flag = targeted_by_hostile_contract_heist
				}
				# Standard Penalties.
				loaa_laamp_rewards_disburse_ordinary_currency_effect = {
					GOLD = 0
					PRESTIGE = task_contract_failure_prestige_loss_crime_value
					PIETY = 0
					PROVISIONS = 0
					OPINION = task_contract_opinion_crime_failure_value
					OPINION_TYPE = attempted_criminal_contract_against_me_opinion
					CONTACT = no
					CONTACT_HOOK = no
					EXTRA_REWARD = scope:extra_reward
				}
				# Update gallowsbait score.
				task_contract_taker = {
					laamp_rewards_apply_criminal_xp_effect = {
						TRACK = thief
						XP_MIN = gallowsbait_xp_minor_gain
						XP_MAX = gallowsbait_xp_minor_gain
					}
					save_scope_as = task_contract_taker
				}
				task_contract_employer = {
					trigger_event = loaa_contract_event.3042
				}
			}
		}
	}
}

# Ambush travellers (player as "employer")
loaa_laamp_base_1041 = {
	group = laamp_contracts_criminal_group
	icon = "gfx/interface/icons/scheme_types/war.dds"

	is_criminal = yes
	use_diplomatic_range = no

	weight = {
		# Standard weights.
		value = task_contract_weight_default_value
		add = laamp_contracts_weight_up_martial_value
		add = laamp_contracts_weight_up_martial_slight_value
		add = laamp_contracts_weight_up_criminal_value
		# Employer weights.
		scope:employer = {
			add = {
				# Weight up.
				## Traits that don't mind telegraphing weakness.
				if = {
					limit = { has_trait = trusting }
					add = task_contract_weight_bonus_employer_has_associated_traits_value
				}
				if = {
					limit = { has_trait = honest }
					add = task_contract_weight_bonus_employer_has_associated_traits_value
				}
				# Weight down.
				## Traits that wouldn't just admit something was wrong.
				if = {
					limit = { has_trait = deceitful }
					add = task_contract_weight_malus_employer_has_associated_traits_value
				}
				if = {
					limit = { has_trait = arrogant }
					add = task_contract_weight_malus_employer_has_associated_traits_value
				}
				# Restrictions.
				min = task_contract_weight_employer_associated_traits_min_value
				max = task_contract_weight_employer_associated_traits_max_value
			}
			multiply = task_contract_weight_by_tier_value
		}
	}

	# Validity Triggers
	valid_to_create = {
		always = no
	}
	valid_to_accept = {
		# Standard triggers.
		valid_laamp_basic_accept_only_trigger = yes
		loaa_valid_laamp_basic_trigger = {
			EMPLOYER = scope:employer
			LAAMP = root
		}
		NOT = {
			house = {
				has_house_modifier = legacy_adventurer_house_modifier
			}
		}
		scope:employer = { is_landed = yes }
	}
	valid_to_continue = {
		# Standard triggers.
		loaa_valid_laamp_basic_trigger = {
			EMPLOYER = root.task_contract_employer
			LAAMP = root.task_contract_taker
		}
		root.task_contract_taker = {
			NOT = {
				house = {
					has_house_modifier = legacy_adventurer_house_modifier
				}
			}
		}
		task_contract_employer = { is_landed = yes }
	}
	valid_to_keep = {
		# Standard triggers.
		loaa_valid_laamp_basic_trigger = {
			EMPLOYER = root.task_contract_employer
			LAAMP = root.task_contract_taker
		}
		task_contract_employer = { is_landed = yes }
	}

	# On_actions
	on_accepted = {
		task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_accept_contract" }
		# For the intro event.
		save_scope_as = task_contract
		task_contract_taker = { save_scope_as = adventurer }
		task_contract_employer = { save_scope_as = employer }
		task_contract_employer = {
			add_character_flag = targeted_by_hostile_contract_ambush
		}
		scope:employer ?= {
			ordered_realm_county = {
				#order_by = loaa_ambush_county_value
				order_by = {
					title_province = { add = "squared_distance(scope:adventurer.location)" }
					multiply = -1
					if = {
						limit = {
							OR = {
								has_county_modifier = laamp_base_1041_success_employer_modifier
								has_county_modifier = laamp_base_1041_failure_employer_modifier
							}
						}
						multiply = 100
					}
					if = {
						limit = {
							NOT = { holder = scope:task_contract.task_contract_employer }
						}
						multiply = 100
					}
				}
				save_scope_as = crime_location
			}
		}
		if = {
			limit = { NOT = { exists = scope:crime_location } }
			scope:employer.capital_county = { save_scope_as = crime_location }
		}
		set_variable = {
			name = crime_location
			value = scope:crime_location
		}
		# Then we start the travel.
		task_contract_taker ?= { trigger_event = loaa_laamp_base_contract_schemes.1044 }
		# Plus, set up some variables for us.
		## Encounters list.
		increment_variable_effect = {
			VAR = encounters_tally
			VAL = 0
		}
		increment_variable_effect = {
			VAR = encounters_max
			VAL = 0
		}
		## Our actual haul.
		increment_variable_effect = {
			VAR = haul_actual
			VAL = 0
		}
		## Path length + length:event ratio — we'll use these to determine how quickly we should get the events.
		increment_variable_effect = {
			VAR = path_length
			VAL = 0
		}
		increment_variable_effect = {
			VAR = event_ratio
			VAL = 0
		}
		increment_variable_effect = {
			VAR = event_ratio_tracker
			VAL = 0
		}
	}
	on_create = {
		scope:contract = {
			set_variable = {
				name = animation
				value = 0
			}
		}
	}

	on_invalidated = {
		if = {
			limit = {
				root.task_contract_taker = {
					any_character_active_contract = {
						this = root
					}
				}
			}
			save_scope_as = task_contract
			task_contract_employer = {
				remove_variable = offered_contract
				remove_character_flag = targeted_by_hostile_contract_ambush
			}
		}
	}

	# Rewards
	task_contract_reward = {
		success_standard = {
			should_print_on_complete = yes
			effect = {
				task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_success_on_contract" }
				save_scope_as = task_contract
				task_contract_employer = {
					remove_character_flag = targeted_by_hostile_contract_ambush
					save_scope_as = employer
				}
				# Camp building extra Criminal Rewards: +50%.
				if = {
					limit = {
						task_contract_taker.domicile ?= { has_domicile_parameter = camp_improved_criminal_contract_rewards }
					}
					save_scope_value_as = { name = extra_reward value = flag:yes }
				}
				else = {
					save_scope_value_as = { name = extra_reward value = flag:no }
				}
				if = {
					limit = {
						NOT = { exists = scope:suppress_gold_warning }
					}
					custom_tooltip = laamp_base_1041.tt.gold_rewards_depend_on_travellers
				}
				else = { custom_tooltip = laamp_base_1041.tt.haul_actual }
				# Standard Rewards.
				loaa_laamp_rewards_disburse_ordinary_currency_effect = {
					GOLD = 0
					PRESTIGE = 0
					PIETY = 0
					PROVISIONS = 0
					OPINION = task_contract_opinion_crime_success_value
					OPINION_TYPE = succeeded_criminal_contract_against_me_opinion
					CONTACT = no
					CONTACT_HOOK = no
					EXTRA_REWARD = scope:extra_reward
				}
				task_contract_taker = { save_scope_as = adventurer }
				scope:employer ?= {
					ordered_realm_county = {
						#order_by = loaa_ambush_county_value
						order_by = {
							title_province = { add = "squared_distance(scope:adventurer.location)" }
							multiply = -1
							if = {
								limit = {
									OR = {
										has_county_modifier = laamp_base_1041_success_employer_modifier
										has_county_modifier = laamp_base_1041_failure_employer_modifier
									}
								}
								multiply = 100
							}
							if = {
								limit = {
									NOT = { holder = scope:task_contract.task_contract_employer }
								}
								multiply = 10
							}
						}
						save_scope_as = crime_location
					}
				}
				if = {
					limit = { NOT = { exists = scope:crime_location } }
					scope:adventurer.location = { save_scope_as = crime_location }
				}
				set_variable = {
					name = crime_location
					value = scope:crime_location
				}

				# Update gallowsbait score.
				task_contract_taker = {
					scope:task_contract.var:crime_location ?= { save_scope_as = crime_location }
					laamp_rewards_apply_criminal_xp_effect = {
						TRACK = bandit
						XP_MAX = gallowsbait_xp_medium_gain
						XP_MIN = gallowsbait_xp_medium_gain
					}
					bandit_king_maa_spawn_effect = yes
					trigger_event = loaa_contract_event.0100
				}

				task_contract_employer = {
					employer_criminal_activity_ambush_effect = yes
				}
			}
		}
		failure_standard = {
			positive = no
			should_print_on_complete = yes
			effect = {
				task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_failure_on_contract" }
				task_contract_employer = {
					remove_character_flag = targeted_by_hostile_contract_ambush
				}
				save_scope_as = task_contract
				task_contract_taker = { save_scope_as = adventurer }
				scope:employer ?= {
					ordered_realm_county = {
						order_by = {
							title_province = { add = "squared_distance(scope:adventurer.location)" }
							multiply = -1
							if = {
								limit = {
									OR = {
										has_county_modifier = laamp_base_1041_success_employer_modifier
										has_county_modifier = laamp_base_1041_failure_employer_modifier
									}
								}
								multiply = 100
							}
							if = {
								limit = {
									NOT = { holder = scope:task_contract.task_contract_employer }
								}
								multiply = 10
							}
						}
						save_scope_as = crime_location
					}
				}
				if = {
					limit = { NOT = { exists = scope:crime_location } }
					scope:adventurer.location = { save_scope_as = crime_location }
				}
				set_variable = {
					name = crime_location
					value = scope:crime_location
				}
				save_scope_value_as = { name = extra_reward value = flag:no }
				# Standard Penalties.
				loaa_laamp_rewards_disburse_ordinary_currency_effect = {
					GOLD = 0
					PRESTIGE = task_contract_failure_prestige_loss_crime_value
					PIETY = 0
					PROVISIONS = 0
					OPINION = task_contract_opinion_crime_failure_value
					OPINION_TYPE = attempted_criminal_contract_against_me_opinion
					CONTACT = no
					CONTACT_HOOK = no
					EXTRA_REWARD = scope:extra_reward
				}
				# Update gallowsbait score.
				task_contract_taker = {
					save_scope_as = adventurer
					scope:task_contract.var:crime_location ?= { save_scope_as = crime_location }
					laamp_rewards_apply_criminal_xp_effect = {
						TRACK = bandit
						XP_MAX = gallowsbait_xp_minor_gain
						XP_MIN = gallowsbait_xp_minor_gain
					}
				}
				task_contract_employer = {
					employer_criminal_activity_ambush_failure_effect = yes
				}
			}
		}
	}
}

# Collect fake taxes (player as "employer")
loaa_laamp_base_2041 = {
	group = laamp_contracts_criminal_group
	icon = "gfx/interface/icons/scheme_types/stewardship.dds"

	travel = no
	is_criminal = yes
	use_diplomatic_range = no

	weight = {
		# Standard weights.
		value = task_contract_weight_default_value
		add = laamp_contracts_weight_up_stewardship_value
		add = laamp_contracts_weight_up_criminal_massive_value
		# Employer weights.
		scope:employer = {
			add = laamp_contract_would_signpost_own_prosperity_value
			multiply = task_contract_weight_by_tier_value
		}
	}

	# Validity Triggers
	valid_to_create = {
		always = no
	}
	valid_to_accept = {
		# Standard triggers.
		valid_laamp_basic_accept_only_trigger = yes
		loaa_valid_laamp_basic_trigger = {
			EMPLOYER = scope:employer
			LAAMP = root
		}
		NOT = {
			house = {
				has_house_modifier = legacy_adventurer_house_modifier
			}
		}
		scope:employer = { is_landed = yes }
	}
	valid_to_continue = {
		# Standard triggers.
		loaa_valid_laamp_basic_trigger = {
			EMPLOYER = root.task_contract_employer
			LAAMP = root.task_contract_taker
		}
		root.task_contract_taker = {
			NOT = {
				house = {
					has_house_modifier = legacy_adventurer_house_modifier
				}
			}
		}
		task_contract_employer = { is_landed = yes }
	}
	valid_to_keep = {
		# Standard triggers.
		loaa_valid_laamp_basic_trigger = {
			EMPLOYER = root.task_contract_employer
			LAAMP = root.task_contract_taker
		}
		task_contract_employer = { is_landed = yes }
	}

	on_invalidated = {
		if = {
			limit = {
				root.task_contract_taker = {
					any_character_active_contract = {
						this = root
					}
				}
			}
			save_scope_as = task_contract
			task_contract_employer = {
				remove_variable = offered_contract
				remove_character_flag = targeted_by_hostile_contract_tax
			}
		}
	}

	# On_actions
	on_accepted = {
		task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_accept_contract" }
		# For the intro event.
		save_scope_as = task_contract
		task_contract_employer = { save_scope_as = employer }
		task_contract_employer = {
			add_character_flag = targeted_by_hostile_contract_tax
		}
		task_contract_taker ?= {
			location.county = { save_temporary_scope_as = start_location }
		}
		set_variable = {
			name = crime_location
			value = scope:start_location
		}
		# Then we start the travel.
		task_contract_taker ?= { trigger_event = loaa_laamp_base_contract_schemes.2044 }
		# Plus, set up some variables for us.
		## Progress tallies.
		increment_variable_effect = {
			VAR = wins_tally
			VAL = 0
		}
		increment_variable_effect = {
			VAR = losses_tally
			VAL = 0
		}
		## Victory tiers.
		save_scope_value_as = {
			name = win_t1_threshold
			value = {
				value = scope:employer.laamp_base_2041_num_counties_to_rob_sans_capital_value
				divide = 3
				floor = yes
			}
		}
		increment_variable_effect = {
			VAR = win_t1_threshold
			VAL = scope:win_t1_threshold
		}
		save_scope_value_as = {
			name = win_t2_threshold
			value = {
				value = scope:employer.laamp_base_2041_num_counties_to_rob_sans_capital_value
				divide = 3
				multiply = 2
				floor = yes
			}
		}
		increment_variable_effect = {
			VAR = win_t2_threshold
			VAL = scope:win_t2_threshold
		}
		increment_variable_effect = {
			VAR = win_t3_threshold
			VAL = scope:employer.laamp_base_2041_num_counties_to_rob_sans_capital_value
		}
		## Roll difficulties.
		increment_variable_effect = {
			VAR = stewardship_diff
			VAL = 10
		}
		increment_variable_effect = {
			VAR = intrigue_diff
			VAL = 10
		}
		increment_variable_effect = {
			VAR = bard_diff
			VAL = 0
		}
		increment_variable_effect = {
			VAR = stress_charge
			VAL = 20
		}
	}
	on_create = {
		scope:contract = {
			set_variable = {
				name = animation
				value = 0
			}
			# Make our gold rewards static.
			grab_gold_fuzz_number_effect = yes
			save_scope_as = task_contract
			set_variable = {
				name = gold_success_standard
				value = {
					value = task_contract_taker.task_contract_success_gold_gain_crime_value
					multiply = 0.5
				}
			}
			set_variable = {
				name = gold_success_qualified
				value = {
					value = task_contract_taker.task_contract_success_gold_gain_half_crime_value
					multiply = 0.5
				}
			}
			# Make sure critical values are a bit higher.
			save_scope_value_as = { name = gold_safety_margin value = flag:yes }
			set_variable = {
				name = gold_success_critical
				value = {
					value = task_contract_taker.task_contract_success_gold_gain_critical_crime_value
					multiply = 0.5
				}
			}
		}
	}

	# Rewards
	task_contract_reward = {
		success_standard = {
			should_print_on_complete = yes
			effect = {
				task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_success_on_contract" }
				# Camp building extra Stewardship Rewards: +50%.
				if = {
					limit = {
						task_contract_taker.domicile ?= { has_domicile_parameter = camp_improved_stewardship_contract_rewards }
					}
					save_scope_value_as = { name = extra_reward value = flag:yes }
				}
				# Standard Reward.
				else = {
					save_scope_value_as = { name = extra_reward value = flag:no }
				}
				loaa_laamp_rewards_disburse_ordinary_currency_effect = {
					GOLD = scope:task_contract.var:gold_success_standard
					PRESTIGE = 0
					PIETY = 0
					PROVISIONS = task_contract_success_provisions_gain_major_value
					OPINION = task_contract_opinion_crime_success_value
					OPINION_TYPE = succeeded_criminal_contract_against_me_opinion
					CONTACT = no
					CONTACT_HOOK = no
					EXTRA_REWARD = scope:extra_reward
				}
				# Update gallowsbait score.
				task_contract_taker = {
					save_scope_as = adventurer
					root.var:crime_location = { save_scope_as = crime_location }
					laamp_rewards_apply_criminal_xp_effect = {
						TRACK = trickster
						XP_MAX = gallowsbait_xp_medium_gain
						XP_MIN = gallowsbait_xp_medium_gain
					}
					bandit_king_maa_spawn_effect = yes
					trigger_event = loaa_contract_event.0100
				}
				task_contract_employer = {
					employer_criminal_activity_tax_effect = yes
				}
				task_contract_employer = {
					remove_character_flag = targeted_by_hostile_contract_tax
				}
			}
		}
		success_qualified = {
			should_print_on_complete = yes
			effect = {
				task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_success_on_contract" }
				# Camp building extra Stewardship Rewards: +50%.
				if = {
					limit = {
						task_contract_taker.domicile ?= { has_domicile_parameter = camp_improved_stewardship_contract_rewards }
					}
					save_scope_value_as = { name = extra_reward value = flag:yes }
				}
				# Standard Reward.
				else = {
					save_scope_value_as = { name = extra_reward value = flag:no }
				}
				loaa_laamp_rewards_disburse_ordinary_currency_effect = {
					GOLD = scope:task_contract.var:gold_success_qualified
					PRESTIGE = 0
					PIETY = 0
					PROVISIONS = task_contract_success_provisions_gain_medium_value
					OPINION = task_contract_opinion_crime_success_value
					OPINION_TYPE = succeeded_criminal_contract_against_me_opinion
					CONTACT = no
					CONTACT_HOOK = no
					EXTRA_REWARD = scope:extra_reward
				}
				# Update gallowsbait score.
				task_contract_taker = {
					save_scope_as = adventurer
					root.var:crime_location = { save_scope_as = crime_location }
					laamp_rewards_apply_criminal_xp_effect = {
						TRACK = trickster
						XP_MAX = gallowsbait_xp_minor_gain
						XP_MIN = gallowsbait_xp_minor_gain
					}
					bandit_king_maa_spawn_effect = yes
					trigger_event = loaa_contract_event.0100
				}
				task_contract_employer = {
					employer_criminal_activity_tax_effect = yes
					remove_character_flag = targeted_by_hostile_contract_tax
				}
			}
		}
		success_critical = {
			should_print_on_complete = yes
			effect = {
				task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_success_on_contract" }
				# Camp building extra Stewardship Rewards: +50%.
				if = {
					limit = {
						task_contract_taker.domicile ?= { has_domicile_parameter = camp_improved_stewardship_contract_rewards }
					}
					save_scope_value_as = { name = extra_reward value = flag:yes }
				}
				# Standard Reward.
				else = {
					save_scope_value_as = { name = extra_reward value = flag:no }
				}
				loaa_laamp_rewards_disburse_ordinary_currency_effect = {
					GOLD = scope:task_contract.var:gold_success_critical
					PRESTIGE = 0
					PIETY = 0
					PROVISIONS = task_contract_success_provisions_gain_major_value
					OPINION = task_contract_opinion_crime_success_value
					OPINION_TYPE = succeeded_criminal_contract_against_me_opinion
					CONTACT = no
					CONTACT_HOOK = no
					EXTRA_REWARD = scope:extra_reward
				}
				# Update gallowsbait score.
				task_contract_taker = {
					save_scope_as = adventurer
					root.var:crime_location = { save_scope_as = crime_location }
					laamp_rewards_apply_criminal_xp_effect = {
						TRACK = trickster
						XP_MAX = gallowsbait_xp_major_gain
						XP_MIN = gallowsbait_xp_major_gain
					}
					bandit_king_maa_spawn_effect = yes
					trigger_event = loaa_contract_event.0100
				}
				task_contract_employer = {
					employer_criminal_activity_tax_effect = yes
					remove_character_flag = targeted_by_hostile_contract_tax
				}
			}
		}
		failure_standard = {
			positive = no
			should_print_on_complete = yes
			effect = {
				task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_failure_on_contract" }
				save_scope_value_as = { name = extra_reward value = flag:no }
				# Standard Penalties.
				loaa_laamp_rewards_disburse_ordinary_currency_effect = {
					GOLD = 0
					PRESTIGE = task_contract_failure_prestige_loss_crime_value
					PIETY = 0
					PROVISIONS = 0
					OPINION = task_contract_opinion_crime_failure_value
					OPINION_TYPE = attempted_criminal_contract_against_me_opinion
					CONTACT = no
					CONTACT_HOOK = no
					EXTRA_REWARD = scope:extra_reward
				}
				# Update gallowsbait score.
				task_contract_taker = {
					save_scope_as = adventurer
					root.var:crime_location = { save_scope_as = crime_location }
					laamp_rewards_apply_criminal_xp_effect = {
						TRACK = trickster
						XP_MAX = gallowsbait_xp_minor_gain
						XP_MIN = gallowsbait_xp_minor_gain
					}
				}
				task_contract_employer = {
					remove_character_flag = targeted_by_hostile_contract_tax
				}
				task_contract_employer = {
					employer_criminal_activity_tax_failure_effect = yes
				}
			}
		}
		failure_qualified = {
			positive = no
			should_print_on_complete = yes
			visible = no
			effect = {
				task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_failure_on_contract" }
				save_scope_value_as = { name = extra_reward value = flag:no }
				# Standard Penalties.
				loaa_laamp_rewards_disburse_ordinary_currency_effect = {
					GOLD = 0
					PRESTIGE = task_contract_failure_prestige_loss_full_value
					PIETY = 0
					PROVISIONS = 0
					OPINION = task_contract_opinion_crime_backed_down_value
					OPINION_TYPE = attempted_criminal_contract_against_me_opinion
					CONTACT = no
					CONTACT_HOOK = no
					EXTRA_REWARD = scope:extra_reward
				}
				# Update gallowsbait score.
				task_contract_taker = {
					save_scope_as = adventurer
					root.var:crime_location = { save_scope_as = crime_location }
					laamp_rewards_apply_criminal_xp_effect = {
						TRACK = trickster
						XP_MAX = gallowsbait_xp_minor_gain
						XP_MIN = gallowsbait_xp_minor_gain
					}
				}
				task_contract_employer = {
					employer_criminal_activity_tax_failure_effect = yes
					remove_character_flag = targeted_by_hostile_contract_tax
				}
			}
		}
	}
}

# Go rustling (player as "employer")
loaa_laamp_base_5031 = {
	group = laamp_contracts_criminal_group
	icon = "gfx/interface/icons/scheme_types/war.dds"

	is_criminal = yes
	use_diplomatic_range = no

	weight = {
		# Standard weights.
		value = task_contract_weight_default_value
		add = laamp_contracts_weight_up_prowess_value
		add = laamp_contracts_weight_up_criminal_value
		# Employer weights.
		scope:employer = {
			add = laamp_contract_would_signpost_own_prosperity_value
			multiply = task_contract_weight_by_tier_value
		}
	}

	# Validity Triggers
	valid_to_create = {
		always = no
	}
	valid_to_accept = {
		# Standard triggers.
		valid_laamp_basic_accept_only_trigger = yes
		loaa_valid_laamp_basic_trigger = {
			EMPLOYER = scope:employer
			LAAMP = root
		}
		NOT = {
			house = {
				has_house_modifier = legacy_adventurer_house_modifier
			}
		}
		scope:employer = { is_landed = yes }
	}
	valid_to_continue = {
		# Standard triggers.
		loaa_valid_laamp_basic_trigger = {
			EMPLOYER = root.task_contract_employer
			LAAMP = root.task_contract_taker
		}
		task_contract_employer = { is_landed = yes }
		# Specific flavour triggers.
		root.task_contract_employer.sub_realm_size >= 2
		root.task_contract_taker = {
			NOT = {
				house = {
					has_house_modifier = legacy_adventurer_house_modifier
				}
			}
		}
	}
	valid_to_keep = {
		# Standard triggers.
		loaa_valid_laamp_basic_trigger = {
			EMPLOYER = root.task_contract_employer
			LAAMP = root.task_contract_taker
		}
		task_contract_employer = { is_landed = yes }
	}

	# On_actions
	on_accepted = {
		task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_accept_contract" }
		# For the intro event.
		save_scope_as = task_contract
		task_contract_employer = { save_scope_as = employer }

		scope:employer = {
			add_character_flag = targeted_by_hostile_contract_rustle
		}

		# Then we start the travel.
		task_contract_taker ?= {
			location.county = { save_scope_as = start_location }
			trigger_event = loaa_laamp_base_contract_schemes.5034
		}
		set_variable = {
			name = crime_location
			value = scope:start_location
		}
		# Plus, set up some variables for us.
		## Progress tallies.
		increment_variable_effect = {
			VAR = encounter_tally
			VAL = 0
		}
		increment_variable_effect = {
			VAR = encounter_max
			VAL = 0
		}
		increment_variable_effect = {
			VAR = wins_tally
			VAL = 0
		}
	}
	on_create = {
		scope:contract = {
			set_variable = {
				name = animation
				value = 0
			}
			# Make our gold rewards static.
			grab_gold_fuzz_number_effect = yes
			save_scope_as = task_contract
			set_variable = {
				name = gold_success_standard
				value = {
					value = task_contract_taker.task_contract_success_gold_gain_crime_value
					multiply = 0.5
				}
			}
			set_variable = {
				name = gold_success_critical
				value = {
					value = task_contract_taker.task_contract_success_gold_gain_critical_crime_value
					multiply = 0.5
				}
			}
		}
	}

	on_invalidated = {
		if = {
			limit = {
				root.task_contract_taker = {
					any_character_active_contract = {
						this = root
					}
				}
			}
			save_scope_as = task_contract
			task_contract_employer = {
				remove_variable = offered_contract
				remove_character_flag = targeted_by_hostile_contract_rustle
			}
		}
	}

	# Rewards
	task_contract_reward = {
		success_critical = {
			should_print_on_complete = yes
			effect = {
				task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_success_on_contract" }
				# Camp building extra Criminal Rewards: +50%.
				if = {
					limit = {
						task_contract_taker.domicile ?= { has_domicile_parameter = camp_improved_criminal_contract_rewards }
					}
					save_scope_value_as = { name = extra_reward value = flag:yes }
				}
				# Critical Reward.
				else = {
					save_scope_value_as = { name = extra_reward value = flag:no }
				}
				loaa_laamp_rewards_disburse_ordinary_currency_effect = {
					GOLD = scope:task_contract.var:gold_success_critical
					PRESTIGE = 0
					PIETY = 0
					PROVISIONS = task_contract_success_provisions_gain_major_value
					OPINION = task_contract_opinion_crime_success_value
					OPINION_TYPE = succeeded_criminal_contract_against_me_opinion
					CONTACT = no
					CONTACT_HOOK = no
					EXTRA_REWARD = scope:extra_reward
				}
				# Update gallowsbait score.
				task_contract_taker = {
					save_scope_as = adventurer
					root.var:crime_location = { save_scope_as = crime_location }
					laamp_rewards_apply_criminal_xp_effect = {
						TRACK = poacher
						XP_MAX = gallowsbait_xp_major_gain
						XP_MIN = gallowsbait_xp_major_gain
					}
					trigger_event = loaa_contract_event.0100
				}
				task_contract_employer = {
					remove_character_flag = targeted_by_hostile_contract_rustle
					employer_criminal_activity_rustle_effect = yes
				}

			}
		}
		success_standard = {
			should_print_on_complete = yes
			effect = {
				task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_success_on_contract" }
				# Camp building extra Criminal Rewards: +50%.
				if = {
					limit = {
						task_contract_taker.domicile ?= { has_domicile_parameter = camp_improved_criminal_contract_rewards }
					}
					save_scope_value_as = { name = extra_reward value = flag:yes }
				}
				else = {
					save_scope_value_as = { name = extra_reward value = flag:no }
				}
				# Standard Rewards.
				loaa_laamp_rewards_disburse_ordinary_currency_effect = {
					GOLD = scope:task_contract.var:gold_success_standard
					PRESTIGE = 0
					PIETY = 0
					PROVISIONS = task_contract_success_provisions_gain_medium_value
					OPINION = task_contract_opinion_crime_success_value
					OPINION_TYPE = succeeded_criminal_contract_against_me_opinion
					CONTACT = no
					CONTACT_HOOK = no
					EXTRA_REWARD = scope:extra_reward
				}
				# Update gallowsbait score.
				task_contract_taker = {
					save_scope_as = adventurer
					root.var:crime_location = { save_scope_as = crime_location }
					laamp_rewards_apply_criminal_xp_effect = {
						TRACK = poacher
						XP_MIN = gallowsbait_xp_medium_gain
						XP_MAX = gallowsbait_xp_medium_gain
					}
					trigger_event = loaa_contract_event.0100
				}
				task_contract_employer = {
					save_scope_as = task_contract_employer
					remove_character_flag = targeted_by_hostile_contract_rustle

				}
				scope:task_contract_employer = {
					employer_criminal_activity_rustle_effect = yes
				}
			}
		}
		failure_standard = {
			positive = no
			should_print_on_complete = yes
			effect = {
				save_scope_as = task_contract
				task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_failure_on_contract" }
				save_scope_value_as = { name = extra_reward value = flag:no }
				# Standard Penalties.
				loaa_laamp_rewards_disburse_ordinary_currency_effect = {
					GOLD = 0
					PRESTIGE = task_contract_failure_prestige_loss_crime_value
					PIETY = 0
					PROVISIONS = task_contract_failure_provisions_gain_minor_value
					OPINION = task_contract_opinion_crime_failure_value
					OPINION_TYPE = attempted_criminal_contract_against_me_opinion
					CONTACT = no
					CONTACT_HOOK = no
					EXTRA_REWARD = scope:extra_reward
				}
				# Update gallowsbait score.
				task_contract_taker = {
				 	save_scope_as = adventurer
					scope:task_contract.var:crime_location = { save_scope_as = crime_location }
					laamp_rewards_apply_criminal_xp_effect = {
						TRACK = poacher
						XP_MIN = gallowsbait_xp_minor_gain
						XP_MAX = gallowsbait_xp_minor_gain
					}
				}
				task_contract_employer = {
					remove_character_flag = targeted_by_hostile_contract_rustle
				}
				task_contract_employer = {
					save_scope_as = task_contract_employer
					employer_criminal_activity_rustle_failure_effect = yes
				}
			}
		}
	}
}

## Legitimist contract
loaa_laamp_legitimist_support_contract = {
	group = laamp_contracts_legitimist_group
	icon = "gfx/interface/icons/scheme_types/diplomacy.dds"

	travel = yes
	use_diplomatic_range = yes

	weight = {
		value = task_contract_weight_interesting_very_rare_value
		add = task_contract_weight_employer_contact_list_value
	}

	valid_to_create = {
		# Standard triggers.
		loaa_valid_laamp_basic_trigger = {
			EMPLOYER = scope:employer
			LAAMP = root
		}
		has_realm_law = camp_purpose_legitimists
		scope:employer = {
			opinion = {
				target = root
				value > 60
			}
		}
		scope:employer.primary_title.tier >= tier_kingdom
	}

	valid_to_continue = {
		# Standard triggers.
		loaa_valid_laamp_basic_trigger = {
			EMPLOYER = root.task_contract_employer
			LAAMP = root.task_contract_taker
		}
	}

	valid_to_keep = {
		# Standard triggers.
		loaa_valid_laamp_basic_trigger = {
			EMPLOYER = root.task_contract_employer
			LAAMP = root.task_contract_taker
		}
	}

	on_invalidated = {
		root.task_contract_employer ?= {
			if = {
				limit = { has_character_flag = legitimist_supporter }
				remove_character_flag = legitimist_supporter
			}
		}
		root.task_contract_taker ?= {
			if = {
				limit = {
					has_variable = potential_legitimist_supporter
					var:potential_legitimist_supporter = root.task_contract_employer
				}
				remove_variable = potential_legitimist_supporter
			}
		}
	}

	on_create = {
		scope:contract = {
			task_contract_employer = {
				add_character_flag = legitimist_supporter
			}
		}
	}

	on_accepted = {
		task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_accept_contract" }
		save_scope_as = task_contract
		task_contract_employer = {
			save_scope_as = petitioned_ruler
		}
		task_contract_taker = {
			save_scope_as = claimant
			trigger_event = loaa_legitimist_support_events.1
		}
	}

	task_contract_reward = {
		success_standard = {
			effect = {
				task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_success_on_contract" }
				task_contract_employer = {
					save_scope_as = recipient
				}
				task_contract_taker = {
					custom_tooltip = loaa_laamp_legitimist_support_contract_success
				}
			}
		}
		failure_standard = {
			positive = no
			effect = {
				task_contract_employer = {
					remove_character_flag = legitimist_supporter
				}
				task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_failure_on_contract" }
				task_contract_taker = {
					custom_tooltip = laamp_legitimist_support_contract_failure
				}
			}
		}
	}
}