##################################################
# INFO
# Extra contracts for laamps. Various types of contracts with interesting things to get and do, like wars, travel, artifacts and more.
#
##################################################



##################################################
# GROUPS (for populate_task_contracts_for_area)
#
# laamp_contracts_war_group
# laamp_contracts_criminal_group
# laamp_contracts_transport_group
# laamp_contracts_diplomacy_group
# laamp_contracts_intrigue_group
#
#
# NOTICEBOARD GROUPS (for Visit Settlement - ep3_laamp_decision_event.1025)
# laamp_contracts_noticeboard_group
#



##################################################
#
# laamp_raid_contract - Raid for Captives
# laamp_join_war_contract - Stand with Us
# laamp_help_claimant_contract - Press My Claims
# laamp_steal_artifact_contract - Reclaim Artifact
# laamp_construction_contract - Construction Work
# laamp_treasure_hunting_contract - Treasure Hunting
# laamp_cultural_minority_contract - Protect Heritage
# laamp_religious_minority_contract - Reward the Faithful
# laamp_prison_break_contract - Prison Break
# laamp_treasure_map_contract - Treasure Map
# laamp_legitimist_support_contract
# laamp_join_faction_contract - Support Faction
# laamp_help_faith_conversion_contract - Missionary Duties
# laamp_fight_faith_conversion_contract - Protect the Adherents
# laamp_help_train_commanders_contract - Knight's Coach
# laamp_help_find_secrets_contract - Private Eye
# laamp_help_fabricate_claim_contract - Forgotten Claims
# laamp_help_increase_control_contract - Fight Corruption
#
##################################################

## Raid for Captives
# scope:employer = ruler wanting to capture prisoners
# task_contract_target = character to declare war on
# task_contract_destination = capital of task_contract_target
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 = {
		# Standard triggers.
		valid_laamp_basic_trigger = {
			EMPLOYER = scope:employer
			LAAMP = root
		}
		employer_has_treasury_to_offer_job_trigger = yes
		valid_laamp_sensible_start_trigger = yes
		# Specific flavour triggers.
		scope:employer = {
			OR = {
				any_relation = {
					type = rival
					is_ai = yes
					is_adult = yes
					is_landed = yes
					capital_province.building_max_garrison < root.current_military_strength
					is_within_diplo_range = { CHARACTER = scope:employer }
					any_courtier_or_guest = {
						count >= 3
						OR = {
							AND = {
								has_dynasty = yes
								dynasty = prev.dynasty
							}
							is_consort_of = prev
						}
					}
				}
				any_neighboring_top_liege_realm_owner = {
					is_ai = yes
					is_adult = yes
					is_landed = yes
					capital_province.building_max_garrison < root.current_military_strength
					house_has_feud_relation_with_trigger = { TARGET = scope:employer }
					any_courtier_or_guest = {
						count >= 3
						OR = {
							AND = {
								has_dynasty = yes
								dynasty = prev.dynasty
							}
							is_consort_of = prev
						}
					}
				}
			}
		}
	}
	valid_to_accept = {
		# Standard triggers.
		valid_laamp_basic_accept_only_trigger = yes
		valid_laamp_basic_trigger = {
			EMPLOYER = scope:employer
			LAAMP = root
		}
	}
	valid_to_continue = {
		# Standard triggers.
		valid_laamp_basic_trigger = {
			EMPLOYER = root.task_contract_employer
			LAAMP = root.task_contract_taker
		}
	}
	valid_to_keep = {
		# Standard triggers.
		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_employer = {
				save_scope_as = task_contract_employer
				if = {
					limit = {
						NOT = { exists = scope:task_contract.task_contract_target }
					}
					if = {
						limit = {
							any_neighboring_top_liege_realm_owner = {
								is_ai = yes
								is_adult = yes
								is_landed = yes
								capital_province.building_max_garrison < root.current_military_strength
								house_has_feud_relation_with_trigger = { TARGET = scope:task_contract_employer }
								any_courtier_or_guest = {
									count >= 3
									OR = {
										AND = {
											has_dynasty = yes
											dynasty = prev.dynasty
										}
										is_consort_of = prev
									}
								}
							}
						}
						random_neighboring_top_liege_realm_owner = {
							limit = {
								is_ai = yes
								is_adult = yes
								is_landed = yes
								capital_province.building_max_garrison < root.current_military_strength
								house_has_feud_relation_with_trigger = { TARGET = scope:task_contract_employer }
								any_courtier_or_guest = {
									count >= 3
									OR = {
										AND = {
											has_dynasty = yes
											dynasty = prev.dynasty
										}
										is_consort_of = prev
									}
								}
							}
							save_scope_as = task_contract_target
							capital_province = {
								save_scope_as = task_contract_destination
							}
						}
					}
					else = {
						random_relation = {
							type = rival
							limit = {
								is_ai = yes
								is_adult = yes
								is_landed = yes
								capital_province.building_max_garrison < root.current_military_strength
								is_within_diplo_range = { CHARACTER = scope:task_contract_employer }
								any_courtier_or_guest = {
									count >= 3
									OR = {
										AND = {
											has_dynasty = yes
											dynasty = prev.dynasty
										}
										is_consort_of = prev
									}
								}
							}
							save_scope_as = task_contract_target
							capital_province = {
								save_scope_as = task_contract_destination
							}
						}
					}
				}
				else_if = {
					limit = {
						NOT = { exists = scope:task_contract.task_contract_destination }
					}
					scope:task_contract_target = {
						capital_province = {
							save_scope_as = task_contract_destination
						}
					}
				}
			}
			set_task_contract_target = scope:task_contract_target
			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 = {
			trigger_event = ep3_contract_event.0003
		}
	}

	on_invalidated = {
		if = {
			limit = {
				root.task_contract_taker = {
					any_character_active_contract = {
						this = root
					}
				}
			}
			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
				}
			}
			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
				}
			}
		}
	}

	# 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 = {
					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 = ep3_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
						}
					}
				}
			}
		}
	}
}

## Stand with Us
# scope:employer = ruler needing help in a civil/religious/de_hure war
# scope:task_contract_war = civil/religious/de_hure war to join on the side of employer
laamp_join_war_contract = {
	group = laamp_contracts_war_group
	icon = "gfx/interface/icons/trait_level_tracks/mercenary.dds"
	travel = no
	use_diplomatic_range = no

	# Validity Triggers
	valid_to_create = {
		# Standard triggers.
		valid_laamp_basic_trigger = {
			EMPLOYER = scope:employer
			LAAMP = root
		}
		employer_has_treasury_to_offer_job_trigger = yes
		# Specific flavour triggers.
		scope:employer = {
			any_character_war = {
				ep3_adventurer_mercenary_war_trigger = {
					EMPLOYER = scope:employer
					LAAMP = root
				}
				save_temporary_scope_as = temp_war
			}
		}
		#don't spawn contracts for the same wars
		NOT = {
			any_character_task_contract = {
				task_contract_type = laamp_join_war_contract
				var:task_contract_war ?= scope:temp_war
			}
		}
		#or if you are already an ally in a war with someone in that war, to prevent being an ally and an enemy at the same time
		scope:temp_war = {
			any_war_participant = {
				NOT = {
					is_allied_in_war = root
				}
			}
		}
	}
	valid_to_accept = {
		# Standard triggers.
		valid_laamp_basic_accept_only_trigger = yes
		valid_laamp_basic_trigger = {
			EMPLOYER = scope:employer
			LAAMP = root
		}
		custom_tooltip = {
			text = laamp_join_war_contract.valid_war
			any_character_task_contract = {
				task_contract_type = laamp_join_war_contract
				exists = var:task_contract_war
				task_contract_employer = scope:employer
			}
		}
	}
	valid_to_continue = {
		# Standard triggers.
		valid_laamp_basic_trigger = {
			EMPLOYER = root.task_contract_employer
			LAAMP = root.task_contract_taker
		}
	}
	valid_to_keep = {
		exists = root.var:task_contract_war
		# Standard triggers.
		valid_laamp_basic_trigger = {
			EMPLOYER = root.task_contract_employer
			LAAMP = root.task_contract_taker
		}
	}

	weight = {
		# Standard weights.
		value = task_contract_weight_interesting_very_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 = {
				random_character_war = {
					limit = {
						is_war_leader = prev
						OR = {
							using_civil_war_cb_trigger = yes
							using_non_ghw_holy_war_cb_trigger = yes
							using_de_jure_cb_trigger = yes
							using_conquest_cb_trigger = yes
						}
						any_war_participant = {
							this != scope:task_contract.task_contract_taker
						}
					}
					save_scope_as = task_contract_war
				}
				save_scope_as = task_contract_employer
			}
			set_variable = {
				name = task_contract_war
				value = scope:task_contract_war
			}
			set_variable = {
				name = task_contract_employer
				value = scope:task_contract_employer
			}
			scope:task_contract_war = {
				if = {
					limit = {
						is_attacker = scope:task_contract_employer
					}
					primary_defender = {
						save_scope_as = task_contract_target
					}
				}
				else = {
					primary_attacker = {
						save_scope_as = task_contract_target
					}
				}
			}
			set_task_contract_target = scope:task_contract_target
			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
		task_contract_taker = {
			trigger_event = ep3_contract_event.0008
		}
		set_variable = {
			name = task_contract_grace_period
			days = 90
		}
	}

	on_invalidated = {
		if = {
			limit = {
				root.task_contract_taker = {
					any_character_active_contract = {
						this = root
					}
				}
			}
			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_target = {
				save_scope_as = task_contract_target
			}
			task_contract_taker = {
				set_variable = {
					name = invalidated_task_contract_type
					value = flag:laamp_join_war_contract
				}
			}

			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_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_war = {
					save_scope_as = war
				}
				task_contract_employer = {
					save_scope_as = task_contract_employer
					save_scope_as = attacker
				}
				task_contract_taker = {
					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 = war_contribution_value
						value = "scope:war.war_contribution(scope:task_contract_taker)"
					}
					if = {
						limit = {
							exists = scope:task_contract_employer.var:valuable_prisoners
						}
						save_scope_value_as = {
							name = war_valuable_prisoners
							value = scope:task_contract_employer.var:valuable_prisoners
						}
					}
					save_scope_value_as = {
						name = task_contract_tier
						value = scope:task_contract.task_contract_tier
					}
					trigger_event = ep3_contract_event.0013
					# 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" }
				if = {
					limit = {
						NOT = { has_variable = task_contract_grace_period }
					}
					save_scope_as = task_contract
					var:task_contract_war = {
						save_scope_as = war
					}
					task_contract_employer = {
						save_scope_as = task_contract_employer
					}
					task_contract_taker = {
						add_prestige = task_contract_failure_prestige_loss_full_value
						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
						}
						trigger_event = ep3_contract_event.0013
					}
				}
			}
		}
	}
}

## Help Legitimate claim
# scope:employer = ruler with a valid claim
# task_contract_target = character to declare war on
# task_contract_destination = capital of task_contract_target
laamp_help_claimant_contract = {
	group = laamp_contracts_war_group
	icon = "gfx/interface/icons/casus_bellis/claim_cb.dds"
	travel = no
	use_diplomatic_range = no

	# Validity Triggers
	valid_to_create = {
		# Standard triggers.
		valid_laamp_basic_trigger = {
			EMPLOYER = scope:employer
			LAAMP = root
		}
		employer_has_treasury_to_offer_job_trigger = yes
		valid_laamp_sensible_start_trigger = yes
		# Specific flavour triggers.
		scope:employer = {
			is_at_war = no
			NAND = {
				government_allows = administrative
				liege = { government_allows = administrative }
			}
			liege = { has_realm_law_flag = vassal_all_wars_banned }
			NOT = {
				vassal_contract_has_flag = vassal_contract_war_override
			}		
			any_claim = {
				holder ?= {
					NOT = { is_allied_to = scope:employer }
					NOT = { any_liege_or_above = { this = scope:employer } }
					scope:employer = {
						has_cb_on = {
							target = prev
							cb = claim_cb
						}
					}
				}
			}
		}
	}
	valid_to_accept = {
		# Standard triggers.
		valid_laamp_basic_accept_only_trigger = yes
		valid_laamp_basic_trigger = {
			EMPLOYER = scope:employer
			LAAMP = root
		}
	}
	valid_to_continue = {
		# Standard triggers.
		valid_laamp_basic_trigger = {
			EMPLOYER = root.task_contract_employer
			LAAMP = root.task_contract_taker
		}
	}
	valid_to_keep = {
		# Standard triggers.
		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_employer = {
				save_scope_as = task_contract_employer
				if = {
					limit = {
						NOT = { exists = scope:task_contract.task_contract_target }
					}
					random_claim = {
						limit = {
							holder ?= {
								NOT = { is_allied_to = root }
								NOT = { any_liege_or_above = { this = root } }
								scope:task_contract_employer = {
									has_cb_on = {
										target = prev
										cb = claim_cb
									}
								}
							}
						}
						save_scope_as = task_contract_title
						holder = {
							save_scope_as = task_contract_target
						}
					}
				}
			}
			set_task_contract_target = scope:task_contract_target
			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_title
				value = scope:task_contract_title	
			}
		}
	}
	# 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 = {
			trigger_event = ep3_contract_event.0060
		}
	}

	on_invalidated = {
		if = {
			limit = {
				root.task_contract_taker = {
					any_character_active_contract = {
						this = root
					}
				}
			}
			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_target = {
				save_scope_as = task_contract_target
			}

			task_contract_taker = {
				set_variable = {
					name = invalidated_task_contract_type
					value = flag:laamp_help_claimant_contract
				}
			}
			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_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_title = {
					save_scope_as = task_contract_title
				}
				task_contract_employer = {
					save_scope_as = task_contract_employer
					save_scope_as = attacker
					show_as_tooltip = {
						get_title = scope:task_contract_title
					}
				}
				task_contract_taker = {
					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
					}
					trigger_event = ep3_contract_event.0013
					# 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
				var:task_contract_title = {
					save_scope_as = task_contract_title
				}
				task_contract_employer = {
					save_scope_as = task_contract_employer
				}
				task_contract_taker = {
					add_prestige = task_contract_failure_prestige_loss_full_value
					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
					}
					trigger_event = ep3_contract_event.0013
				}
			}
		}
	}
}

## Reclaim Artifact
# scope:employer = ruler wanting to steal an artifact
# task_contract_target = character to steal an artifact from
# task_contract_object = an artifact to steal
laamp_steal_artifact_contract = {
	group = laamp_contracts_criminal_group
	icon = "gfx/interface/icons/character_interactions/icon_scheme_steal_back_artifact.dds"
	travel = yes
	use_diplomatic_range = no
	is_criminal = yes

	# Validity Triggers
	valid_to_create = {
		# Standard triggers.
		valid_laamp_basic_trigger = {
			EMPLOYER = scope:employer
			LAAMP = root
		}
		employer_has_treasury_to_offer_job_trigger = yes
		valid_laamp_sensible_start_trigger = yes
		# Specific flavour triggers.
		scope:employer = {
			OR = {
				#target any artifact you have a claim on
				any_claimed_artifact = {
					artifact_owner = {
						is_within_diplo_range = { CHARACTER = root }
					}
				}
				#or if you are greedy target at least a masterwork artifact of someone that is up to 1 tier above you
				AND = {
					ai_greed >= 50
					any_neighboring_top_liege_realm_owner = {
						highest_held_title_tier <= {
							value = scope:employer.highest_held_title_tier
							add = 1
						}
						any_character_artifact = {
							artifact_high_rarity_trigger = yes
						}
					}
				}
			}
		}
	}

	valid_to_keep = {
		exists = root.var:task_contract_object
		root.var:task_contract_object = {
			artifact_owner != root.task_contract_employer
		}
		task_contract_target = {
			NOT = {
				has_opinion_modifier = {
					target = root.task_contract_taker
					modifier = stole_artifact_from_me
				}
			}
		}
		# Standard triggers.
		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
		}
	}
	valid_to_continue = {
		exists = root.var:task_contract_object
		root.var:task_contract_object = {
			artifact_owner != root.task_contract_employer
		}
		task_contract_target = {
			NOT = {
				has_opinion_modifier = {
					target = root.task_contract_taker
					modifier = stole_artifact_from_me
				}
			}
		}
		# Standard triggers.
		valid_laamp_basic_trigger = {
			EMPLOYER = root.task_contract_employer
			LAAMP = root.task_contract_taker
		}
	}

	weight = {
		# Standard weights.
		value = task_contract_weight_interesting_quite_rare_value
		add = laamp_contracts_weight_up_intrigue_value
		if = {
			limit = {
				employs_court_position = master_thief_camp_officer
			}
			add = 50
		}
		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
			task_contract_employer = {
				if = {
					limit = {
						any_claimed_artifact = {
							artifact_owner = {
								is_within_diplo_range = { CHARACTER = scope:task_contract.task_contract_taker }
							}
							save_temporary_scope_as = claimed_artifact
						}
					}
					scope:claimed_artifact = {
						save_scope_as = task_contract_object
						artifact_owner = {
							save_scope_as = task_contract_target
						}
					}
				}
				else = {
					random_neighboring_top_liege_realm_owner = {
						limit = {
							highest_held_title_tier <= {
								value = scope:task_contract.task_contract_employer.highest_held_title_tier
								add = 1
							}
							any_character_artifact = {
								artifact_high_rarity_trigger = yes
								save_temporary_scope_as = claimed_artifact
							}
						}
						scope:claimed_artifact = {
							save_scope_as = task_contract_object
						}
						save_scope_as = task_contract_target
					}
				}
			}
			set_task_contract_target = scope:task_contract_target
			set_variable = {
				name = task_contract_employer
				value = scope:task_contract.task_contract_employer
			}
			set_variable = {
				name = task_contract_target
				value = scope:task_contract_target
			}
			set_variable = {
				name = task_contract_object
				value = scope:task_contract_object
			}
			# Make our gold rewards static.
			grab_gold_fuzz_number_effect = yes
			set_variable = {
				name = gold_success_standard
				value = task_contract_taker.task_contract_success_gold_gain_full_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
		task_contract_taker = {
			trigger_event = ep3_contract_event.0009
		}
	}

	on_invalidated = {
		if = {
			limit = {
				root.task_contract_taker = {
					any_character_active_contract = {
						this = root
					}
				}
			}
			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_steal_artifact_contract
				}
			}
			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_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_object = {
					save_scope_as = task_contract_object
				}
				task_contract_taker = {
					send_interface_toast = {
						title = laamp_transport_contract.success
						left_icon = scope:task_contract.task_contract_taker
						right_icon = scope:task_contract.task_contract_employer
						root = {
							save_scope_value_as = { name = extra_reward value = flag:no }
							# Standard Rewards.
							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 = 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
							}
						}
					}
					# Update gallowsbait score.
					laamp_rewards_apply_criminal_xp_effect = {
						TRACK = thief
						XP_MIN = gallowsbait_xp_medium_gain
						XP_MAX = gallowsbait_xp_medium_gain
					}
				}
				hidden_effect = {
					scope:task_contract_object = {
						set_owner = scope:task_contract.task_contract_employer
					}
				}
			}
		}
		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
				save_scope_value_as = { name = extra_reward value = flag:no }
				# Standard Penalties.
				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 = {
					# Update gallowsbait score.
					laamp_rewards_apply_criminal_xp_effect = {
						TRACK = thief
						XP_MIN = gallowsbait_xp_minor_gain
						XP_MAX = gallowsbait_xp_minor_gain
					}
				}
			}
		}
	}
}

## Construction Work
# scope:employer = ruler wanting to build a holding
# task_contract_destination = province where the holding is being built
laamp_construction_contract = {
	group = laamp_contracts_transport_group
	icon = "gfx/interface/icons/vassal_stances/builder.dds"
	travel = no
	use_diplomatic_range = no

	# Validity Triggers
	valid_to_create = {
		# Standard triggers.
		valid_laamp_basic_trigger = {
			EMPLOYER = scope:employer
			LAAMP = root
		}
		employer_has_treasury_to_offer_job_trigger = yes
		valid_laamp_sensible_start_trigger = yes
		# Specific flavour triggers.
		scope:employer = {
			NOT = { government_has_flag = government_is_tribal }
			any_held_title = {
				county_has_empty_province_trigger = yes
			}
			short_term_gold > main_building_tier_1_cost
			OR = {
				has_trait = architect
				AND = {
					has_royal_court = yes
					employs_court_position = royal_architect_court_position
					any_court_position_holder = {
						type = royal_architect_court_position
						is_available_ai_adult = yes
					}
				}
				ai_has_builder_or_pious_builder_personality = yes 
			}
		}		
	}
	valid_to_keep = {
		var:task_contract_destination ?= {
			has_ongoing_construction = yes
		}
	}
	valid_to_accept = {
		# Standard triggers.
		valid_laamp_basic_accept_only_trigger = yes
		valid_laamp_basic_trigger = {
			EMPLOYER = scope:employer
			LAAMP = root
		}
	}
	valid_to_continue = {
		#once you are there, you need to stay to complete the contract
		trigger_if = {
			limit = {
				var:task_contract_destination.county = {
					has_county_modifier = massive_construction_efforts_modifier		
				}
			}
			task_contract_taker.capital_county = var:task_contract_destination.county
		}
		NOT = { #start_city_construction_decision invalidation
			var:task_contract_destination = {
				has_variable = laamp_city_construction
			}
		}
	}

	weight = {
		# Standard weights.
		value = task_contract_weight_default_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
			if = {
				limit = {
					NOT = { has_variable = task_contract_destination }
				}
				task_contract_employer = {
					ordered_held_title = {
						limit = { county_has_empty_province_trigger = yes }
						order_by = development_level
						random_county_province = {
							limit = { province_has_no_holding_trigger = yes }
							save_scope_as = task_contract_destination
							random_list = {
								1 = {
									begin_create_holding = {
										type = castle_holding
										refund_cost = { gold = 0 }
									}
								}
								1 = {
									modifier = {
										add = 10
										county = { county_has_no_city_trigger = yes }
									}
									begin_create_holding = {
										type = church_holding
										refund_cost = { gold = 0 }
									}
								}
								1 = {
									modifier = {
										add = 10
										county = { county_has_no_church_trigger = yes }
									}
									begin_create_holding = {
										type = city_holding
										refund_cost = { gold = 0 }
									}
								}
							}
						}
					}
					remove_short_term_gold = main_building_tier_1_cost
				}
				set_variable = {
					name = task_contract_destination
					value = scope:task_contract_destination
				}
			}
			else = {
				var:task_contract_destination = {
					save_scope_as = task_contract_destination
				}
			}
			# Make our gold rewards static.
			grab_gold_fuzz_number_effect = yes
			set_variable = {
				name = gold_success_standard
				value = task_contract_taker.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.task_contract_success_gold_gain_critical_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
		task_contract_taker = {
			trigger_event = ep3_contract_event.0001
		}
	}

	on_invalidated = {
		if = {
			limit = {
				root.task_contract_taker = {
					any_character_active_contract = {
						this = root
					}
				}
			}
			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
			}

			task_contract_taker = {
				set_variable = {
					name = invalidated_task_contract_type
					value = flag:laamp_construction_contract
				}
			}
			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
				
				}
			}
			var:task_contract_destination.county = {
				remove_county_modifier = massive_construction_efforts_modifier		
			}
			task_contract_taker = {
				remove_character_modifier = ep3_construction_contract_modifier
			}
		}
	}

	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 = {
					send_interface_toast = {
						title = laamp_transport_contract.success
						left_icon = scope:task_contract.task_contract_taker
						right_icon = scope:task_contract.task_contract_employer
						scope:task_contract.var:task_contract_destination = {
							switch = {
								trigger = has_holding_type
								castle_holding = {
									scope:task_contract.task_contract_taker = {
										add_prestige = task_contract_success_prestige_gain_critical_value
									}
								}
								church_holding = {
									scope:task_contract.task_contract_taker = {
										add_piety = task_contract_success_piety_gain_critical_value
									}
								}
								city_holding = {
									scope:task_contract.task_contract_taker = {
										add_gold = scope:task_contract.var:gold_success_standard
									}
								}
							}
						}
						if = {
							limit = {
								is_ai = no
							}
							scope:task_contract.task_contract_employer = {
								pay_short_term_gold = {
									target = scope:task_contract.task_contract_taker
									gold = scope:task_contract.var:gold_success_standard
								}
							}
						}
						else = {
							add_gold = scope:task_contract.var:gold_success_standard
						}
						reverse_add_opinion = {
							modifier = succeeded_task_contract_opinion
							target = scope:task_contract.task_contract_employer
							opinion = 20
						}
						# Huck 'em into our contact list.
						add_contact = scope:task_contract.task_contract_employer
					}
				}
			}
		}
		success_critical = {
			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 = {
					send_interface_toast = {
						title = laamp_transport_contract.success
						left_icon = scope:task_contract.task_contract_taker
						right_icon = scope:task_contract.task_contract_employer
						scope:task_contract.var:task_contract_destination = {
							switch = {
								trigger = has_holding_type
								castle_holding = {
									scope:task_contract.task_contract_taker = {
										add_prestige = task_contract_success_prestige_gain_full_value
									}
								}
								church_holding = {
									scope:task_contract.task_contract_taker = {
										add_piety = task_contract_success_piety_gain_full_value
									}
								}
								city_holding = {
									scope:task_contract.task_contract_taker = {
										add_gold = scope:task_contract.var:gold_success_critical
									}
								}
							}
						}
						if = {
							limit = {
								is_ai = no
							}
							scope:task_contract.task_contract_employer = {
								pay_short_term_gold = {
									target = scope:task_contract.task_contract_taker
									gold = scope:task_contract.var:gold_success_critical
								}
							}
						}
						else = {
							add_gold = scope:task_contract.var:gold_success_critical
						}
						reverse_add_opinion = {
							modifier = critically_succeeded_task_contract_opinion
							target = scope:task_contract.task_contract_employer
							opinion = 50
						}
						# 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
						}
					}
				}
			}
		}
		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 = {
					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
					}
				}
				var:task_contract_destination.county ?= {
					remove_county_modifier = massive_construction_efforts_modifier
				}
			}
		}
	}
}

## Treasure Hunting
# scope:employer = ruler wanting a treasure
# task_contract_destination = province where you go to find a treasure - set in the treasure_hunting_contract_decision decision
laamp_treasure_hunting_contract = {
	group = laamp_contracts_transport_group
	icon = "gfx/interface/icons/inspirations/adventure_inspiration.dds"
	travel = no
	use_diplomatic_range = no

	# Validity Triggers
	valid_to_create = {
		# Standard triggers.
		valid_laamp_basic_trigger = {
			EMPLOYER = scope:employer
			LAAMP = root
		}
		employer_has_treasury_to_offer_job_trigger = yes
		valid_laamp_sensible_start_trigger = yes
		# Specific flavour triggers.
		#There can only be one contract of this type at a time, so that the decision is easier to manage
		any_character_task_contract = {
			NOT = { has_task_contract_type = laamp_treasure_hunting_contract }
		}
		scope:employer = {
			highest_held_title_tier > tier_duchy
		}
	}
	valid_to_accept = {
		# Standard triggers.
		valid_laamp_basic_accept_only_trigger = yes
		valid_laamp_basic_trigger = {
			EMPLOYER = scope:employer
			LAAMP = root
		}
	}
	valid_to_continue = {
		# Standard triggers.
		valid_laamp_basic_trigger = {
			EMPLOYER = root.task_contract_employer
			LAAMP = root.task_contract_taker
		}
	}
	valid_to_keep = {
		# Standard triggers.
		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_transport_value
		add = task_contract_weight_employer_contact_list_value
		scope:employer = { multiply = task_contract_weight_by_tier_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
		task_contract_taker = {
			save_scope_as = task_contract_taker
		}
		task_contract_employer = {
			save_scope_as = task_contract_employer
		}
		scope:task_contract_taker = {
			trigger_event = ep3_contract_event.0005
		}
	}

	on_invalidated = {
		if = {
			limit = {
				root.task_contract_taker = {
					any_character_active_contract = {
						this = root
					}
				}
			}
			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
			}
			task_contract_taker = {
				set_variable = {
					name = invalidated_task_contract_type
					value = flag:laamp_treasure_hunting_contract
				}
			}
			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
				
				}
			}
		}
	}

	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 = {
					send_interface_toast = {
						title = laamp_transport_contract.success
						left_icon = scope:task_contract.task_contract_taker
						right_icon = scope:task_contract.task_contract_employer
						add_prestige = task_contract_success_prestige_gain_full_value
						if = {
							limit = {
								is_ai = no
							}
							scope:task_contract.task_contract_employer = {
								pay_short_term_gold = {
									target = scope:task_contract.task_contract_taker
									gold = task_contract_success_gold_gain_full_value
								}
							}
						}
						else = {
							add_short_term_gold = task_contract_success_gold_gain_full_value
						}
						reverse_add_opinion = {
							modifier = succeeded_task_contract_opinion
							target = scope:task_contract.task_contract_employer
							opinion = 20
						}
						# 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
						}
					}
				}
			}
		}
		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 = {
					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
					}
				}
			}
		}
	}
}

## Protect Heritage
# scope:employer = a minority vassal of the same culture as root wanting to get title revocation rights vassal contract
# task_contract_target = liege of task_contract_employer
# task_contract_destination = capital of task_contract_employer
laamp_cultural_minority_contract = {
	group = laamp_contracts_diplomacy_group
	icon = "gfx/interface/icons/character_interactions/icon_culture.dds"
	travel = yes
	use_diplomatic_range = no

	# Validity Triggers
	valid_to_create = {
		# Standard triggers.
		valid_laamp_basic_trigger = {
			EMPLOYER = scope:employer
			LAAMP = root
		}
		employer_has_treasury_to_offer_job_trigger = yes
		valid_laamp_sensible_start_trigger = yes
		# Specific flavour triggers.
		scope:employer = {
			top_liege != this
			has_vassal_stance = minority
			liege ?= {
				is_ai = yes
			}
			vassal_contract_obligation_level_can_be_increased = title_revocation_rights
			culture = {
				this != scope:employer.liege.culture
			}
		}
	}
	valid_to_accept = {
		# Standard triggers.
		valid_laamp_basic_accept_only_trigger = yes
		valid_laamp_basic_trigger = {
			EMPLOYER = scope:employer
			LAAMP = root
		}
	}
	valid_to_continue = {
		save_temporary_scope_as = task_contract
		var:task_contract_target = {
			any_vassal = {
				scope:task_contract.var:task_contract_employer = this
			}
		}
		# Standard triggers.
		valid_laamp_basic_trigger = {
			EMPLOYER = root.task_contract_employer
			LAAMP = root.task_contract_taker
		}
	}
	valid_to_keep = {
		# Standard triggers.
		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_diplomacy_value
		add = laamp_contracts_weight_up_diplomacy_slight_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
			task_contract_employer = {
				liege = {
					save_scope_as = task_contract_target
				}
				capital_province = {
					save_scope_as = task_contract_destination
				}
			}
			set_task_contract_target = scope:task_contract_target
			set_variable = {
				name = task_contract_employer
				value = scope:task_contract.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	
			}
			# Make our gold rewards static.
			grab_gold_fuzz_number_effect = yes
			set_variable = {
				name = gold_success_standard
				value = task_contract_taker.task_contract_success_gold_gain_full_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
		task_contract_taker = {
			trigger_event = ep3_contract_event.0020
		}
	}

	on_invalidated = {
		if = {
			limit = {
				root.task_contract_taker = {
					any_character_active_contract = {
						this = root
					}
				}
			}
			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_cultural_minority_contract
				}
			}
			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 = {
					scope:task_contract_target = {
						any_vassal = {
							count = all
							scope:task_contract_employer != this
						}
					}
				}
				task_contract_taker = {
					save_scope_value_as = {
						name = task_contract_invalidation_reason
						value = flag:not_vassal
					}
					trigger_event = ep3_contract_event.0012
				}
			}
		}
	}

	# 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 = {
					send_interface_toast = {
						type = event_toast_effect_good
						title = laamp_transport_contract.success
						left_icon = scope:task_contract.task_contract_taker
						right_icon = scope:task_contract.task_contract_employer
						root = {
							save_scope_value_as = { name = extra_reward value = flag:no }
							# Standard Rewards.
							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 = 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
							}
						}
						if = {
							limit = {
								scope:task_contract.task_contract_taker.culture != scope:task_contract.task_contract_employer.culture
							}
							scope:task_contract.task_contract_taker.culture = {
								change_cultural_acceptance = {
									target = scope:task_contract.task_contract_employer.culture
									value = low_positive_culture_acceptance
									desc = cultural_acceptance_laamp_cultural_minority_contract
								}
							}
						}
						show_as_tooltip = {
							scope:task_contract.task_contract_employer = {
								vassal_contract_set_obligation_level = {
									type = title_revocation_rights
									level = 1
								}
							}
						}
					}
				}
			}
		}		
		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 = {
					send_interface_toast = {
						type = event_toast_effect_bad
						title = laamp_transport_contract.transport_failed
						root = {
							save_scope_value_as = { name = extra_reward value = flag:no }
							# Standard Penalties.
							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
							}
						}
					}
				}
			}
		}
	}
}

## Reward the Faithful
# scope:employer = a minority vassal of the same faith as root wanting to get religious rights vassal contract
# task_contract_target = liege of task_contract_employer
# task_contract_destination = capital of task_contract_employer
laamp_religious_minority_contract = {
	group = laamp_contracts_diplomacy_group
	icon = "gfx/interface/icons/character_interactions/religious.dds"
	travel = yes
	use_diplomatic_range = no

	# Validity Triggers
	valid_to_create = {
		# Standard triggers.
		valid_laamp_basic_trigger = {
			EMPLOYER = scope:employer
			LAAMP = root
		}
		employer_has_treasury_to_offer_job_trigger = yes
		valid_laamp_sensible_start_trigger = yes
		# Specific flavour triggers.
		scope:employer = {
			top_liege != this
			has_vassal_stance = minority
			liege ?= {
				is_ai = yes
			}
			vassal_contract_obligation_level_can_be_increased = religious_rights
			faith != liege.faith
		}
	}
	valid_to_accept = {
		# Standard triggers.
		valid_laamp_basic_accept_only_trigger = yes
		valid_laamp_basic_trigger = {
			EMPLOYER = scope:employer
			LAAMP = root
		}
	}
	valid_to_continue = {
		save_temporary_scope_as = task_contract
		var:task_contract_target = {
			any_vassal = {
				scope:task_contract.var:task_contract_employer = this
			}
		}
		# Standard triggers.
		valid_laamp_basic_trigger = {
			EMPLOYER = root.task_contract_employer
			LAAMP = root.task_contract_taker
		}
	}
	valid_to_keep = {
		# Standard triggers.
		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_diplomacy_value
		add = laamp_contracts_weight_up_diplomacy_slight_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
			task_contract_employer = {
				liege = {
					save_scope_as = task_contract_target
				}
				capital_province = {
					save_scope_as = task_contract_destination
				}
			}
			set_task_contract_target = scope:task_contract_target
			set_variable = {
				name = task_contract_employer
				value = scope:task_contract.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	
			}
			# Make our gold rewards static.
			grab_gold_fuzz_number_effect = yes
			set_variable = {
				name = gold_success_standard
				value = task_contract_taker.task_contract_success_gold_gain_full_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
		task_contract_taker = {
			trigger_event = ep3_contract_event.0021
		}
	}

	on_invalidated = {
		if = {
			limit = {
				root.task_contract_taker = {
					any_character_active_contract = {
						this = root
					}
				}
			}
			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_religious_minority_contract
				}
			}
			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 = {
					scope:task_contract_target = {
						any_vassal = {
							count = all
							scope:task_contract_employer != this
						}
					}
				}
				task_contract_taker = {
					save_scope_value_as = {
						name = task_contract_invalidation_reason
						value = flag:not_vassal
					}
					trigger_event = ep3_contract_event.0012
				}
			}
		}
	}

	# 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 = {
					send_interface_toast = {
						type = event_toast_effect_good
						title = laamp_transport_contract.success
						left_icon = scope:task_contract.task_contract_taker
						right_icon = scope:task_contract.task_contract_employer
						save_scope_value_as = { name = extra_reward value = flag:no }
						root = {
							# Standard Rewards.
							laamp_rewards_disburse_ordinary_currency_effect = {
								GOLD = 0
								PRESTIGE = 0
								PIETY = task_contract_success_piety_gain_full_value
								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
							}
						}
						show_as_tooltip = {
							scope:task_contract.task_contract_employer = {
								vassal_contract_set_obligation_level = {
									type = religious_rights
									level = 1
								}
							}
						}
					}
				}
			}
		}		
		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 = {
					send_interface_toast = {
						type = event_toast_effect_bad
						title = laamp_transport_contract.transport_failed
						save_scope_value_as = { name = extra_reward value = flag:no }
						root = {
							# Standard Penalties.
							laamp_rewards_disburse_ordinary_currency_effect = {
								GOLD = 0
								PRESTIGE = 0
								PIETY = task_contract_failure_piety_loss_full_value
								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
							}
						}
					}
				}
			}
		}
	}
}

## Prison Break
# scope:employer = a character that has a spouse, family member, soulmate or best friend imprisoned by another character
# task_contract_target = imprisoner
# task_contract_destination = capital of task_contract_target
# task_contract_object = the imprisoned character to be rescued
laamp_prison_break_contract = {
	group = laamp_contracts_intrigue_group
	icon = "gfx/interface/icons/casus_bellis/fp3_free_house_member.dds"
	travel = no
	use_diplomatic_range = no

	# Validity Triggers
	valid_to_create = {
		# Standard triggers.
		valid_laamp_basic_trigger = {
			EMPLOYER = scope:employer
			LAAMP = root
		}
		employer_has_treasury_to_offer_job_trigger = yes
		valid_laamp_sensible_start_trigger = yes
		# Specific flavour triggers.
		scope:employer = {
			OR = {
				any_spouse = {
					is_imprisoned = yes
					NOR = {
						is_imprisoned_by = scope:employer
						is_imprisoned_by = root
					}
				}
				any_close_family_member = {
					is_imprisoned = yes
					NOR = {
						is_imprisoned_by = scope:employer
						is_imprisoned_by = root
					}		
				}
				any_relation = {
					type = soulmate
					is_imprisoned = yes
					NOR = {
						is_imprisoned_by = scope:employer
						is_imprisoned_by = root
					}
				}
				any_relation = {
					type = best_friend
					is_imprisoned = yes
					NOR = {
						is_imprisoned_by = scope:employer
						is_imprisoned_by = root
					}
				}
			}
		}
	}
	valid_to_keep = {
		exists = root.var:task_contract_object
		root.var:task_contract_object = {
			is_imprisoned = yes
		}
		# Standard triggers.
		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
		}
	}
	valid_to_continue = {
		var:task_contract_object ?= {
			is_imprisoned = yes
			is_alive = yes
		}
		# Standard triggers.
		valid_laamp_basic_trigger = {
			EMPLOYER = root.task_contract_employer
			LAAMP = root.task_contract_taker
		}
	}
	weight = {
		# Standard weights.
		value = task_contract_weight_interesting_very_rare_value
		add = laamp_contracts_weight_up_intrigue_value
		scope:employer = {
			if = {
				limit = { has_trait = compassionate }
				add = task_contract_weight_bonus_employer_has_associated_traits_value
			}
			multiply = task_contract_weight_by_tier_value
		}
		add = task_contract_weight_employer_contact_list_value
	}

	on_create = {
		scope:contract = {
			save_scope_as = task_contract
			task_contract_employer = {
				every_spouse = {
					limit = {
						is_imprisoned = yes
						NOR = {
							is_imprisoned_by = scope:task_contract.task_contract_employer
							is_imprisoned_by = scope:task_contract.task_contract_taker
						}
					}
					add_to_list = character_to_breakout
				}
				every_close_family_member = {
					limit = {
						is_imprisoned = yes
						NOR = {
							is_imprisoned_by = scope:task_contract.task_contract_employer
							is_imprisoned_by = scope:task_contract.task_contract_taker
						}	
					}
					add_to_list = character_to_breakout
				}
				every_relation = {
					type = soulmate
					limit = {
						is_imprisoned = yes
						NOR = {
							is_imprisoned_by = scope:task_contract.task_contract_employer
							is_imprisoned_by = scope:task_contract.task_contract_taker
						}
					}
					add_to_list = character_to_breakout
				}
				every_relation = {
					type = best_friend
					limit = {
						is_imprisoned = yes
						NOR = {
							is_imprisoned_by = scope:task_contract.task_contract_employer
							is_imprisoned_by = scope:task_contract.task_contract_taker
						}
					}
					add_to_list = character_to_breakout
				}
				ordered_in_list = {
					list = character_to_breakout
					order_by = prison_break_value	
					save_scope_as = task_contract_object
				}
			}
			set_variable = {
				name = task_contract_employer
				value = scope:task_contract.task_contract_employer
			}
			set_variable = {
				name = task_contract_object
				value = scope:task_contract_object
			}
			scope:task_contract_object = {
				imprisoner = {
					save_scope_as = task_contract_target
					capital_province = {
						save_scope_as = task_contract_destination
					}
				}
				add_character_flag = being_prisonbroken_by_laamp
			}
			set_task_contract_target = scope:task_contract_target
			set_variable = {
				name = task_contract_target
				value = scope:task_contract_target
			}
			set_variable = {
				name = task_contract_destination
				value = scope:task_contract_destination
			}
			# Make our gold rewards static.
			grab_gold_fuzz_number_effect = yes
			set_variable = {
				name = gold_success_standard
				value = task_contract_taker.task_contract_success_gold_gain_full_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
		task_contract_taker = {
			trigger_event = ep3_contract_event.0030
		}
	}

	on_invalidated = {
		if = {
			limit = {
				root.task_contract_taker = {
					any_character_active_contract = {
						this = root
					}
				}
			}
			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
			}
			var:task_contract_object = {
				save_scope_as = task_contract_object
			}
			task_contract_taker = {
				set_variable = {
					name = invalidated_task_contract_type
					value = flag:laamp_prison_break_contract
				}
			}
			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 = {
					scope: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 = {
					scope:task_contract_object = {
						is_imprisoned = no
					}
				}
				task_contract_taker = {
					save_scope_value_as = {
						name = task_contract_invalidation_reason
						value = flag:prisoner_free
					}
					trigger_event = ep3_contract_event.0012
				}
			}
		}
	}

	# 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 = {
					send_interface_toast = {
						type = event_toast_effect_good
						title = laamp_transport_contract.success
						left_icon = scope:task_contract.task_contract_taker
						right_icon = scope:task_contract.task_contract_employer
						save_scope_value_as = { name = extra_reward value = flag:no }
						# Standard Rewards.
						scope:task_contract = {
							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 = 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
							}
						}
						scope:task_contract.var:task_contract_object = {
							scope:task_contract.var:task_contract_target = {
								save_scope_as = imprisoner
							}
							escape_from_prison_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 = {
					send_interface_toast = {
						type = event_toast_effect_bad
						title = laamp_transport_contract.transport_failed
						left_icon = scope:task_contract.task_contract_taker
						right_icon = scope:task_contract.task_contract_employer
						save_scope_value_as = { name = extra_reward value = flag:no }
						# Standard Penalties.
						scope:task_contract = {
							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
							}
						}
					}
				}
			}
		}
	}
}

## Treasure Map
# scope:employer = root
# task_contract_target = root
# contract_treasure_location = ep3_laamp_decision_event.1025
# contract_picked_up_in_location = ep3_laamp_decision_event.1025
laamp_treasure_map_contract = {
	group = laamp_contracts_noticeboard_group #These are created in the Visit Local Settlement-decision
	icon = "gfx/interface/icons/character_interactions/icon_contract_escort.dds"

	# Validity Triggers
	valid_to_create = {
		# Standard triggers.
		valid_laamp_basic_trigger = {
			EMPLOYER = scope:employer
			LAAMP = root
		}
		employer_has_treasury_to_offer_job_trigger = yes
		valid_laamp_sensible_start_trigger = yes
		# Specific flavour triggers.
		#There can only be one contract of this type at a time
		any_task_contract = {
			NOT = { has_task_contract_type = laamp_treasure_map_contract }
		}
	}
	valid_to_accept = {
		# Standard triggers.
		valid_laamp_basic_accept_only_trigger = yes
		valid_laamp_basic_trigger = {
			EMPLOYER = scope:employer
			LAAMP = root
		}
		#We're not already enrolled in a treasure map contract
		NOT = { 
			any_character_artifact = { has_variable = 1025_treasure_map } 
		}
	}
	valid_to_continue = {
		#We haven't already located the treasure
		trigger_if = {
			limit = {
				NOT = { has_variable = 0045_used_map }
			}
			root.task_contract_taker = {
				any_character_artifact = { has_variable = 1025_treasure_map }
			}
		}
		#The employer is still alive and free
		root.task_contract_employer = { 
			is_alive = yes
			is_imprisoned = no
			NOT = { has_trait = incapable }
		}
		# Standard triggers.
		valid_laamp_basic_trigger = {
			EMPLOYER = root.task_contract_employer
			LAAMP = root.task_contract_taker
		}
	}
	valid_to_keep = {
		# Standard triggers.
		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_transport_value
		add = task_contract_weight_employer_contact_list_value
		scope:employer = { multiply = task_contract_weight_by_tier_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
		task_contract_taker = { save_scope_as = task_contract_taker }
		task_contract_employer = { save_scope_as = task_contract_employer }

		#Create quest item Treasure Map
		scope:task_contract_taker = {
			create_artifact = {
				name = treasure_map
				description = treasure_map_desc
				modifier = artifact_monthly_minor_prestige_1_modifier
				type = miscellaneous
				visuals = pocket_map
				max_durability = 10
				history = { 
					type = given
					actor = scope:task_contract_employer
					recipient = scope:task_contract_taker
					location = scope:task_contract.var:contract_picked_up_in_location
				}
				save_scope_as = newly_created_map
			}
			#Set variables
			scope:newly_created_map ?= { 
				set_variable = 1025_treasure_map
				set_variable = {
					name = picked_up_in_location
					value = scope:task_contract.var:contract_picked_up_in_location
				}
				set_variable = {
					name = artifact_treasure_location
					value = scope:task_contract.var:contract_treasure_location
				}
				if = {
					limit = { 
						exists = var:picked_up_in_location
						exists = var:artifact_treasure_location
					}
					set_artifact_description = treasure_map_desc
				}
			}
			#Chuck the employer in there as well
			add_courtier = scope:task_contract_employer
			scope:task_contract_employer = {
				add_character_flag = {
					flag = blocked_from_leaving
					years = 11 #The map should break first, and is set to 10 years
				}
			}
			trigger_event = ep3_contract_event.0043
		}
	}

	#Employer died? Map decayed?
	on_invalidated = {
		#Employer unavailable
		if = { 
			limit = {
				task_contract_employer = { 
					OR = {
						is_alive = no
						has_trait = incapable
						is_imprisoned = yes
					}
				}
			}
			task_contract_employer = { save_scope_as = task_contract_employer }
			#Save the location of the employer
			var:contract_picked_up_in_location = { save_scope_as = original_contract_location }
			#Save contract
			save_scope_as = task_contract
			#Save tier, realistically always 1
			save_scope_value_as = {
				name = task_contract_tier
				value = root.task_contract_tier
			}
			#Save the destination
			var:contract_treasure_location ?= { save_scope_as = task_contract_destination }
			#Destroy the historical artifact if the LAAMP is an AI
			if = {
				limit = { 
					has_variable = has_unique_historical_artifact
					task_contract_taker = { is_ai = yes }
				}
				var:has_unique_historical_artifact = { save_scope_as = historical_artifact }
				hidden_effect = { destroy_artifact = scope:historical_artifact }
			}
			#Send the appropriate event
			task_contract_taker = {
				set_variable = {
					name = invalidated_task_contract_type
					value = flag:laamp_treasure_map_contract
				}
				#Dead
				if = {
					limit = { 
						scope:task_contract_employer = { is_alive = no }
					}
					trigger_event = ep3_contract_event.0041
				}
				#Incapable
				if = {
					limit = { 
						scope:task_contract_employer = { has_trait = incapable }
					}
					trigger_event = ep3_contract_event.0041
				}
				#Imprisoned
				if = {
					limit = { 
						scope:task_contract_employer = { is_imprisoned = yes }
					}
					#Save the invalidation flag
					save_scope_value_as = {
						name = task_contract_invalidation_reason
						value = flag:unlanded_employer_is_imprisoned
					}
					trigger_event = ep3_contract_event.0012
				}
			}
			#No longer excavating
			remove_variable ?= ep3_laamp_decision_1000_is_excavating
		}
		#Decay-destroyed map is handled via on_artifact_broken_through_decay, leading to ep3_contract_event.0040
	}

	task_contract_reward = {
		#Something to display in the Contract Reward window. Not actually used.
		success_qualified = {
			effect = {
				save_scope_as = task_contract
				if = { # Camp building extra Criminal Rewards: +50%.
					limit = {
						task_contract_taker.domicile ?= { has_domicile_parameter = camp_improved_criminal_contract_rewards }
					}
					save_scope_value_as = { name = extra_reward value = flag:yes }
				}
				else = { # Standard Reward.
					save_scope_value_as = { name = extra_reward value = flag:no }
				}
				#Check for provision overflows
				save_scope_value_as = {
					name = provisions_to_add_value
					value = {
						value = task_contract_taker.domicile.max_provisions
						max = old_adventurer_stashed_provisions_value
					}
				}
				save_scope_value_as = {
					name = total_provisions_after_reward_value
					value = {
						value = task_contract_taker.domicile.provisions
						add = scope:provisions_to_add_value
					}
				}
				#If there is an overflow
				if = {
					limit = { scope:total_provisions_after_reward_value > task_contract_taker.domicile.max_provisions }
					save_scope_value_as = {
						name = provisions_to_add_value
						value = {
							value = task_contract_taker.domicile.max_provisions
							subtract = task_contract_taker.domicile.provisions
						}
					}
					save_scope_value_as = {
						name = provisions_overflow_value
						value = {
							value = scope:total_provisions_after_reward_value
							subtract = task_contract_taker.domicile.max_provisions
						}
					}
					save_scope_value_as = {
						name = provisions_transformed_to_gold_value
						value = {
							value = scope:total_provisions_after_reward_value
							subtract = task_contract_taker.domicile.max_provisions
							multiply = 0.05
						}
					}
				}
				task_contract_taker = {
					scope:task_contract.task_contract_employer = {
						pay_short_term_gold = {
							target = scope:task_contract.task_contract_taker
							gold = {
								value = {
									value = old_adventurer_stashed_gold_value
									#Extra rewards
									if = {
										limit = { scope:extra_reward = flag:yes }
										multiply = task_contract_extra_reward_multiplier_value
									}
								}
							}
						}
					}	
					stress_impact = {
						base = major_stress_impact_loss
						honest = minor_stress_impact_loss
					}		
					#1000 seems like a fine, round number for some old adventurer to have stashed somewhere
					domicile ?= {
						change_provisions = {
							#We're capped
							if = {
								limit = { provisions >= max_provisions }
								value = 0 #No provisions, you're full
							}
							#We're not capped and our max cap is less than 1000
							else_if = {
								limit = { max_provisions < old_adventurer_stashed_provisions_value }
								value = {
									value = max_provisions
									subtract = provisions
								}
							}
							#We're not capped and our max cap is equal to -or more- than 1000
							else = { 
								value = {
									value = max_provisions
									subtract = provisions
									max = old_adventurer_stashed_provisions_value
								}
							}
						}
					}
					#Inform the player about the overflow
					if = {
						limit = { exists = scope:provisions_transformed_to_gold_value }
						custom_tooltip = {
							text = overflowing_provisions_to_gold.tt
							add_gold = scope:provisions_transformed_to_gold_value
						}
					}
				}
			}
		}
		#Handled in ep3_contract_event.0050
		success_standard = {
			visible = no
			effect = {
				task_contract_taker = { play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_success_on_contract" }
				save_scope_as = task_contract
				if = { # Camp building extra Criminal Rewards: +50%.
					limit = {
						task_contract_taker.domicile ?= { has_domicile_parameter = camp_improved_criminal_contract_rewards }
					}
					save_scope_value_as = { name = extra_reward value = flag:yes }
				}
				else = { # Standard Reward.
					save_scope_value_as = { name = extra_reward value = flag:no }
				}
				#Check for provision overflows
				if = {
					limit = { task_contract_taker.domicile.max_provisions < old_adventurer_stashed_provisions_value }
					save_scope_value_as = {
						name = provisions_to_add_value
						value = task_contract_taker.domicile.max_provisions
					}
				}
				else = {
					save_scope_value_as = {
						name = provisions_to_add_value 
						value = old_adventurer_stashed_provisions_value
					}
				}
				save_scope_value_as = {
					name = total_provisions_after_reward_value
					value = {
						value = task_contract_taker.domicile.provisions
						add = scope:provisions_to_add_value
					}
				}
				#If there is an overflow
				if = {
					limit = { scope:total_provisions_after_reward_value > task_contract_taker.domicile.max_provisions }
					save_scope_value_as = {
						name = provisions_to_add_value
						value = {
							value = task_contract_taker.domicile.max_provisions
							subtract = task_contract_taker.domicile.provisions
						}
					}
					save_scope_value_as = {
						name = provisions_overflow_value
						value = {
							value = scope:total_provisions_after_reward_value
							subtract = task_contract_taker.domicile.max_provisions
						}
					}
					save_scope_value_as = {
						name = provisions_transformed_to_gold_value
						value = {
							value = scope:total_provisions_after_reward_value
							subtract = task_contract_taker.domicile.max_provisions
							multiply = 0.05
						}
					}
				}
				#The actual toast
				task_contract_taker = {
					send_interface_toast = {
						title = laamp_transport_contract.success
						left_icon = scope:task_contract.task_contract_taker
						right_icon = scope:task_contract.task_contract_employer
						#Historical Artifact 'transferred owner'
						if = {
							limit = { 
								scope:task_contract = { has_variable = has_unique_historical_artifact }
							}
							scope:task_contract = {
								var:has_unique_historical_artifact = { save_scope_as = historical_artifact }
							}
							show_as_tooltip = {
								scope:historical_artifact = { set_owner = scope:task_contract.task_contract_employer }
							}
						}
						#Random Jewellry 'transferred owner'
						if = {
							limit = { 
								scope:task_contract = { has_variable = has_jewelry_artifact }
							}
							scope:task_contract = {
								var:has_jewelry_artifact = { save_scope_as = jewelry_artifact }
							}
							show_as_tooltip = {
								scope:jewelry_artifact = { set_owner = scope:task_contract.task_contract_employer }
							}
						}
						#Gold reward
						if = {
							limit = { is_ai = no }
							scope:task_contract.task_contract_employer = {
								if = {
									limit = { exists = scope:historical_artifact }
									scope:task_contract.task_contract_employer = {
										pay_short_term_gold = {
											target = scope:task_contract.task_contract_taker
											gold = {
												value = {
													value = old_adventurer_stashed_gold_value
													multiply = 4
													#Extra rewards
													if = {
														limit = { scope:extra_reward = flag:yes }
														multiply = task_contract_extra_reward_multiplier_value
													}
												}
											}
										}
									}
								}
								else_if = {
									limit = { exists = scope:jewelry_artifact }
									pay_short_term_gold = {
										target = scope:task_contract.task_contract_taker
										gold = {
											value = {
												value = old_adventurer_stashed_gold_value
												multiply = {
													value = scope:task_contract.var:has_jewelry_artifact.artifact_rarity
													subtract = 1
												}
												#Extra rewards
												if = {
													limit = { scope:extra_reward = flag:yes }
													multiply = task_contract_extra_reward_multiplier_value
												}
											}
										}
									}
								}
								else_if = {
									limit = {
										scope:task_contract = { has_variable = treasure_gold_great }
									}
									pay_short_term_gold = {
										target = scope:task_contract.task_contract_taker
										gold = {
											value = {
												value = old_adventurer_stashed_gold_value
												multiply = 1.5
												#Extra rewards
												if = {
													limit = { scope:extra_reward = flag:yes }
													multiply = task_contract_extra_reward_multiplier_value
												}
											}
										}
									}
								}
								else_if = {
									limit = {
										scope:task_contract = {
											OR = {
												has_variable = treasure_gold_mediocre
												has_variable = treasure_gold_poor
											}
										}
									}
									pay_short_term_gold = {
										target = scope:task_contract.task_contract_taker
										gold = {
											value = {
												value = old_adventurer_stashed_gold_value
												multiply = 1.25	
												#Extra rewards
												if = {
													limit = { scope:extra_reward = flag:yes }
													multiply = task_contract_extra_reward_multiplier_value
												}
											}
										}
									}
								}
								else_if = {
									limit = {
										scope:task_contract = { has_variable = treasure_pillaged }
									}
									pay_short_term_gold = {
										target = scope:task_contract.task_contract_taker
										gold = {
											value = {
												value = old_adventurer_stashed_gold_value
												#Extra rewards
												if = {
													limit = { scope:extra_reward = flag:yes }
													multiply = task_contract_extra_reward_multiplier_value
												}
											}
										}
									}
								}
							}	
						}
						#For AI
						else = {
							add_short_term_gold = {
								value = {
									value = old_adventurer_stashed_gold_value
									#Extra rewards
									if = {
										limit = { scope:extra_reward = flag:yes }
										multiply = task_contract_extra_reward_multiplier_value
									}
								}
							}
						}
						#Prestige reward
						if = {
							limit = { exists = scope:historical_artifact }
							add_prestige = {
								value = {
									value = major_prestige_gain
									#Extra rewards
									if = {
										limit = { scope:extra_reward = flag:yes }
										multiply = task_contract_extra_reward_multiplier_value
									}
								}
							}
						}
						#Stress loss -- less stress loss if you gained more gold and vice versa (for doing a good thing)
						if = {
							limit = {
								NOT = { exists = scope:historical_artifact }
							}
							if = {
								limit = {
									OR = {
										exists = scope:jewelry_artifact
										scope:task_contract = { has_variable = treasure_gold_great }
									}
								}
								stress_impact = {
									base = minor_stress_impact_loss
									honest = minor_stress_impact_loss
								}
							}
							else_if = {
								limit = {
									scope:task_contract = {
										OR = {
											has_variable = treasure_gold_mediocre
											has_variable = treasure_gold_poor
										}
									}
								}
								stress_impact = {
									base = medium_stress_impact_loss
									honest = minor_stress_impact_loss
								}
							}
							else_if = {
								limit = {
									scope:task_contract = { has_variable = treasure_pillaged }
								}
								stress_impact = {
									base = major_stress_impact_loss
									honest = minor_stress_impact_loss
								}
							}
						}
						#Lose some Gallowsbait xp
						if = {
							limit = {
								#... you can't steal a view
								NOT = { 
									scope:task_contract = { has_variable = has_scenic_riches }
								}
							}
							#Lose some Gallowsbait xp
							if = {
								limit = { 
									has_trait = gallowsbait
									has_trait_xp = {
										trait = gallowsbait
										track = thief
										value > 0
									}
								}
								laamp_rewards_apply_criminal_xp_effect = {
									TRACK = thief
									XP_MIN = negative_small_lifestyle_random_xp_low
									XP_MAX = negative_small_lifestyle_random_xp_low
								}
							}
						}
						#Inform the player about the overflow
						if = {
							limit = { exists = scope:provisions_transformed_to_gold_value }
							custom_tooltip = {
								text = overflowing_provisions_to_gold.tt
								add_gold = scope:provisions_transformed_to_gold_value
							}
						}
						#Throw the historical artifact back in the pool
						if = {
							limit = { exists = scope:historical_artifact }
							hidden_effect = { destroy_artifact = scope:historical_artifact }
						}
					}		
					#1000 seems like a fine, round number for some old adventurer to have stashed somewhere
					domicile ?= {
						change_provisions = {
							#We're capped
							if = {
								limit = { provisions = max_provisions }
								value = 0 #No provisions, you're full
							}
							#We're not capped and our max cap is less than 1000
							else_if = {
								limit = { max_provisions < old_adventurer_stashed_provisions_value }
								value = {
									value = max_provisions
									subtract = provisions
								}
							}
							#We're not capped and our max cap is equal to -or more- than 1000
							else = { 
								value = {
									value = max_provisions
									subtract = provisions
									max = old_adventurer_stashed_provisions_value
								}
							}
						}
					}
					#Sweep, sweep.
					hidden_effect = {
						if = {
							limit = {
								any_character_artifact = { has_variable = 1025_treasure_map }
							}
							random_character_artifact = {
								limit = { has_variable = 1025_treasure_map }
								destroy_artifact = this
							}
						}
					}
					#No longer excavating
					remove_variable ?= ep3_laamp_decision_1000_is_excavating
				}
			}
		}
		#Handled in ep3_contract_event.0045
		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
				scope:task_contract = {
					if = {
						limit = { has_variable = has_unique_historical_artifact }
						task_contract_taker = { #Pretty inconsequential, since you couldn't really determine ahead of time
							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
								#And this adventurer doesn't want to see you again
								progress_towards_rival_effect = {
									REASON = rival_mia_contract
									CHARACTER = scope:task_contract.task_contract_employer
									OPINION = 0
								}
								reverse_add_opinion = {
									modifier = stole_artifact_from_me
									target = scope:task_contract.task_contract_employer
									opinion = -50
								}
								add_prestige = medium_prestige_loss
							}
						}	
					}
					else = {
						task_contract_taker = { #Pretty inconsequential, since you couldn't really determine ahead of time
							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
								#And this adventurer doesn't want to see you again
								hidden_effect = { #For narrative reasons. For mechanical reasons, this character won't get picked in Visit Settlement again
									progress_towards_rival_effect = {
										REASON = rival_mia_contract
										CHARACTER = scope:task_contract.task_contract_employer
										OPINION = 0
									}
								}	
								reverse_add_opinion = {
									modifier = disappointed_opinion
									target = scope:task_contract.task_contract_employer
									opinion = -30
								}
								add_prestige = minor_prestige_loss
							}
						}	
					}
					task_contract_taker = {
						#Sweep, sweep. (Let the player know the map will be destroyed when failing)
						if = {
							limit = {
								any_character_artifact = { has_variable = 1025_treasure_map }
							}
							random_character_artifact = {
								limit = { has_variable = 1025_treasure_map }
								destroy_artifact = this
							}
						}
						#No longer excavating
						remove_variable ?= ep3_laamp_decision_1000_is_excavating
					}
				}
			}
		}
	}
}


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.
		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
		any_claim = {
			exists = holder
			tier >= tier_kingdom
			holder != scope:employer
		}
	}

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

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

	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 = {
			trigger_event = ep3_laamps.8101
		}
	}

	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 = laamp_legitimist_support_contract_success
				}
			}
		}
		failure_standard = {
			positive = no
			effect = {
				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
				}
			}
		}
	}
}

## Support Faction
# scope:employer = ruler needing help in a faction
# scope:task_contract_faction = faction to join
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 = {
		# Standard triggers.
		valid_laamp_basic_trigger = {
			EMPLOYER = scope:employer
			LAAMP = root
		}
		employer_has_treasury_to_offer_job_trigger = yes
		# Specific flavour triggers.
		scope:employer = {
			is_a_faction_member = yes
			joined_faction = {
				save_temporary_scope_as = temp_faction
			}
		}
		is_a_faction_member = no
		#don't spawn contracts for the same factions or faction targets
		NOT = {
			any_character_task_contract = {
				task_contract_type = laamp_join_faction_contract
				OR = {
					var:task_contract_faction ?= scope:temp_faction
					task_contract_employer = scope:temp_faction.faction_target
				}
			}
		}
		is_adult = yes
		is_imprisoned = no
		NOR = {
			is_allied_to = scope:temp_faction.faction_target
			scope:temp_faction.faction_target = { has_strong_hook = root }
			has_trait = incapable
			has_character_flag = joining_faction_block
			has_relation_friend = scope:temp_faction.faction_target
			has_relation_lover = scope:temp_faction.faction_target
			has_secret_relation_lover = scope:temp_faction.faction_target
			scope:temp_faction.faction_target = { is_contact_of = root }
		}
	}
	valid_to_keep = {
		exists = root.var:task_contract_faction
		# Standard triggers.
		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 = {
					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.
		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 = {
				joined_faction = {
					save_scope_as = task_contract_faction
				}
				save_scope_as = task_contract_employer
			}
			set_variable = {
				name = task_contract_faction
				value = scope:task_contract_faction
			}
			set_variable = {
				name = task_contract_employer
				value = scope:task_contract_employer
			}
			scope:task_contract_faction = {
				faction_target = {
					save_scope_as = task_contract_target
				}
			}
			set_task_contract_target = scope:task_contract_target
			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
		task_contract_taker = {
			trigger_event = ep3_contract_event.0070
		}
	}

	on_invalidated = {
		if = {
			limit = {
				root.task_contract_taker = {
					any_character_active_contract = {
						this = root
					}
				}
			}
			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_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 = {
					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 = 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
						}
					}
				}
			}
		}
		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_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
					}
				}
			}
		}
	}
}

## Missionary Duties
# scope:employer = ruler converting the county
# scope:task_contract_target = court chaplain doing the convert council task
# scope:task_contract_destination = county that has the council task active
# scope:task_contract_councillor = always the councillor performing the task
laamp_help_faith_conversion_contract = {
	group = laamp_contracts_learning_group
	icon = "/gfx/interface/icons/council_task_types/task_conversion.dds"
	travel = yes
	use_diplomatic_range = yes

	valid_to_create = {
		any_task_contract = {
			task_contract_type = laamp_help_faith_conversion_contract
			NOT = {	task_contract_location = scope:employer.location }
		}
		council_task_contract_valid_employer_trigger = {
			COUNCILLOR_TYPE = councillor_court_chaplain
			COUNCIL_TASK_TYPE = task_conversion
		}
	}

	valid_to_accept = {
		council_task_contract_valid_employer_trigger = {
			COUNCILLOR_TYPE = councillor_court_chaplain
			COUNCIL_TASK_TYPE = task_conversion
		}
	}

	valid_to_keep = {
		exists = root.var:task_contract_councillor_liege
		exists = root.var:task_contract_councillor
		# Standard triggers.
		valid_laamp_basic_trigger = {
			EMPLOYER = root.task_contract_employer
			LAAMP = root.task_contract_taker
		}
	}
	valid_to_continue = {
		exists = root.var:task_contract_councillor_liege
		exists = root.var:task_contract_councillor
		# Standard triggers.
		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_learning_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 }
			if = {
				limit = {
					scope:task_contract_employer.cp:councillor_court_chaplain ?= { is_performing_council_task = task_conversion }
				}
				set_task_contract_target = scope:task_contract_employer.cp:councillor_court_chaplain
				scope:task_contract_employer.cp:councillor_court_chaplain = { save_scope_as = task_contract_councillor }
			}
			else = {
				set_task_contract_target = scope:task_contract_employer.liege
				scope:task_contract_employer = { save_scope_as = task_contract_councillor }
			}
			set_variable = {
				name = task_contract_destination
				value = root.task_contract_target.councillor_task_target
			}
			set_variable = {
				name = task_contract_employer
				value = scope:task_contract_employer
			}
			set_variable = {
				name = task_contract_target
				value = root.task_contract_target
			}
			set_variable = {
				name = task_contract_councillor
				value = scope:task_contract_councillor
			}
			# Make our gold rewards static.
			grab_gold_fuzz_number_effect = yes
			set_variable = {
				name = gold_success_standard
				value = task_contract_taker.task_contract_success_gold_gain_full_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
		task_contract_taker = {
			trigger_event = ep3_contract_event.0085
		}
	}

	on_invalidated = {
		if = {
			limit = {
				root.task_contract_taker = {
					any_character_active_contract = {
						this = root
					}
				}
			}
			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_help_faith_conversion_contract
				}
			}
			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
				}
			}
		}
	}

	# 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_value_as = { name = extra_reward value = flag:no }
				laamp_rewards_disburse_ordinary_currency_effect = {
					GOLD = scope:task_contract.var:gold_success_standard
					PRESTIGE = task_contract_success_prestige_gain_half_value
					PIETY = task_contract_success_piety_gain_full_value
					PROVISIONS = task_contract_failure_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
				}
				gain_patron_and_hook_from_council_task_contract_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_value_as = { name = extra_reward value = flag:no }
				# Standard Penalties.
				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
				}
			}
		}
	}
}

## Protect the Adherents
# scope:employer = pool character resisting county conversion
# scope:task_contract_target = court chaplain doing the convert council task
# scope:task_contract_destination = county that has the council task active
# scope:task_contract_object = task_contract_target's liege
laamp_fight_faith_conversion_contract = {
	group = laamp_contracts_learning_group
	icon = "/gfx/interface/icons/council_task_types/task_conversion.dds"
	travel = no
	use_diplomatic_range = yes

	valid_to_create = {
		NOT = {
			any_task_contract = {
				task_contract_type = laamp_fight_faith_conversion_contract
				task_contract_location = scope:employer.location
			}
		}
		scope:employer = {
			top_liege != this
			any_liege_or_above = {
				cp:councillor_court_chaplain ?= {
					is_performing_council_task = task_conversion
					councillor_task_target = scope:employer.location
				}
				faith != root.faith
				faith != scope:employer.faith
			}
		}
		valid_laamp_basic_trigger = {
			EMPLOYER = scope:employer
			LAAMP = root
		}
	}

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

	valid_to_keep = {
		exists = root.var:task_contract_councillor_liege
		exists = root.var:task_contract_councillor
		# Standard triggers.
		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
		}
	}

	weight = {
		# Standard weights.
		value = task_contract_weight_interesting_almost_rare_value
		add = laamp_contracts_weight_up_learning_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
				if = {
					limit = {
						NOT = { exists = scope:task_contract.task_contract_destination }
					}
					random_liege_or_above = {
						limit = {
							cp:councillor_court_chaplain ?= {
								is_performing_council_task = task_conversion
								councillor_task_target = scope:task_contract_employer.location
								save_temporary_scope_as = temp_councillor								
							}
							faith != scope:task_contract.task_contract_taker.faith
							faith != scope:task_contract_employer.faith
						}
						save_scope_as = task_contract_councillor_liege
						scope:temp_councillor = {
							save_scope_as = task_contract_councillor
						}
					}
					scope:task_contract = {
						#save how the contract was generated for easier debugging
						set_variable = {
							name = spawned_by
							value = flag:populate_effect
						}
					}
				}
				else = {
					scope:task_contract = {
						task_contract_target = {
							save_scope_as = task_contract_councillor
							liege = {
								save_scope_as = task_contract_councillor_liege
							}
						}
						#save how the contract was generated for easier debugging
						set_variable = {
							name = spawned_by
							value = flag:on_action
						}
					}
				}
			}
			# Error suppression
			if = {
				limit = { exists = var:spawned_by
					OR = {
						var:spawned_by = flag:populate_effect
						var:spawned_by = flag:on_action
					}
				} 
			}
			set_variable = {
				name = task_contract_councillor_liege
				value = scope:task_contract_councillor_liege
			}
			set_variable = {
				name = task_contract_councillor
				value = scope:task_contract_councillor
			}
			if = {
				limit = {
					NOT = { exists = scope:task_contract.task_contract_target }
				}
				set_task_contract_target = scope:task_contract.var:task_contract_councillor
			}
			set_variable = {
				name = task_contract_employer
				value = scope:task_contract_employer
			}
			set_variable = {
				name = task_contract_target
				value = scope:task_contract.task_contract_target
			}
			if = {
				limit = {
					exists = scope:task_contract.task_contract_destination
				}
				set_variable = {
					name = task_contract_destination
					value = scope:task_contract.task_contract_destination
				}
			}
			else = {
				set_variable = {
					name = task_contract_destination
					value = scope:task_contract.var:task_contract_councillor.councillor_task_target
				}
			}
			# Make our gold rewards static.
			grab_gold_fuzz_number_effect = yes
			set_variable = {
				name = gold_success_standard
				value = task_contract_taker.task_contract_success_gold_gain_full_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
		task_contract_taker = {
			trigger_event = ep3_contract_event.0082
		}
	}

	on_invalidated = {
		if = {
			limit = {
				root.task_contract_taker = {
					any_character_active_contract = {
						this = root
					}
				}
			}
			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_fight_faith_conversion_contract
				}
			}
			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
				}
			}
		}
	}

	# 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_value_as = { name = extra_reward value = flag:no }
				# Standard Rewards.
				laamp_rewards_disburse_ordinary_currency_effect = {
					GOLD = scope:task_contract.var:gold_success_standard
					PRESTIGE = task_contract_success_prestige_gain_half_value
					PIETY = task_contract_success_piety_gain_full_value
					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
				}
			} 
		}		
		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 }
				# Standard Penalties.
				laamp_rewards_disburse_ordinary_currency_effect = {
					GOLD = 0
					PRESTIGE = 0
					PIETY = -25
					PROVISIONS = 0
					OPINION = task_contract_opinion_standard_failure_value
					OPINION_TYPE = failed_task_contract_opinion
					CONTACT = no
					CONTACT_HOOK = no
					EXTRA_REWARD = scope:extra_reward
				}
			}
		}
	}
}

## Knight's Coach
# scope:employer = ruler or marshal needing help in train commanders council task
# scope:task_contract_target = marshal or ruler, depending on who's the employer
# var:knights_to_train = list of all knights you have to train
laamp_help_train_commanders_contract = {
	group = laamp_contracts_martial_group
	icon = "/gfx/interface/icons/council_task_types/task_train_commanders.dds"
	travel = yes
	use_diplomatic_range = yes

	valid_to_create = {
		council_task_contract_valid_employer_trigger = {
			COUNCILLOR_TYPE = councillor_marshal
			COUNCIL_TASK_TYPE = task_train_commanders
		}
		trigger_if = {
			limit = {
				scope:employer.cp:councillor_marshal ?= {
					is_performing_council_task = task_train_commanders
				}
			}
			scope:employer = {
				any_knight = { }		
			}
		}
		trigger_else = {
			scope:employer.liege = {
				any_knight = { }		
			}
		}
	}

	valid_to_accept = {
		council_task_contract_valid_employer_trigger = {
			COUNCILLOR_TYPE = councillor_marshal
			COUNCIL_TASK_TYPE = task_train_commanders
		}
	}
	valid_to_keep = {
		exists = root.var:task_contract_councillor_liege
		exists = root.var:task_contract_councillor
		# Standard triggers.
		valid_laamp_basic_trigger = {
			EMPLOYER = root.task_contract_employer
			LAAMP = root.task_contract_taker
		}
	}

	valid_to_continue = {
		time_since_contract_taken <= 720
		has_variable_list = knights_to_train
		any_in_list = {
			variable = knights_to_train
			is_alive = yes
			is_knight = yes
		}
		# Standard triggers.
		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_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
			}
			set_variable = {
				name = task_contract_employer
				value = scope:task_contract_employer
			}
			
			assign_council_task_scopes_in_contract_effect = {
				COUNCILLOR_TYPE = councillor_marshal
				COUNCIL_TASK_TYPE = task_train_commanders
			}
			#save all knights to train
			scope:task_contract_councillor_liege = {
				ordered_knight = {
					order_by = {
						value = prowess
						multiply = -1
					}
					max = 3
					add_to_list = knights_list
					scope:task_contract = {
						add_to_variable_list = {
							name = knights_to_train
							target = prev
						}
					}
				}
			}
			#keep track of success and failure
			set_variable = {
				name = knights_trained
				value = 0
			}
			set_variable = {
				name = knights_failed
				value = 0
			}
			set_variable = {
				name = knights_limit
				value = {
					value = list_size:knights_list
					subtract = 1
				}
			}
			#get a list of traits you can teach		
			task_contract_taker = {
				every_character_trait = {
					limit = {
						has_trait_category = commander
					}
					scope:task_contract = {
						add_to_variable_list = {
							name = takers_commander_traits
							target = prev
						}
					}
				}
			}
			# Make our gold rewards static.
			grab_gold_fuzz_number_effect = yes
			set_variable = {
				name = gold_success_standard
				value = task_contract_taker.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.task_contract_success_gold_gain_critical_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
		task_contract_taker = {
			trigger_event = ep3_contract_event.0090
		}
	}

	on_invalidated = {
		save_scope_as = task_contract
		if = {
			limit = {
				root.task_contract_taker = {
					any_character_active_contract = {
						this = root
					}
				}
			}
			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
			}
			task_contract_taker = {
				set_variable = {
					name = invalidated_task_contract_type
					value = flag:laamp_help_train_commanders_contract
				}
			}
			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 = {
				scope:task_contract = {
					if = {
						limit = {
							NAND = {
								var:knights_trained = 0
								var:knights_failed = 0
							}
						}
						if = {
							limit = {
								var:knights_trained >= scope:task_contract.var:knights_failed
							}
							complete_task_contract = success_standard
						}
						else = {
							complete_task_contract = failure_standard
						}
					}
				}
			}
		}
	}

	task_contract_reward = {
		success_critical = {
			effect = {
				save_scope_value_as = { name = extra_reward value = flag:no }
				save_scope_as = task_contract
				task_contract_taker = {
					play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_success_on_contract"
					send_interface_toast = {
						title = laamp_transport_contract.success
						left_icon = scope:task_contract.task_contract_taker
						right_icon = scope:task_contract.task_contract_employer
						scope:task_contract = {
							# Standard Rewards.
							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_minor_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
							}
							gain_patron_and_hook_from_council_task_contract_effect = yes
						}
					}
				}
			}
		}
		success_standard = {
			effect = {
				save_scope_value_as = { name = extra_reward value = flag:no }
				save_scope_as = task_contract
				task_contract_taker = {
					play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_success_on_contract"
					send_interface_toast = {
						title = laamp_transport_contract.success
						left_icon = scope:task_contract.task_contract_taker
						right_icon = scope:task_contract.task_contract_employer
						scope:task_contract = {
							# Standard Rewards.
							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 = yes
								EXTRA_REWARD = scope:extra_reward
							}
						}
					}
				}
			}
		}
		failure_standard = {
			positive = no
			effect = {
				save_scope_value_as = { name = extra_reward value = flag:no }
				save_scope_as = task_contract
				task_contract_taker = {
					play_sound_effect = "event:/DLC/EP3/SFX/UI/Contracts/ep3_ui_contracts_failure_on_contract"
					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
						scope:task_contract = {
							# Standard Penalties.
							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
							}
						}
					}
				}
			}
		}
	}
}

## Private Eye
# scope:employer = spymaster or ruler finding secrets
# scope:task_contract_target = holder of the claimed title
# scope:task_contract_destination = county that has the council task active
# scope:task_contract_object = employer's liege or court chaplain, depending on who's the employer
laamp_help_find_secrets_contract = {
	group = laamp_contracts_intrigue_group
	icon = "/gfx/interface/icons/council_task_types/task_find_secrets.dds"
	travel = yes
	use_diplomatic_range = yes

	valid_to_create = {
		council_task_contract_valid_employer_trigger = {
			COUNCILLOR_TYPE = councillor_spymaster
			COUNCIL_TASK_TYPE = task_find_secrets
		}
	}

	valid_to_keep = {
		exists = root.var:task_contract_councillor_liege
		exists = root.var:task_contract_councillor
		# Standard triggers.
		valid_laamp_basic_trigger = {
			EMPLOYER = root.task_contract_employer
			LAAMP = root.task_contract_taker
		}
	}
	valid_to_accept = {
		council_task_contract_valid_employer_trigger = {
			COUNCILLOR_TYPE = councillor_spymaster
			COUNCIL_TASK_TYPE = task_find_secrets
		}
	}

	valid_to_continue = {
		time_since_contract_taken <= 720
		# Standard triggers.
		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_intrigue_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
			}
			set_variable = {
				name = task_contract_employer
				value = scope:task_contract_employer
			}
			set_variable = {
				name = task_contract_destination
				value = scope:task_contract.task_contract_location
			}
			set_variable = {
				name = secrets_found
				value = 0
			}
			assign_council_task_scopes_in_contract_effect = {
				COUNCILLOR_TYPE = councillor_spymaster
				COUNCIL_TASK_TYPE = task_find_secrets
			}
			# Make our gold rewards static.
			grab_gold_fuzz_number_effect = yes
			set_variable = {
				name = gold_success_standard
				value = task_contract_taker.task_contract_success_gold_gain_full_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
		task_contract_taker = {
			trigger_event = ep3_contract_event.0100
		}
	}

	on_invalidated = {
		save_scope_as = task_contract
		if = {
			limit = {
				root.task_contract_taker = {
					any_character_active_contract = {
						this = root
					}
				}
			}
			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
			}
			task_contract_taker = {
				set_variable = {
					name = invalidated_task_contract_type
					value = flag:laamp_help_find_secrets_contract
				}
			}
			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 = {
				scope:task_contract = {
					if = {
						limit = {
							var:knights_trained >= scope:task_contract.var:knights_failed
						}
						complete_task_contract = success_standard
					}
					else = {
						complete_task_contract = failure_standard
					}
				}
			}
		}
	}

	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_value_as = { name = extra_reward value = flag:no }
				# Standard Rewards.
				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 = yes
					EXTRA_REWARD = scope:extra_reward
				}
				gain_patron_and_hook_from_council_task_contract_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_value_as = { name = extra_reward value = flag:no }
				# Standard Penalties.
				laamp_rewards_disburse_ordinary_currency_effect = {
					GOLD = 0
					PRESTIGE = -25
					PIETY = 0
					PROVISIONS = 0
					OPINION = task_contract_opinion_standard_failure_value
					OPINION_TYPE = failed_task_contract_opinion
					CONTACT = no
					CONTACT_HOOK = no
					EXTRA_REWARD = scope:extra_reward
				}
			}
		}
	}
}

## Forgotten Claims
# scope:employer = court chaplain or ruler fabricating a claim
# scope:task_contract_target = holder of the claimed title
# scope:task_contract_destination = county that has the council task active
# scope:task_contract_councillor_liege = always liege of the councillor performing the task
# scope:task_contract_councillor = always the councillor performing the task
laamp_help_fabricate_claim_contract = {
	group = laamp_contracts_intrigue_group
	icon = "/gfx/interface/icons/council_task_types/task_fabricate_claim.dds"
	travel = yes
	use_diplomatic_range = yes

	valid_to_create = {
		council_task_contract_valid_employer_trigger = {
			COUNCILLOR_TYPE = councillor_court_chaplain
			COUNCIL_TASK_TYPE = task_fabricate_claim
		}
	}

	valid_to_keep = {
		exists = root.var:task_contract_councillor_liege
		exists = root.var:task_contract_councillor
		# Standard triggers.
		valid_laamp_basic_trigger = {
			EMPLOYER = root.task_contract_employer
			LAAMP = root.task_contract_taker
		}
	}
	valid_to_accept = {
		council_task_contract_valid_employer_trigger = {
			COUNCILLOR_TYPE = councillor_court_chaplain
			COUNCIL_TASK_TYPE = task_fabricate_claim
		}
	}
	valid_to_continue = {
		# Standard triggers.
		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_intrigue_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
			assign_council_task_scopes_in_contract_effect = {
				COUNCILLOR_TYPE = councillor_court_chaplain
				COUNCIL_TASK_TYPE = task_fabricate_claim
			}
			if = {
				limit = {
					exists = scope:task_contract.task_contract_destination
				}
				set_variable = {
					name = task_contract_destination
					value = scope:task_contract.task_contract_destination
				}
			}
			else = {
				set_variable = {
					name = task_contract_destination
					value = scope:task_contract_councillor.councillor_task_target
				}
			}
			set_variable = {
				name = task_contract_employer
				value = scope:task_contract.task_contract_employer
			}
			set_variable = {
				name = task_contract_target
				value = scope:task_contract.var:task_contract_destination.province_owner
			}
			set_task_contract_target = scope:task_contract.var:task_contract_target
			# Make our gold rewards static.
			grab_gold_fuzz_number_effect = yes
			set_variable = {
				name = gold_success_critical
				value = task_contract_taker.task_contract_success_gold_gain_full_value
			}
			set_variable = {
				name = gold_success_standard
				value = task_contract_taker.task_contract_success_gold_gain_full_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
		task_contract_taker = {
			trigger_event = ep3_contract_event.0080
		}
	}

	on_invalidated = {
		if = {
			limit = {
				root.task_contract_taker = {
					any_character_active_contract = {
						this = root
					}
				}
			}
			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_help_fabricate_claim_contract
				}
			}
			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
				}
			}
		}
	}

	# 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 }
				# Standard Rewards.
				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_minor_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
				}
				if = {
					limit = {
						exists = var:attached_scheme
					}
					var:attached_scheme = {
						scheme_target_title = {
							save_scope_as = claimed_title
						}
					}
				}
				else = {
					scope:task_contract.var:task_contract_destination.county = {
						save_scope_as = claimed_title
					}
				}
				var:task_contract_councillor_liege = {
					add_pressed_claim = scope:claimed_title
				}
				task_contract_taker = {
					show_as_tooltip = {
						add_pressed_claim = scope:claimed_title
					}
				}
				gain_patron_and_hook_from_council_task_contract_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 }
				# Standard Rewards.
				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 = no
					CONTACT_HOOK = no
					EXTRA_REWARD = scope:extra_reward
				}
				if = {
					limit = {
						exists = var:attached_scheme
					}
					var:attached_scheme = {
						scheme_target_title = {
							save_scope_as = claimed_title
						}
					}
				}
				else = {
					scope:task_contract.var:task_contract_destination.county = {
						save_scope_as = claimed_title
					}
				}
				var:task_contract_councillor_liege = {
					add_pressed_claim = scope:claimed_title
				}
				task_contract_taker = {
					hidden_effect = {
						remove_claim = scope:claimed_title
					}
				}
				gain_patron_and_hook_from_council_task_contract_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_value_as = { name = extra_reward value = flag:no }
				# Standard Penalties.
				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
				}
			}
		}
	}
}

## Fight Corruption
# scope:employer = marshal or ruler increasing control
# scope:task_contract_target = holder of the claimed title
# scope:task_contract_destination = county that has the council task active
# scope:task_contract_councillor_liege = always liege of the councillor performing the task
# scope:task_contract_councillor = always the councillor performing the task
laamp_help_increase_control_contract = {
	group = laamp_contracts_intrigue_group
	icon = "/gfx/interface/icons/council_task_types/task_increase_control.dds"
	travel = no
	use_diplomatic_range = yes

	valid_to_create = {
		valid_laamp_basic_trigger = {
			EMPLOYER = scope:employer
			LAAMP = root
		}
		OR = {
			scope:employer = {
				NOT = { var:issued_help_increase_control_contract_recently ?= root }
				top_liege = this
				any_councillor = {
					OR = {
						has_council_position = councillor_marshal
						AND = {
							is_kurultai_trigger = yes
							highest_skill = martial
						}
					}
				}
				any_sub_realm_county = {
					OR = {
						has_county_corruption_trigger = yes
						county_control <= low_county_control
					}
				}
			}
			scope:employer = {
				NOT = { var:issued_help_increase_control_contract_recently ?= root }
				OR = {
					has_council_position = councillor_marshal
					AND = {
						is_kurultai_trigger = yes
						highest_skill = martial
					}
				}
				is_councillor_of = top_liege				
				top_liege = {
					NOT = {
						has_any_bad_relationship_with_character_trigger = { CHARACTER = scope:employer }
					}
					any_sub_realm_county = {
						OR = {
							has_county_corruption_trigger = yes
							county_control <= low_county_control
						}
					}
				}
			}
		}
	}

	valid_to_keep = {
		var:task_contract_councillor_liege ?= {
			any_sub_realm_county = {
				OR = {
					has_county_corruption_trigger = yes
					county_control <= low_county_control
				}
			}
		}
		# Standard triggers.
		valid_laamp_basic_trigger = {
			EMPLOYER = root.task_contract_employer
			LAAMP = root.task_contract_taker
		}
	}

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

	valid_to_accept = {
	}

	weight = {
		# Standard weights.
		value = task_contract_weight_interesting_almost_rare_value
		add = laamp_contracts_weight_up_martial_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 = {
				set_variable = {
					name = issued_help_increase_control_contract_recently
					value = scope:task_contract.task_contract_taker
					years = 10
				}
				save_scope_as = task_contract_employer
				if = {
					limit = {
						top_liege = this
					}
					scope:task_contract_employer = {
						save_scope_as = task_contract_councillor_liege
						random_councillor = {
							limit = {
								OR = {
									has_council_position = councillor_marshal
									AND = {
										is_kurultai_trigger = yes
										highest_skill = martial
									}
								}
							}
							save_scope_as = task_contract_councillor
						}
					}
				}
				else = {
					scope:task_contract_employer = {
						save_scope_as = task_contract_councillor
						top_liege = {
							save_scope_as = task_contract_councillor_liege
						}
					}
				}
			}
			set_variable = {
				name = task_contract_councillor_liege
				value = scope:task_contract_councillor_liege
			}
			set_variable = {
				name = task_contract_councillor
				value = scope:task_contract_councillor
			}
			set_variable = {
				name = task_contract_employer
				value = scope:task_contract.task_contract_employer
			}
			set_variable = {
				name = support
				value = 0
			}
			set_variable = {
				name = control
				value = 0
			}
			set_variable = {
				name = num_of_corrupt_counties
				value = 0
			}
			#save the liege as the target
			set_task_contract_target = scope:task_contract_councillor_liege
			#save all counties with low control or corruption modifier in liege's realm
			scope:task_contract_councillor_liege = {
				ordered_sub_realm_county = {
					order_by = {
						value = county_opinion
						multiply = -1
					}
					max = 6
					check_range_bounds = no
					limit = {
						OR = {
							has_county_corruption_trigger = yes
							county_control <= low_county_control
						}
					}
					scope:task_contract = {
						add_to_variable_list = {
							name = corrupt_counties
							target = prev
						}
					}
				}
			}
			# We do this a bit later on because otherwise it was having some slight issues if only one county was valid.
			set_variable = {
				name = num_of_corrupt_counties
				value = {
					every_in_list = {
						variable = corrupt_counties
						add = 1
					}
				}
			}
			random_in_list = {
				variable = corrupt_counties
				title_province = {
					save_scope_as = destination
				}
			}
			set_variable = {
				name = task_contract_destination
				value = scope:destination
			}
			# Make our gold rewards static.
			grab_gold_fuzz_number_effect = yes
			set_variable = {
				name = gold_success_critical
				value = {
					value = task_contract_taker.task_contract_success_gold_gain_full_value
					multiply = scope:task_contract.var:num_of_corrupt_counties
				}
			}
			set_variable = {
				name = gold_success_standard
				value = {
					value = task_contract_taker.task_contract_success_gold_gain_full_value
					multiply = scope:task_contract.var:num_of_corrupt_counties
					multiply = 0.5
				}
			}
		}
	}

	# On_Actions
	on_accepted = {
		save_scope_as = task_contract
		task_contract_taker = {
			trigger_event = ep3_contract_event.0092
		}
	}

	on_invalidated = {
		if = {
			limit = {
				root.task_contract_taker = {
					any_character_active_contract = {
						this = root
					}
				}
			}
			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_help_increase_control_contract
				}
			}
			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
				}
			}
		}
	}

	# Rewards
	task_contract_reward = {
		success_critical = {
			effect = {
				save_scope_value_as = { name = extra_reward value = flag:no }
				save_scope_as = task_contract
				set_variable = {
					name = gold_success_critical
					value = {
						value = task_contract_taker.task_contract_success_gold_gain_full_value
						multiply = var:control
					}
				}
				set_variable = {
					name = gold_success_standard
					value = {
						value = task_contract_taker.task_contract_success_gold_gain_full_value
						multiply = var:control
						multiply = 0.5
					}
				}
				# Standard Rewards.
				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_minor_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
				}
				gain_patron_and_hook_from_council_task_contract_effect = yes
				hidden_effect = {
					scope:task_contract.task_contract_taker= { return_home = yes }
				}
			} 
		}
		success_standard = {
			effect = {
				save_scope_value_as = { name = extra_reward value = flag:no }
				save_scope_as = task_contract
				set_variable = {
					name = gold_success_critical
					value = {
						value = task_contract_taker.task_contract_success_gold_gain_full_value
						multiply = var:control
					}
				}
				set_variable = {
					name = gold_success_standard
					value = {
						value = task_contract_taker.task_contract_success_gold_gain_full_value
						multiply = var:control
						multiply = 0.5
					}
				}
				# Standard Rewards.
				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 = no
					CONTACT_HOOK = no
					EXTRA_REWARD = scope:extra_reward
				}
				gain_patron_and_hook_from_council_task_contract_effect = yes
				hidden_effect = {
					scope:task_contract.task_contract_taker = {
						return_home = yes
					}
				}
			}
		}		
		failure_standard = {
			positive = no
			effect = {
				save_scope_value_as = { name = extra_reward value = flag:no }
				save_scope_as = task_contract
				# Standard Penalties.
				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
				}
				hidden_effect = {
					scope:task_contract.task_contract_taker = {
						return_home = yes
					}
				}
			}
		}
	}
}
