###################################################
##	EP3 Contract Events
##
###################################################

namespace = ep3_contract_event

scripted_effect set_contract_scopes_effect = {
	scope:task_contract.task_contract_taker ?= {
		save_scope_as = task_contract_taker
	}
	scope:task_contract.task_contract_employer ?= {
		save_scope_as = task_contract_employer
	}
	if = {
		limit = {
			exists = scope:task_contract.task_contract_destination
		}
		scope:task_contract.task_contract_destination = {
			save_scope_as = task_contract_destination
		}
	}
	else = {
		scope:task_contract.var:task_contract_destination ?= {
			save_scope_as = task_contract_destination
		}
	}
	if = {
		limit = {
			exists = scope:task_contract.task_contract_target
		}
		scope:task_contract.task_contract_target ?= {
			save_scope_as = task_contract_target
		}
	}
	else = {
		scope:task_contract.var:task_contract_target ?= {
			save_scope_as = task_contract_target
		}
	}
	scope:task_contract.var:task_contract_war ?= {
		save_scope_as = task_contract_war
	}
	if = {
		limit = {
			exists = scope:task_contract.var:task_contract_object
		}
		scope:task_contract.var:task_contract_object = {
			save_scope_as = task_contract_object
		}
	}
	if = {
		limit = {
			exists = scope:task_contract.var:escorted_artifact
		}
		scope:task_contract.var:escorted_artifact = {
			save_scope_as = escorted_artifact
		}
	}
	if = {
		limit = {
			exists = scope:task_contract.var:escorted_gold
		}
		scope:task_contract.var:escorted_gold = {
			save_scope_as = escorted_gold
		}
	}
	if = {
		limit = {
			exists = scope:task_contract.var:escorted_story
		}
		scope:task_contract.var:escorted_story = {
			save_scope_as = escorted_story
		}
	}
}

scripted_effect start_contract_travel_without_domicile = {
	start_travel_plan = {
		destination = scope:task_contract_destination
		on_arrival_destinations = all
	}
}
scripted_effect start_contract_travel_with_domicile = {
	start_travel_plan = {
		destination = scope:task_contract_destination
		travel_with_domicile = yes
		return_trip = no
		on_arrival_destinations = all
	}	
}

#taking a transport contract - triggered after you take a transport contract
ep3_contract_event.0001 = {
	type = character_event
	title = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:task_contract = { has_task_contract_type = laamp_transport_vip } }
				desc = ep3_contract_event.0001.t_vip
			}
			triggered_desc = {
				trigger = { scope:task_contract = { has_task_contract_type = laamp_transport_ward } }
				desc = ep3_contract_event.0001.t_child
			}
			triggered_desc = {
				trigger = { scope:task_contract = { has_task_contract_type = laamp_transport_explorer } }
				desc = ep3_contract_event.0001.t_explorer
			}
			triggered_desc = {
				trigger = { scope:task_contract = { has_task_contract_type = laamp_transport_artifact } }
				desc = ep3_contract_event.0001.t_artifact
			}
			triggered_desc = {
				trigger = { scope:task_contract = { has_task_contract_type = laamp_transport_gold } }
				desc = ep3_contract_event.0001.t_gold
			}
			triggered_desc = {
				trigger = { scope:task_contract = { has_task_contract_type = laamp_transport_animal } }
				desc = ep3_contract_event.0001.t_animal
			}
			triggered_desc = {
				trigger = { scope:task_contract = { has_task_contract_type = laamp_construction_contract } }
				desc = ep3_contract_event.0001.t_construction
			}
		}
	}
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:task_contract = { has_task_contract_type = laamp_transport_explorer } }
				desc = ep3_contract_event.0001.desc_intro_explorer
			}
			desc = ep3_contract_event.0001.desc
		}
		#desc for the explorer contract type for differrent point of interests types
		first_valid = {
			triggered_desc = {
				trigger = { scope:task_contract.var:travel_reason ?= flag:special_buildings_martial }
				desc = ep3_contract_event.0001.desc_special_buildings_martial
			}
			triggered_desc = {
				trigger = { scope:task_contract.var:travel_reason ?= flag:special_buildings_learning }
				desc = ep3_contract_event.0001.desc_special_buildings_learning
			}
			triggered_desc = {
				trigger = { scope:task_contract.var:travel_reason ?= flag:special_buildings_religious }
				desc = ep3_contract_event.0001.desc_special_buildings_religious
			}
			triggered_desc = {
				trigger = { scope:task_contract.var:travel_reason ?= flag:special_buildings_diplomatic }
				desc = ep3_contract_event.0001.desc_special_buildings_diplomatic
			}
			triggered_desc = {
				trigger = { scope:task_contract.var:travel_reason ?= flag:grand_city }
				desc = ep3_contract_event.0001.desc_grand_city
			}
			triggered_desc = {
				trigger = { scope:task_contract.var:travel_reason ?= flag:special_buildings_wonder }
				desc = ep3_contract_event.0001.desc_special_buildings_wonder
			}
			triggered_desc = {
				trigger = { scope:task_contract.var:travel_reason ?= flag:special_buildings_economic }
				desc = ep3_contract_event.0001.desc_special_buildings_economic
			}
			triggered_desc = {
				trigger = { scope:task_contract.var:travel_reason ?= flag:mausoleum_at_halicarnassus }
				desc = ep3_contract_event.0001.desc_mausoleum_at_halicarnassus
			}
			triggered_desc = {
				trigger = { scope:task_contract.var:travel_reason ?= flag:lighthouse_of_alexandria }
				desc = ep3_contract_event.0001.desc_lighthouse_of_alexandria
			}
			triggered_desc = {
				trigger = { scope:task_contract.var:travel_reason ?= flag:natural_feature }
				desc = ep3_contract_event.0001.desc_natural_feature
			}
			triggered_desc = {
				trigger = { scope:task_contract.var:travel_reason ?= flag:capitals }
				desc = ep3_contract_event.0001.desc_capitals
			}
		}
		first_valid = {
			triggered_desc = {
				trigger = { scope:task_contract = { has_task_contract_type = laamp_transport_vip } }
				desc = ep3_contract_event.0001.desc_vip
			}
			triggered_desc = {
				trigger = { scope:task_contract = { has_task_contract_type = laamp_transport_ward } }
				desc = ep3_contract_event.0001.desc_child
			}
			triggered_desc = {
				trigger = { scope:task_contract = { has_task_contract_type = laamp_transport_explorer } }
				desc = ep3_contract_event.0001.desc_explorer
			}
			triggered_desc = {
				trigger = { scope:task_contract = { has_task_contract_type = laamp_transport_artifact } }
				desc = ep3_contract_event.0001.desc_artifact
			}
			triggered_desc = {
				trigger = { scope:task_contract = { has_task_contract_type = laamp_transport_gold } }
				desc = ep3_contract_event.0001.desc_gold
			}
			triggered_desc = {
				trigger = { scope:task_contract = { has_task_contract_type = laamp_transport_animal } }
				desc = ep3_contract_event.0001.desc_animal
			}
			triggered_desc = {
				trigger = { scope:task_contract = { has_task_contract_type = laamp_construction_contract } }
				desc = ep3_contract_event.0001.desc_construction
			}
		}
	}
	theme = landless_adventurer
	override_background = { reference = terrain }
	#task_contract_taker, you
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = { scope:task_contract = { has_task_contract_type = laamp_transport_vip } }
			animation = personality_honorable
		}
		triggered_animation = {
			trigger = { scope:task_contract = { has_task_contract_type = laamp_transport_ward } }
			animation = personality_compassionate
		}
		triggered_animation = {
			trigger = { scope:task_contract = { has_task_contract_type = laamp_transport_explorer } }
			animation = interested_left
		}
		triggered_animation = {
			trigger = { scope:task_contract = { has_task_contract_type = laamp_transport_artifact } }
			animation = personality_bold
		}
		triggered_animation = {
			trigger = { scope:task_contract = { has_task_contract_type = laamp_transport_gold } }
			animation = stunned
		}
		triggered_animation = {
			trigger = { scope:task_contract = { has_task_contract_type = laamp_transport_animal } }
			animation = love
		}
		triggered_animation = {
			trigger = { scope:task_contract = { has_task_contract_type = laamp_construction_contract } }
			animation = personality_rational
		}
	}
	#character you have to escort, if exists
	right_portrait = {
		character = scope:right_portrait
		triggered_animation = {
			trigger = { scope:task_contract = { has_task_contract_type = laamp_transport_vip } }
			animation = personality_rational
		}
		triggered_animation = {
			trigger = { scope:task_contract = { has_task_contract_type = laamp_transport_ward } }
			animation = clutching_toy
		}
		triggered_animation = {
			trigger = { scope:task_contract = { has_task_contract_type = laamp_transport_explorer } }
			animation = eccentric
		}
		triggered_animation = {
			trigger = { scope:task_contract = { has_task_contract_type = laamp_transport_artifact } }
			animation = personality_compassionate
		}
		triggered_animation = {
			trigger = { scope:task_contract = { has_task_contract_type = laamp_transport_gold } }
			animation = personality_compassionate
		}
		triggered_animation = {
			trigger = { scope:task_contract = { has_task_contract_type = laamp_transport_animal } }
			animation = personality_compassionate
		}
		triggered_animation = {
			trigger = { scope:task_contract = { has_task_contract_type = laamp_construction_contract } }
			animation = personality_bold
		}
	}
	#character giving you the contract, if it's not the chracter you have to escort
	lower_right_portrait = {
		trigger = {
			NOR = {
				scope:task_contract_object ?= scope:task_contract_target 
				scope:task_contract_object ?= scope:task_contract_employer
			}
		}
		character = scope:task_contract_employer
	}
	#character you have to go to, if exists
	lower_left_portrait = {
		trigger = {
			exists = scope:task_contract_target 
			scope:task_contract_target != scope:task_contract_employer
		}
		character = scope:task_contract_target
	}
	#artifact you have to escort, if exists
	artifact = {
		trigger = { exists = scope:escorted_artifact }
        target = scope:escorted_artifact
        position = lower_center_portrait
	}

	immediate = {
		set_contract_scopes_effect = yes
		if = {
			limit = {
				exists = scope:task_contract_object
			}
			scope:task_contract_object = {
				save_scope_as = right_portrait
			}
		}
		else = {
			scope:task_contract_employer = {
				save_scope_as = right_portrait
			}
		}
	}

	#take the contract and start the travel without domicile
	option = {
		name = {
			trigger = { scope:task_contract = { has_task_contract_type = laamp_transport_vip } }
			text = ep3_contract_event.0001.vip
		}
		name = {
			trigger = { scope:task_contract = { has_task_contract_type = laamp_transport_ward } }
			text = ep3_contract_event.0001.child
		}
		name = {
			trigger = { scope:task_contract = { has_task_contract_type = laamp_transport_explorer } }
			text = ep3_contract_event.0001.explorer
		}
		name = {
			trigger = { scope:task_contract = { has_task_contract_type = laamp_transport_artifact } }
			text = ep3_contract_event.0001.artifact
		}
		name = {
			trigger = { scope:task_contract = { has_task_contract_type = laamp_transport_gold } }
			text = ep3_contract_event.0001.gold
		}
		name = {
			trigger = { scope:task_contract = { has_task_contract_type = laamp_transport_animal } }
			text = ep3_contract_event.0001.animal
		}
		name = {
			trigger = { scope:task_contract = { has_task_contract_type = laamp_construction_contract } }
			text = ep3_contract_event.0001.construction
		}
		scope:task_contract = {
			 switch = {
				trigger = has_task_contract_type
				#escorting a VIP
				laamp_transport_vip = {
					custom_tooltip = ep3_contract_event.0001.tt_vip
					scope:task_contract_object = {
						visit_court_of = root
						add_character_flag = blocked_from_leaving
					}
					root = {
						start_contract_travel_without_domicile = yes
					}
				}
				#escorting a ward to guardian
				laamp_transport_ward = {
					custom_tooltip = ep3_contract_event.0001.tt_ward
					scope:task_contract_object = {
						visit_court_of = root
						add_character_flag = blocked_from_leaving
					}
					root = {
						start_contract_travel_without_domicile = yes
					}
				}
				#escorting a random pool character to a random point of interest
				laamp_transport_explorer = {
					custom_tooltip = ep3_contract_event.0001.tt_explorer
					scope:task_contract_object = {
						if = {
							limit = {
								is_landed = no
							}
							visit_court_of = root
							add_character_flag = blocked_from_leaving
						}
					}
					root = {
						start_contract_travel_without_domicile = yes
					}
				}
				#escorting an artifact
				laamp_transport_artifact = {
					custom_tooltip = ep3_contract_event.0001.tt_artifact
					scope:escorted_artifact = {
						set_owner = root
						set_variable = {
							name = ungiftable
						}
					}
					root = {
						start_contract_travel_without_domicile = yes
					}
				}
				#escorting a large sum of money
				laamp_transport_gold = {
					custom_tooltip = ep3_contract_event.0001.tt_gold
					scope:task_contract_employer = {
						pay_treasury_or_gold = {
							target = root
							value = scope:escorted_gold
						}
					}
					root = {
						start_contract_travel_without_domicile = yes
					}
				}
				#escorting a dog or a cat
				laamp_transport_animal = {
					custom_tooltip = ep3_contract_event.0001.tt_animal
					scope:task_contract_employer = {
						if = {
							limit = {
								scope:escorted_story ?= { story_type = story_cycle_pet_dog }
							}
							transfer_dog_story_cycle_to_effect = {
								CHARACTER = root
								STORY = scope:escorted_story
							}
						}
						else = {
							transfer_cat_story_cycle_to_effect = {
								CHARACTER = root
								STORY = scope:escorted_story
							}
						}
					}
					root = {
						start_contract_travel_without_domicile = yes
					}
				}
				#delivering materials for holding construcion
				laamp_construction_contract = {
					custom_tooltip = ep3_contract_event.0001.tt_construction
					root = {
						start_contract_travel_without_domicile = yes
					}
				}
			}
		}
		#AI should always try to complete the contract
		ai_chance = {
			base = 1
		}
	}
	#take the contract and start the travel with domicile
	option = {
		name = ep3_contract_event.0001.with_domicile
		scope:task_contract = {
			 switch = {
				trigger = has_task_contract_type
				#escorting a VIP
				laamp_transport_vip = {
					custom_tooltip = ep3_contract_event.0001.tt_vip
					scope:task_contract_object = {
						visit_court_of = root
						add_character_flag = blocked_from_leaving
					}
					root = {
						start_contract_travel_with_domicile = yes
					}
				}
				#escorting a ward to guardian
				laamp_transport_ward = {
					custom_tooltip = ep3_contract_event.0001.tt_ward
					scope:task_contract_object = {
						visit_court_of = root
						add_character_flag = blocked_from_leaving
					}
					root = {
						start_contract_travel_with_domicile = yes
					}
				}
				#escorting a random pool character to a random point of interest
				laamp_transport_explorer = {
					custom_tooltip = ep3_contract_event.0001.tt_explorer
					scope:task_contract_object = {
						if = {
							limit = {
								is_landed = no
							}
							visit_court_of = root
							add_character_flag = blocked_from_leaving
						}
					}
					root = {
						start_contract_travel_with_domicile = yes
					}
				}
				#escorting an artifact
				laamp_transport_artifact = {
					custom_tooltip = ep3_contract_event.0001.tt_artifact
					scope:escorted_artifact = {
						set_owner = root
						set_variable = {
							name = ungiftable
						}
					}
					root = {
						start_contract_travel_with_domicile = yes
					}
				}
				#escorting a large sum of money
				laamp_transport_gold = {
					custom_tooltip = ep3_contract_event.0001.tt_gold
					scope:task_contract_employer = {
						pay_treasury_or_gold = {
							target = root
							value = scope:escorted_gold
						}
					}
					root = {
						start_contract_travel_with_domicile = yes
					}
				}
				#escorting a dog or a cat
				laamp_transport_animal = {
					custom_tooltip = ep3_contract_event.0001.tt_animal
					scope:task_contract_employer = {
						if = {
							limit = {
								scope:escorted_story ?= { story_type = story_cycle_pet_dog }
							}
							transfer_dog_story_cycle_to_effect = {
								CHARACTER = root
								STORY = scope:escorted_story
							}
						}
						else = {
							transfer_cat_story_cycle_to_effect = {
								CHARACTER = root
								STORY = scope:escorted_story
							}
						}
					}
					root = {
						start_contract_travel_with_domicile = yes
					}
				}
				#delivering materials for holding construcion
				laamp_construction_contract = {
					custom_tooltip = ep3_contract_event.0001.tt_construction
					root = {
						start_contract_travel_with_domicile = yes
					}
				}
			}
		}
		custom_tooltip = ep3_contract_event.0001.with_domicile.tt
		#AI should always try to complete the contract
		ai_chance = {
			base = 0
		}
	}
	#invalidate the contract
	option = {
		name = ep3_contract_event.0001.invalidate
		scope:task_contract = {
			invalidate_contract = yes
		}
		#AI should always try to complete the contract
		ai_chance = {
			base = 0
		}
	}
}

scripted_trigger 0002_is_applicable_contract_trigger = {
	OR = {
		has_task_contract_group = laamp_contracts_transport_group
		#Treasure Map Contract
		AND = {
			root = { has_variable = ep3_laamp_decision_1000_is_excavating }
			exists = var:contract_treasure_location
		}
	}
}

#Event adding relevant characters to your travel entourage if you have an active transport contract
ep3_contract_event.0002 = {
	hidden = yes
	trigger = {
		has_government = landless_adventurer_government
	}
	immediate = {
		every_character_active_contract = {
			limit = {
				0002_is_applicable_contract_trigger = yes
				save_temporary_scope_as = temp_contract
				#task_contract_taker ?= root
				root.current_travel_plan = {
					#Treasure Map Contract
					trigger_if = {
						limit = { 
							scope:temp_contract = { exists = var:contract_treasure_location }
						}
						OR = {
							final_destination_province ?= scope:temp_contract.var:contract_treasure_location
							next_destination_province = scope:temp_contract.var:contract_treasure_location
							any_future_path_location = {
								this = scope:temp_contract.var:contract_treasure_location
							}
						}
					}
					trigger_else = {
						OR = {
							final_destination_province ?= scope:temp_contract.var:task_contract_destination
							next_destination_province = scope:temp_contract.var:task_contract_destination
							any_future_path_location = {
								this = scope:temp_contract.var:task_contract_destination
							}
						}
					}
				}
			}
			var:task_contract_object ?= { add_to_list = task_contract_companions }
			#Treasure Map Contract, add the scraggly old employer
			if = {
				limit = { has_task_contract_type = laamp_treasure_map_contract }
				task_contract_employer = { add_to_list = task_contract_companions }
			}
		}
		every_courtier_or_guest = {
			limit = {
				is_travelling = no
			}
			add_to_list = task_contract_companions
		}
		every_in_list = {
			list = task_contract_companions
			root.current_travel_plan = { add_companion = prev }
		}
	}
}

#Raid for Captives contract starting a war
ep3_contract_event.0003 = {
	type = character_event
	title = ep3_contract_event.0003.t
	desc = ep3_contract_event.0003.desc
	theme = war
	#task_contract_taker, you
	left_portrait = {
		character = root
		animation = personality_compassionate
	}
	#character giving you the contract
	lower_right_portrait = {
		character = scope:task_contract_employer
	}
	#character you have to fight in a war
	lower_left_portrait = {
		character = scope:task_contract_target
	}

	immediate = {
		set_contract_scopes_effect = yes
	}

	#take the contract and start raiding
	option = {
		name = ep3_contract_event.0003.a
		start_war = {
			cb = ep3_laamp_raid_contract_cb
			target = scope:task_contract_target
		}
		random_character_war = {
			limit = {
				using_cb = ep3_laamp_raid_contract_cb
				primary_attacker = root
				primary_defender = scope:task_contract_target
			}
			save_scope_as = new_war
		}
		scope:task_contract = {
			set_variable = {
				name = task_contract_war
				value = scope:new_war
			}
		}
		#AI should always try to complete the contract
		ai_chance = {
			base = 20
		}
	}
	#invalidate the contract
	option = {
		name = ep3_contract_event.0001.invalidate
		scope:task_contract = {
			invalidate_contract = yes
		}
		#AI should always try to complete the contract
		ai_chance = {
			base = 0
		}
	}
}

#Raid for Captives - complete contract letter event, triggered in the cb on war end
ep3_contract_event.0004 = {
	type = letter_event
	sender = scope:task_contract_employer
	opening = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:task_contract_outcome ?= flag:failure }
				desc = ep3_contract_event.0004.opening_failure
			}
			desc = ep3_contract_event.0004.opening
		}
	}
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:task_contract_outcome ?= flag:failure }
				desc = ep3_contract_event.0004.desc_failure
			}
			desc = ep3_contract_event.0004.desc
		}
	}

	immediate = {
		if = {
			limit = {
				scope:task_contract_outcome ?= flag:failure
			}
			add_prestige = task_contract_failure_prestige_loss_full_value
			reverse_add_opinion = {
				opinion = -50
				modifier = hate_opinion
				target = scope:task_contract_employer
			}
		}
		else = {
			scope:task_contract_employer = {
				custom_tooltip = ep3_contract_event.0004.success
				every_prisoner = {
					limit = {
						has_character_flag = captured_in_ep3_laamp_raid_contract_cb
					}
					#doing this here instead of in the war effects to show a neat list of the prisoners in the tooltip
					add_opinion = {
						modifier = abductor_opinion
						target = root
						years = 5
					}
					root = {
						if = {
							limit = { NOT = { exists = local_var:temp_ransom } }
							set_local_variable = {
								name = temp_ransom
								value = prev.ransom_cost
							}
						}
						else = {
							change_local_variable = {
								name = temp_ransom
								add = prev.ransom_cost
							}
						}
					}
					remove_character_flag = captured_in_ep3_laamp_raid_contract_cb
				}
			}
		}
	}

	option = {
		name = {
			trigger = { scope:task_contract_outcome ?= flag:failure }
			text = ep3_contract_event.0004.b
		}
		name = {
			trigger = { NOT = { exists = scope:task_contract_outcome } }
			text = ep3_contract_event.0004.a
		}
		if = {
			limit = {
				scope:task_contract_outcome ?= flag:failure
			}
		}
		else = {
			add_gold = {
				value = local_var:temp_ransom
				if = {
					limit = {
						domicile = { has_domicile_parameter = camp_improved_mercenary_contract_rewards }
					}
					multiply = camp_improved_mercenary_contract_rewards_value
				}
				if = {
					limit = {
						has_perk = hard_rule_perk
					}
					multiply = adventurer_hard_rule_contract_rewards_value
				}
			}
			if = {
				limit = {
					faith != scope:defender.faith
				}
				add_piety = minor_piety_gain 
			}
		}
	}
}

#Treasure Hunting Contract - start event
ep3_contract_event.0005 = {
	type = character_event
	title = ep3_contract_event.0005.t
	desc = ep3_contract_event.0005.desc
	theme = travel

	left_portrait = {
		character = root
		animation = personality_compassionate
	}
	lower_right_portrait = {
		character = scope:task_contract_employer
	}

	immediate = {
	}

	#go on a treasure hunting travel, opens decision to set target location
	option = {
		name = ep3_contract_event.0005.a
		custom_tooltip = ep3_contract_event.0005.a_tt
		decision:treasure_hunting_contract_decision = {
			open_view_data = {
				view = decision_detail
				player = root
			}
		}
		#AI should always try to complete the contract
		ai_chance = {
			base = 1
		}
	}
	#invalidate the contract
	option = {
		name = ep3_contract_event.0001.invalidate
		scope:task_contract = {
			invalidate_contract = yes
		}
		#AI should always try to complete the contract
		ai_chance = {
			base = 0
		}
	}
}

#Treasure Hunting Contract - event triggered when you reach a location chosen in the decision
ep3_contract_event.0006 = {
	type = character_event
	title = ep3_contract_event.0006.t
	desc = {
		desc = ep3_contract_event.0006.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:task_contract_destination = {
						has_holding_type = church_holding
					}
				}
				desc = ep3_contract_event.0006.desc_locals_temple
			}
			triggered_desc = {
				trigger = {
					scope:task_contract_destination = {
						has_holding_type = city_holding
					}
				}
				desc = ep3_contract_event.0006.desc_locals_city
			}
			triggered_desc = {
				trigger = {
					scope:task_contract_destination = {
						has_holding_type = castle_holding
					}
				}
				desc = ep3_contract_event.0006.desc_locals_castle
			}
			desc = ep3_contract_event.0006.desc_locals
		}
	}
	theme = travel
	left_portrait = {
		character = root
		animation = eavesdrop
	}
	right_portrait = {
		character = scope:local_1
		animation = debating
	}
	lower_left_portrait = {
		character = scope:local_ruler
	}
	lower_right_portrait = {
		trigger = { exists = scope:local_2 }
		character = scope:local_2
	}
	#artifact you find
	artifact = {
        target = scope:newly_created_artifact
        position = lower_center_portrait
	}
	override_background = {
		trigger = { 
			scope:task_contract_destination = {
				has_holding_type = castle_holding
			}
		}
		reference = corridor_night
	}
	override_background = {
		trigger = { 
			scope:task_contract_destination = {
				has_holding_type = city_holding
			}
		}
		reference = market
	}
	override_background = {
		trigger = { 
			scope:task_contract_destination = {
				has_holding_type = church_holding
			}
		}
		reference = temple
	}
	override_background = {
		trigger = { 
			scope:task_contract_destination = {
				NOR = {
					has_holding_type = castle_holding
					has_holding_type = city_holding
					has_holding_type = church_holding
				}
			}
		}
		reference = tavern
	}

	trigger = {
		any_character_task_contract = {
			task_contract_type = laamp_treasure_hunting_contract
			var:task_contract_destination ?= root.location
		}
	}

	immediate = {
		random_character_task_contract = {
			task_contract_type = laamp_treasure_hunting_contract
			limit = {
				var:task_contract_destination ?= root.location
			}
			save_scope_as = task_contract
		}
		scope:task_contract.var:task_contract_destination = {
			save_scope_as = task_contract_destination
			county.holder = {
				save_scope_as = local_ruler
			}
		}
		scope:task_contract.task_contract_employer = {
			save_scope_as = inspiration_owner
			save_scope_as = task_contract_employer
		}
		if = {
			limit = {
				scope:task_contract_destination = {
					has_holding_type = church_holding
				}
			}
			if = {
				limit = {
					any_pool_character = {
						province = scope:task_contract_destination
						is_available_healthy_ai_adult = yes
					}
				}
				random_pool_character = {
					province = scope:task_contract_destination
					limit = {
						is_available_healthy_ai_adult = yes
					}
					save_scope_as = local_1
				}
			}
			else = {
				create_character = {
					template = fp1_trade_partner_priest
					location = scope:task_contract_destination
					culture = scope:task_contract_destination.county.culture
					faith = scope:task_contract_destination.county.faith
					#Set up the scope
					save_scope_as = local_1
				}
			}
			inspiration_adventure_create_artifact_effect = {
				OWNER = scope:local_1
				CREATOR = scope:local_1
			}
		}
		else_if = {
			limit = {
				scope:task_contract_destination = {
					has_holding_type = city_holding
				}
			}
			if = {
				limit = {
					any_pool_character = {
						province = scope:task_contract_destination
						is_available_healthy_ai_adult = yes
					}
				}
				random_pool_character = {
					province = scope:task_contract_destination
					limit = {
						is_available_healthy_ai_adult = yes
					}
					save_scope_as = local_1
				}
			}
			else = {
				create_character = {
					template = merchant_template
					location = scope:task_contract_destination
					culture = scope:task_contract_destination.county.culture
					faith = scope:task_contract_destination.county.faith
					#Set up the scope
					save_scope_as = local_1
				}
			}
			inspiration_adventure_create_artifact_effect = {
				OWNER = scope:local_1
				CREATOR = scope:local_1
			}
		}
		else = {
			if = {
				limit = {
					any_pool_character = {
						province = scope:task_contract_destination
						is_available_healthy_ai_adult = yes
					}
				}
				random_pool_character = {
					province = scope:task_contract_destination
					limit = {
						is_available_healthy_ai_adult = yes
					}
					save_scope_as = local_1
				}
			}
			else = {
				create_character = {
					template = fp3_tomb_raider
					location = scope:task_contract_destination
					culture = scope:task_contract_destination.county.culture
					faith = scope:task_contract_destination.county.faith
					#Set up the scope
					save_scope_as = local_1
				}
			}
			if = {
				limit = {
					any_pool_character = {
						province = scope:task_contract_destination
						is_available_healthy_ai_adult = yes
						this != scope:local_1
					}
				}
				random_pool_character = {
					province = scope:task_contract_destination
					limit = {
						is_available_healthy_ai_adult = yes
						this != scope:local_1
					}
					save_scope_as = local_2
				}
			}
			else = {
				create_character = {
					template = fp3_tomb_raider
					location = scope:task_contract_destination
					culture = scope:task_contract_destination.county.culture
					faith = scope:task_contract_destination.county.faith
					#Set up the scope
					save_scope_as = local_2
				}
			}
			if = {
				limit = {
					scope:task_contract_destination = {
						has_holding_type = castle_holding
					}
				}
				inspiration_adventure_create_artifact_effect = {
					OWNER = scope:local_ruler
					CREATOR = scope:local_ruler
				}
			}
			else = {
				inspiration_adventure_create_artifact_effect = {
					OWNER = scope:local_1
					CREATOR = scope:local_1
				}
			}
		}
		#Don't need no "Lost Court Artifact to [...]" errors for this
		scope:newly_created_artifact = {
			set_variable = {
				name = suppress_artifact_notifications
				value = yes
				days = 2
			}
		}
	}

	#go with the locals - castle only
	option = {
		name = ep3_contract_event.0006.castle
		trigger = {
			scope:task_contract_destination = {
				has_holding_type = castle_holding
			}
		}
		reason = castle_holding
		duel = {
			skills = { diplomacy intrigue }
			target = scope:local_1
			25 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					max = 50
				}
				desc = ep3_contract_event.0006.castle_won
				save_scope_value_as = {
					name = success_reason
					value = flag:castle
				}
				trigger_event = ep3_contract_event.0007
				show_as_tooltip = {
					scope:newly_created_artifact = {
						set_owner = root
					}
				}
			}
			25 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -1
					min = -49
				}
				modifier = {
					exists = scope:local_2
					add = scope:local_2.intrigue
					add = scope:local_2.diplomacy
				}
				desc = ep3_contract_event.0006.castle_lost_desc
				send_interface_toast = {
					type = event_toast_effect_bad
					title = ep3_contract_event.0006.castle_lost
					desc = ep3_contract_event.0006.castle_lost_desc
					left_icon = root
					right_icon = scope:local_1
					scope:newly_created_artifact = {
						set_owner = scope:local_1
					}
				}
			}
		}
		stress_impact = {
			compassionate = minor_stress_impact_gain
			deceitful = minor_stress_impact_loss
		}
		#AI should always try to complete the contract
		ai_chance = {
			base = 20
		}
	}
	#prove you're pious - church only
	option = {
		name = ep3_contract_event.0006.church
		trigger = {
			scope:task_contract_destination = {
				has_holding_type = church_holding
			}
		}
		reason = church_holding
		random_list = {
			4 = {
				modifier = {
					add = root.piety_level
				}
				modifier = {
					add = root.num_virtuous_traits
				}
				modifier = {
					add = {
						value = root.num_sinful_traits
						multiply = -1
					}
				}
				modifier = {
					add = root.learning
				}
				desc = ep3_contract_event.0006.church_won
				save_scope_value_as = {
					name = success_reason
					value = flag:church
				}
				trigger_event = ep3_contract_event.0007
				show_as_tooltip = {
					scope:newly_created_artifact = {
						set_owner = root
					}
				}
			}
			4 = {
				modifier = {
					add = scope:local_1.piety_level
				}
				modifier = {
					add = scope:local_1.num_virtuous_traits
				}
				modifier = {
					add = {
						value = scope:local_1.num_sinful_traits
						multiply = -1
					}
				}
				desc = ep3_contract_event.0006.church_lost_desc
				send_interface_toast = {
					type = event_toast_effect_bad
					title = ep3_contract_event.0006.church_lost
					desc = ep3_contract_event.0006.church_lost_desc
					left_icon = root
					right_icon = scope:local_1
					scope:newly_created_artifact = {
						set_owner = scope:local_1
					}
				}
			}
		}
		stress_impact = {
			cynical = minor_stress_impact_gain
			zealous = minor_stress_impact_loss
		}
		#AI should always try to complete the contract
		ai_chance = {
			base = 20
		}
	}
	#barter for lower price - city only
	option = {
		name = ep3_contract_event.0006.city
		trigger = {
			scope:task_contract_destination = {
				has_holding_type = city_holding
			}
		}
		reason = city_holding
		random_list = {
			1 = {
				modifier = {
					add = root.prestige_level
				}
				modifier = {
					add = root.dynasty.dynasty_prestige_level
				}
				modifier = {
					add = root.stewardship
				}
				desc = ep3_contract_event.0006.city_won
				save_scope_value_as = {
					name = success_reason
					value = flag:city
				}
				pay_short_term_gold = {
					target = scope:local_1
					gold = minor_gold_value
				}
				trigger_event = ep3_contract_event.0007
				show_as_tooltip = {
					scope:newly_created_artifact = {
						set_owner = root
					}
				}
			}
			1 = {
				modifier = {
					add = scope:local_1.prestige_level
				}
				modifier = {
					add = scope:local_1.dynasty.dynasty_prestige_level
				}
				desc = ep3_contract_event.0006.city_lost_desc
				send_interface_toast = {
					type = event_toast_effect_bad
					title = ep3_contract_event.0006.city_lost
					desc = ep3_contract_event.0006.city_lost_desc
					left_icon = root
					right_icon = scope:local_1
				}
			}
		}
		stress_impact = {
			generous = minor_stress_impact_gain
			greedy = minor_stress_impact_loss
		}
		#AI should always try to complete the contract
		ai_chance = {
			base = 20
			modifier = {
				factor = 0
				short_term_gold < minor_gold_value
			}
		}
	}
	#try to buy it - always
	option = {
		name = ep3_contract_event.0006.buy
		if = {
			limit = {
				scope:task_contract_destination = {
					has_holding_type = city_holding
				}
			}
			pay_short_term_gold = {
				target = scope:local_1
				gold = major_gold_value
			}
			save_scope_value_as = {
				name = success_reason
				value = flag:buy
			}
			trigger_event = ep3_contract_event.0007
			show_as_tooltip = {
				scope:newly_created_artifact = {
					set_owner = root
				}
			}
		}
		else = {
			duel = {
				skill = stewardship
				target = scope:local_1
				25 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = 2
						max = 50
					}
					desc = ep3_contract_event.0006.buy_won
					pay_short_term_gold = {
						target = scope:local_1
						gold = major_gold_value
					}
					save_scope_value_as = {
						name = success_reason
						value = flag:buy
					}
					trigger_event = ep3_contract_event.0007
					show_as_tooltip = {
						scope:newly_created_artifact = {
							set_owner = root
						}
					}
				}
				25 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = -1
						min = -49
					}
					modifier = {
						exists = scope:local_2
						add = scope:local_2.stewardship
					}
					desc = ep3_contract_event.0006.buy_lost_desc
					send_interface_toast = {
						type = event_toast_effect_bad
						title = ep3_contract_event.0006.buy_lost
						desc = ep3_contract_event.0006.buy_lost_desc
						left_icon = root
						right_icon = scope:local_1
						pay_short_term_gold = {
							target = scope:local_1
							gold = major_gold_value
						}
						scope:newly_created_artifact = {
							set_owner = scope:local_1
						}
					}
				}
			}
		}
		stress_impact = {
			greedy = minor_stress_impact_gain
			generous = minor_stress_impact_loss
		}
		#AI should always try to complete the contract
		ai_chance = {
			base = 20
			modifier = {
				factor = 0
				short_term_gold < major_gold_value
			}
		}
	}
	#intimidate them - freebooters and swords-for-hire only
	option = {
		name = ep3_contract_event.0006.intimidate
		trigger = {
			OR = {
				has_realm_law = camp_purpose_brigands
				has_realm_law = camp_purpose_mercenaries
			}
		}
		reason = purpose_brigands_and_mercenaries
		duel = {
			skills = { intrigue prowess }
			target = scope:local_1
			25 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					max = 50
				}
				desc = ep3_contract_event.0006.intimidate_won
				save_scope_value_as = {
					name = success_reason
					value = flag:intimidate
				}
				trigger_event = ep3_contract_event.0007
				show_as_tooltip = {
					scope:newly_created_artifact = {
						set_owner = root
					}
				}
			}
			25 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -1
					min = -49
				}
				modifier = {
					exists = scope:local_2
					add = scope:local_2.intrigue
					add = scope:local_2.prowess
				}
				desc = ep3_contract_event.0006.intimidate_lost_desc
				send_interface_toast = {
					type = event_toast_effect_bad
					title = ep3_contract_event.0006.intimidate_lost
					desc = ep3_contract_event.0006.intimidate_lost_desc
					left_icon = root
					right_icon = scope:local_1
					scope:newly_created_artifact = {
						set_owner = scope:local_1
					}
				}
			}
		}
		stress_impact = {
			compassionate = minor_stress_impact_gain
			wrathful = minor_stress_impact_loss
		}
		#AI should always try to complete the contract
		ai_chance = {
			base = 20
		}
	}
	#hit the local library - scholars and legitimists only
	option = {
		name = ep3_contract_event.0006.library
		trigger = {
			OR = {
				has_realm_law = camp_purpose_scholars
				has_realm_law = camp_purpose_legitimists
			}
		}
		reason = purpose_legitimists_and_scholars
		duel = {
			skill = learning
			value = decent_skill_rating
			25 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					max = 50
				}
				desc = ep3_contract_event.0006.library_won
				save_scope_value_as = {
					name = success_reason
					value = flag:library
				}
				hidden_effect = {
					destroy_artifact = scope:newly_created_artifact
				}
				custom_tooltip = ep3_contract_event.0006.library.tt
				trigger_event = ep3_contract_event.0007
			}
			25 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = ep3_contract_event.0006.library_lost_desc
				send_interface_toast = {
					type = event_toast_effect_bad
					title = ep3_contract_event.0006.library_lost
					desc = ep3_contract_event.0006.library_lost_desc
					left_icon = root
					hidden_effect = {
						if = {
							limit = {
								exists = scope:newly_created_artifact
							}
							destroy_artifact = scope:newly_created_artifact
						}
					}
				}
			}
		}
		stress_impact = {
			impatient = minor_stress_impact_gain
			patient = minor_stress_impact_loss
			stubborn = minor_stress_impact_loss
		}
		#AI should always try to complete the contract
		ai_chance = {
			base = 20
		}
	}
	#go on your own - wanderers and explorers only
	option = {
		name = ep3_contract_event.0006.explore
		trigger = {
			OR = {
				has_realm_law = camp_purpose_wanderers
				has_realm_law = camp_purpose_explorers
			}
		}
		reason = purpose_explorers_and_wanderers
		duel = {
			skills = { diplomacy martial }
			value = decent_skill_rating
			25 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					max = 50
				}
				desc = ep3_contract_event.0006.explore_won
				save_scope_value_as = {
					name = success_reason
					value = flag:explore
				}
				hidden_effect = {
					destroy_artifact = scope:newly_created_artifact
				}
				custom_tooltip = ep3_contract_event.0006.explore.tt
				trigger_event = ep3_contract_event.0007
			}
			25 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = ep3_contract_event.0006.explore_lost_desc
				send_interface_toast = {
					type = event_toast_effect_bad
					title = ep3_contract_event.0006.explore_lost
					desc = ep3_contract_event.0006.explore_lost_desc
					left_icon = root
					hidden_effect = {
						if = {
							limit = {
								exists = scope:newly_created_artifact
							}
							destroy_artifact = scope:newly_created_artifact
						}
					}
				}
			}
		}
		stress_impact = {
			impatient = minor_stress_impact_gain
			patient = minor_stress_impact_loss
			stubborn = minor_stress_impact_loss
		}
		#AI should always try to complete the contract
		ai_chance = {
			base = 20
		}
	}
}

scripted_effect change_treasure_type = {
	scope:newly_created_artifact = {
		if = {
			limit = {
				OR = {
					exists = scope:cupboard
					exists = scope:ark_covenant
					exists = scope:throne
					exists = scope:necklace_artifact
					exists = scope:armor_artifact
					exists = scope:weapon_artifact
					exists = scope:regalia_artifact
					#exists = scope:box
					#exists = scope:skull
					#exists = scope:goblet
					#exists = scope:animal_hide_size
					exists = scope:tapestry
				}
			}
			#do nothing, as they should already have the correct type
		}
		else_if = {
			limit = {
				OR = {
					has_variable = ascalon
					has_variable = staff_kakusandha
					has_variable = zomorrodnegar
					has_variable = aruval
					has_variable = sword_cid
					has_variable = sword_of_muhammad
					has_variable = mmaagha_kamalu
					has_variable = sword_attila
				}
			}
			reforge_artifact = { type = regalia }
		}
		else_if = {
			limit = { has_variable = iron_crown }
			reforge_artifact = { type = helmet }				
		}
		else_if = {
			limit = { artifact_type = pedestal }
			reforge_artifact = { type = miscellaneous }
		}
		set_owner = root
	}
}

#Treasure Hunting Contract - event triggered if you find an artifact in previous event ep3_contract_event.0006 to decide if you want to keep the artifact for yourself or complete the contract 
ep3_contract_event.0007 = {
	type = character_event
	title = ep3_contract_event.0007.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:success_reason = flag:castle
					scope:task_contract_destination = {
						has_holding_type = castle_holding
					}
				}
				desc = ep3_contract_event.0007.desc_castle_castle
			}
			triggered_desc = {
				trigger = {
					scope:success_reason = flag:church
					scope:task_contract_destination = {
						has_holding_type = church_holding
					}
				}
				desc = ep3_contract_event.0007.desc_church_church
			}
			triggered_desc = {
				trigger = {
					scope:success_reason = flag:city
					scope:task_contract_destination = {
						has_holding_type = city_holding
					}
				}
				desc = ep3_contract_event.0007.desc_city_city
			}
			triggered_desc = {
				trigger = {
					scope:success_reason = flag:buy
					scope:task_contract_destination = {
						has_holding_type = castle_holding
					}
				}
				desc = ep3_contract_event.0007.desc_castle_buy
			}
			triggered_desc = {
				trigger = {
					scope:success_reason = flag:buy
					scope:task_contract_destination = {
						has_holding_type = city_holding
					}
				}
				desc = ep3_contract_event.0007.desc_city_buy
			}
			triggered_desc = {
				trigger = {
					scope:success_reason = flag:buy
					scope:task_contract_destination = {
						has_holding_type = church_holding
					}
				}
				desc = ep3_contract_event.0007.desc_church_buy
			}
			triggered_desc = {
				trigger = {
					scope:success_reason = flag:intimidate
					scope:task_contract_destination = {
						has_holding_type = castle_holding
					}
				}
				desc = ep3_contract_event.0007.desc_castle_intimidate
			}
			triggered_desc = {
				trigger = {
					scope:success_reason = flag:intimidate
					scope:task_contract_destination = {
						has_holding_type = city_holding
					}
				}
				desc = ep3_contract_event.0007.desc_city_intimidate
			}
			triggered_desc = {
				trigger = {
					scope:success_reason = flag:intimidate
					scope:task_contract_destination = {
						has_holding_type = church_holding
					}
				}
				desc = ep3_contract_event.0007.desc_church_intimidate
			}
			triggered_desc = {
				trigger = { scope:success_reason = flag:library } 
				desc = ep3_contract_event.0007.desc_library
			}
			triggered_desc = {
				trigger = { scope:success_reason = flag:explore } 
				desc = ep3_contract_event.0007.desc_explore
			}
		}
	}
	theme = travel

	left_portrait = {
		character = root
		animation = happiness
	}
	right_portrait = {
		character = scope:local_1
		trigger = {
			NOR = {
				scope:success_reason = flag:library
				scope:success_reason = flag:explore
			}
		}
		animation = rage
	}
	lower_left_portrait = {
		character = scope:task_contract_employer
	}
	lower_right_portrait = {
		trigger = {
			exists = scope:local_2
			NOR = {
				scope:success_reason = flag:library
				scope:success_reason = flag:explore
			}
		}
		character = scope:local_2
	}
	#artifact you find
	artifact = {
        target = scope:newly_created_artifact
        position = lower_center_portrait
	}

	override_background = {
		trigger = { 
			OR = {
				scope:success_reason = flag:library
				scope:success_reason = flag:explore
			}
		}
		reference = wilderness
	}
	override_background = {
		trigger = { 
			scope:task_contract_destination = {
				has_holding_type = castle_holding
			}
		}
		reference = corridor_night
	}
	override_background = {
		trigger = { 
			scope:task_contract_destination = {
				has_holding_type = city_holding
			}
		}
		reference = market
	}
	override_background = {
		trigger = { 
			scope:task_contract_destination = {
				has_holding_type = church_holding
			}
		}
		reference = temple
	}
	override_background = {
		trigger = { 
			scope:task_contract_destination = {
				NOR = {
					has_holding_type = castle_holding
					has_holding_type = city_holding
					has_holding_type = church_holding
				}
			}
		}
		reference = tavern
	}

	immediate = {
		random_courtier = {
			limit = {
				is_adult = yes
			}
			save_scope_as = follower
		}
		if = {
			limit = {
				OR = {
					scope:success_reason = flag:library
					scope:success_reason = flag:explore
				}
			}
			inspiration_adventure_create_artifact_effect = {
				OWNER = root
				CREATOR = root
			}
			add_gold = major_gold_value
		}
		if = {
			limit = {
				scope:success_reason = flag:city	
			}
			change_treasure_type = yes
			scope:newly_created_artifact = {
				set_owner = root
			}
			inspiration_adventure_create_artifact_effect = {
				OWNER = scope:local_1
				CREATOR = scope:local_1
			}
		}
	}

	#give it back to locals so they join you
	option = {
		name = ep3_contract_event.0007.castle
		trigger = {
			scope:success_reason = flag:castle
		}
		scope:newly_created_artifact = {
			set_owner = scope:local_1
		}
		add_courtier = scope:local_1
		add_courtier = scope:local_2

		stress_impact = {
			greedy = minor_stress_impact_gain
			compassionate = minor_stress_impact_loss
		}
		#AI should always complete the contract
		ai_chance = {
			base = 0
		}
	}
	#pay them more so they join you
	option = {
		name = ep3_contract_event.0007.castle_buy
		trigger = {
			scope:success_reason = flag:buy
			scope:task_contract_destination = {
				has_holding_type = city_holding
			}
		}
		pay_short_term_gold = {
			target = scope:local_2
			gold = major_gold_value
		}
		add_courtier = scope:local_1
		add_courtier = scope:local_2

		stress_impact = {
			greedy = minor_stress_impact_gain
			compassionate = minor_stress_impact_loss
		}
		#AI should always complete the contract
		ai_chance = {
			base = 0
		}
	}
	#Buy everything for yourself
	option = {
		name = ep3_contract_event.0007.city_city
		trigger = {
			scope:success_reason = flag:city
		}
		pay_short_term_gold = {
			target = scope:local_1
			gold = major_gold_value
		}
		change_treasure_type = yes
		scope:newly_created_artifact = {
			set_owner = scope:local_1
		}

		stress_impact = {
			content = minor_stress_impact_gain
			greedy = minor_stress_impact_loss
		}
		#AI should always complete the contract
		ai_chance = {
			base = 0
		}
	}
	#after all, why wouldn't I take it for myself?
	option = {
		name = ep3_contract_event.0007.a
		if = {
			limit = {
				NOT = { scope:success_reason = flag:city }
			}
			change_treasure_type = yes
		}
		if = {
			limit = {
				scope:success_reason = flag:castle
			}
			set_relation_rival = {
				target = scope:local_1
				reason = rival_stole_artifact
			}
			set_relation_rival = {
				target = scope:local_2
				reason = rival_stole_artifact
			}
		}

		stress_impact = {
			content = minor_stress_impact_gain
			compassionate = minor_stress_impact_gain
			greedy = minor_stress_impact_loss
		}
		#AI should always complete the contract
		ai_chance = {
			base = 0
		}
	}
	#give it back to task_contract_employer to complete the contract
	option = {
		name = ep3_contract_event.0007.b
		scope:newly_created_artifact = {
			set_owner = scope:task_contract_employer
		}
		scope:task_contract = {
			complete_task_contract = success_standard
		}
		if = {
			limit = {
				scope:success_reason = flag:castle
			}
			set_relation_rival = {
				target = scope:local_1
				reason = rival_stole_artifact
			}
			set_relation_rival = {
				target = scope:local_2
				reason = rival_stole_artifact
			}
		}
		#AI should always complete the contract
		ai_chance = {
			base = 10
		}
	}
	after = {
		if = {
			limit = {
				can_set_relation_rival_trigger = { CHARACTER = scope:local_ruler }
				scope:success_reason = flag:castle
			}
			progress_towards_rival_effect = {
				REASON = rival_stole_artifact
				CHARACTER = scope:local_ruler
				OPINION = default_rival_opinion
			}
		}
	}
}

#Join war contract - joining the war
ep3_contract_event.0008 = {
	type = character_event
	title = ep3_contract_event.0008.t
	desc = ep3_contract_event.0008.desc
	theme = war
	#task_contract_taker, you
	left_portrait = {
		character = root
		animation = inspect_weapon
	}
	right_portrait = {
		character = scope:commander
		animation = personality_callous
	}
	#character giving you the contract
	lower_right_portrait = {
		character = scope:task_contract_employer
	}
	#character you have to fight in a war
	lower_left_portrait = {
		character = scope:task_contract_target
	}

	immediate = {
		set_contract_scopes_effect = yes
		scope:task_contract_employer = {
			random_knight = {
				save_scope_as = commander
			}
		}
		scope:commander = {
			add_character_flag = need_military_outfit
		}
	}

	#take the contract and join the war
	option = {
		name = ep3_contract_event.0008.a
		highlight_portrait = scope:task_contract_employer
		scope:task_contract_war = {
			hidden_effect = { set_called_to = root }
			if = {
				limit = {
					is_attacker = scope:task_contract_employer
				}
				add_attacker = root
			}
			else = {
				add_defender = root
			}
		}
		custom_tooltip = join_war_contract.employer_military_strength
		custom_tooltip = join_war_contract.target_military_strength
		#AI should always complete the contract
		ai_chance = {
			base = 10
		}
	}
	#invalidate the contract
	option = {
		name = ep3_contract_event.0001.invalidate
		scope:task_contract = {
			invalidate_contract = yes
		}
		#AI should always try to complete the contract
		ai_chance = {
			base = 0
		}
	}
	after = {
		scope:commander = {
			remove_character_flag = need_military_outfit
		}
	}
}

#Reclaim Artifact contract - start event
ep3_contract_event.0009 = {
	type = character_event
	title = ep3_contract_event.0009.t
	desc = ep3_contract_event.0009.desc
	theme = intrigue
	#task_contract_taker, you
	left_portrait = {
		character = root
		animation = scheme
	}
	#character giving you the contract
	right_portrait = {
		character = scope:task_contract_employer
		animation = bribing
	}
	#character you have to steal from
	lower_right_portrait = {
		character = scope:task_contract_target
	}
	#artifact you have to steal
	artifact = {
        target = scope:task_contract_object
        position = lower_center_portrait
	}

	immediate = {
		set_contract_scopes_effect = yes
	}
	#take the contract and start scheme to steal the artifact
	option = {
		name = ep3_contract_event.0009.a
		custom_tooltip = ep3_contract_event.0009.open_start_stealing_back_artifact
		if = {
			limit = {
				is_ai = yes
			}
			begin_contract_scheme_with_agents_effect = {
				SCHEME_TYPE = steal_back_artifact
				TARGET_TYPE = target_character
				TARGET_SCOPE = scope:task_contract_target
				TASK_CONTRACT = scope:task_contract
				# Success.
				AGENT_1 = agent_thief
				AGENT_2 = agent_thief
				# Speed.
				AGENT_3 = agent_infiltrator
				AGENT_4 = agent_infiltrator
				# Secrecy.
				AGENT_5 = agent_lookout
			}
			scope:new_scheme ?= {
				set_variable = {
					name = target_artifact
					value = scope:task_contract_object
				}
			}
		}
		else = {
			open_interaction_window = {
				interaction = start_stealing_back_artifact
				actor = root
				recipient = scope:task_contract_target
			}
		}
		#AI should always complete the contract
		ai_chance = {
			base = 10
		}
	}
	#take the contract, but only unlock the steal artifact interaction
	option = {
		name = ep3_contract_event.0009.b
		#AI should always complete the contract
		ai_chance = {
			base = 0
		}
	}
}

#transport contract completion event - triggered whenever you have an active transport contract and pass through a contract location
ep3_contract_event.0011 = {
	type = character_event
	title = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:task_contract = { has_task_contract_type = laamp_transport_vip } }
				desc = ep3_contract_event.0011.t_vip
			}
			triggered_desc = {
				trigger = { scope:task_contract = { has_task_contract_type = laamp_transport_ward } }
				desc = ep3_contract_event.0011.t_child
			}
			triggered_desc = {
				trigger = { scope:task_contract = { has_task_contract_type = laamp_transport_explorer } }
				desc = ep3_contract_event.0011.t_explorer
			}
			triggered_desc = {
				trigger = { scope:task_contract = { has_task_contract_type = laamp_transport_artifact } }
				desc = ep3_contract_event.0011.t_artifact
			}
			triggered_desc = {
				trigger = { scope:task_contract = { has_task_contract_type = laamp_transport_gold } }
				desc = ep3_contract_event.0011.t_gold
			}
			triggered_desc = {
				trigger = { scope:task_contract = { has_task_contract_type = laamp_transport_animal } }
				desc = ep3_contract_event.0011.t_animal
			}
			triggered_desc = {
				trigger = { scope:task_contract = { has_task_contract_type = laamp_construction_contract } }
				desc = ep3_contract_event.0011.t_construction
			}
		}
	}
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:task_contract = { has_task_contract_type = laamp_transport_vip } }
				desc = ep3_contract_event.0011.desc_vip
			}
			triggered_desc = {
				trigger = { scope:task_contract = { has_task_contract_type = laamp_transport_ward } }
				desc = {
					desc = ep3_contract_event.0011.desc_ward
					first_valid = {
						triggered_desc = {
							trigger = { scope:ward_too_old ?= yes }
							desc = ep3_contract_event.0011.desc_ward_too_old
						}
						triggered_desc = {
							trigger = { scope:ward_limit ?= yes }
							desc = ep3_contract_event.0011.desc_ward_limit
						}
						desc = ep3_contract_event.0011.desc_ward_accepted
					}
				}
			}
			triggered_desc = {
				trigger = { scope:task_contract = { has_task_contract_type = laamp_transport_explorer } }
				desc = {
					first_valid = {
						triggered_desc = {
							trigger = {
								scope:task_contract.var:travel_reason = {
									OR = {
										flag:capitals ?= this
										flag:grand_city ?= this
										flag:mausoleum_at_halicarnassus ?= this
										flag:lighthouse_of_alexandria ?= this
									}
								}
							}
							desc = ep3_contract_event.0011.desc_explorer_other
						}
						desc = ep3_contract_event.0011.desc_explorer_building
					}
				}
			}
			triggered_desc = {
				trigger = { scope:task_contract = { has_task_contract_type = laamp_transport_artifact } }
				desc = ep3_contract_event.0011.desc_artifact
			}
			triggered_desc = {
				trigger = { scope:task_contract = { has_task_contract_type = laamp_transport_gold } }
				desc = ep3_contract_event.0011.desc_gold
			}
			triggered_desc = {
				trigger = { scope:task_contract = { has_task_contract_type = laamp_transport_animal } }
				desc = {
					first_valid = {
						triggered_desc = {
							trigger = {
								scope:task_contract.var:escorted_story ?= { story_type = story_cycle_pet_dog } 
								scope:hates_pets ?= yes
							}
							desc = ep3_contract_event.0011.desc_animal_dog_hate
						}
						triggered_desc = {
							trigger = { scope:task_contract.var:escorted_story ?= { story_type = story_cycle_pet_dog } }
							desc = ep3_contract_event.0011.desc_animal_dog_love
						}
						triggered_desc = {
							trigger = {
								scope:task_contract.var:escorted_story ?= { story_type = story_cycle_pet_cat }
								scope:hates_pets ?= yes
							}
							desc = ep3_contract_event.0011.desc_animal_cat_hate
						}
						triggered_desc = {
							trigger = { scope:task_contract.var:escorted_story ?= { story_type = story_cycle_pet_cat } }
							desc = ep3_contract_event.0011.desc_animal_cat_love
						}
					}
				}
			}
			triggered_desc = {
				trigger = { scope:task_contract = { has_task_contract_type = laamp_construction_contract } }
				desc = ep3_contract_event.0011.desc_construction
			}
		}
	}
	theme = landless_adventurer
	override_background = { reference = throne_room }
	left_portrait = {
		character = root
		animation = war_over_win
	}
	right_portrait = {
		trigger = { exists = scope:task_contract_target }
		character = scope:task_contract_target
		animation = personality_compassionate
	}
	lower_right_portrait = {
		trigger = {
			exists = scope:task_contract_employer
			NOT = { scope:task_contract_target ?= scope:task_contract_employer }
		}
		character = scope:task_contract_employer
	}
	lower_left_portrait = {
		trigger = {
			exists = scope:task_contract_object 
			NOR = {
				scope:task_contract_target = scope:task_contract_object
				scope:task_contract_employer = scope:task_contract_object
			}
		}
		character = scope:task_contract_object
	}
	artifact = {
		trigger = { exists = scope:escorted_artifact }
        target = scope:escorted_artifact
        position = lower_center_portrait
	}

	immediate = {
		set_contract_scopes_effect = yes
		scope:task_contract = {
			switch = {
				trigger = has_task_contract_type
				laamp_transport_vip = {
					root.current_travel_plan = { remove_character = scope:task_contract_object }
					scope:task_contract_object = {
						remove_variable = blocked_from_leaving
						visit_court_of = scope:task_contract_target
					}
				}
				laamp_transport_ward = {
					root.current_travel_plan = { remove_character = scope:task_contract_object }
					if = {
						limit = {
							scope:task_contract_object = {
								is_adult = yes
							}
						}
						save_scope_value_as = {
							name = ward_too_old
							value = yes
						}
					}
					else_if = {
						limit = {
							scope:task_contract_target = {
								num_of_relation_ward > 1
							}
						}
						save_scope_value_as = {
							name = ward_limit
							value = yes
						}
					}
					else = {
						scope:task_contract_object = {
							if = {
								limit = {
									any_relation = {
										type = guardian
									}
								}
								random_relation = {
									type = guardian
									save_scope_as = old_guardian
								}
								remove_guardian_effect = {
									GUARDIAN = scope:old_guardian
									WARD = scope:task_contract_object
									RETURN_WARD = no
									HIDE_OPINION = no
								}
							}
							remove_variable = blocked_from_leaving
							visit_court_of = scope:task_contract_target
							set_relation_guardian = scope:task_contract_target
							save_scope_as = ward
							scope:task_contract_target = {
								save_scope_as = guardian
							}
							scope:task_contract_employer = {
								save_scope_as = ward_liege
							}
							trigger_event = { on_action = on_ward_arrive_at_guardian }	
						}
					}
					scope:task_contract_object = {
						progress_towards_friend_effect = {
							REASON = friend_random_fallback
							CHARACTER = root
							OPINION = default_friend_opinion
						}
					}
				}
				laamp_transport_explorer = {
					root.current_travel_plan = { remove_character = scope:task_contract_object }
					scope:task_contract_object = {
						remove_variable = blocked_from_leaving
						save_scope_as = task_contract_target
					}
				}
				laamp_transport_artifact = {
					scope:escorted_artifact = {
						set_owner = scope:task_contract_target
						set_variable = {
							name = ungiftable
						}
					}
				}
				laamp_transport_gold = {
					root = {
						pay_treasury_or_gold = {
							target = scope:task_contract_target
							value = scope:task_contract.var:escorted_gold
						}
					}
					scope:task_contract_employer = {
						if = {
							limit = {
								can_add_hook = {
									target = scope:task_contract_target
									type = indebted_hook
								}
							}
							add_hook = {
								target = scope:task_contract_target
								type = indebted_hook
							}
						}
					}
				}
				laamp_transport_animal = {
					#give them the whole story cycle for pets
					if = {
						limit = {
							scope:escorted_story = { story_type = story_cycle_pet_dog }
						}
						root = {
							transfer_dog_story_cycle_to_effect = {
								CHARACTER = scope:task_contract_target
								STORY = scope:escorted_story
							}
						}
					}
					else = {
						root = {
							transfer_cat_story_cycle_to_effect = {
								CHARACTER = scope:task_contract_target
								STORY = scope:escorted_story
							}
						}
						scope:escorted_story = {
							set_variable = {
								name = gifted_pet_story
								value = scope:task_contract_employer
							}
						}
					}
					scope:task_contract_target = {
						if = {
							limit = { #"What am I supposed to do with this??"
								OR = {
									has_personality_malicious_trigger = yes
									AND = {
										scope:escorted_story = { story_type = story_cycle_pet_cat }
										has_character_modifier = cat_story_allergy_modifier
									}
									AND = {
										scope:escorted_story = { story_type = story_cycle_pet_dog }
										faith = { religion_tag = islam_religion }
									}
								}
							}
							save_scope_value_as = {
								name = hates_pets
								value = yes
							}
							add_opinion = {
								target = scope:task_contract_employer
								modifier = dumped_animal_on_me_opinion
							}
						}
						else = {
							add_opinion = {
								target = scope:task_contract_employer
								modifier = grateful_opinion
								opinion = 15
							}
						}
					}
				}
				laamp_construction_contract = {
					scope:task_contract_destination = {
						county = {
							add_county_modifier = {
								modifier = massive_construction_efforts_modifier
								years = 5
							}
						}
					}
				}
			}
		}
	}

	option = {
		name = ep3_contract_event.0011.a
		trigger = {
			scope:task_contract = {
				has_task_contract_type = laamp_construction_contract
			}
		}
		add_character_modifier = ep3_construction_contract_modifier
		custom_tooltip = ep3_contract_event.0011.construction_invalidation
		show_as_tooltip = {
			custom_tooltip = ep3_contract_event.0011.construction_reward
			scope:task_contract = { complete_task_contract = success_critical }
		}
		if = {
			limit = {
				current_travel_plan ?= {
					is_travel_with_domicile = no
				}
			}
			current_travel_plan ?= {
				abort_travel_plan = yes
			}
			save_scope_value_as = {
				name = provision_to_gold_conversion_value
				value = {
					value = root.domicile.provision_cost_to_owner
					add = root.domicile.provisions
				}
			}
			if = {
				limit = {
					scope:provision_to_gold_conversion_value < 0
				}
				domicile = {
					change_provisions = {
						value = 0
						subtract = root.domicile.provisions
					}
				}
				add_gold = {
					value = scope:provision_to_gold_conversion_value
					multiply = 0.1
				}
			}
			else = {
				domicile = {
					change_provisions = root.domicile.provision_cost_to_owner
				}
			}
		}
		#AI should have a small chance to move the domicile
		ai_chance = {
			base = 2
		}
	}

	option = {
		name = ep3_contract_event.0011.b
		trigger = {
			scope:task_contract = {
				has_task_contract_type = laamp_transport_explorer
				task_contract_employer = {
					is_landed = no
				}
			}
		}
		add_courtier = scope:task_contract_object
		current_travel_plan = {
			add_companion = scope:task_contract_object
		}
		#AI should be willing to take more people, as it's probably their best bet to get them
		ai_chance = {
			base = 20
		}
	}

	option = {
		name = ep3_contract_event.0011.c
		trigger = {	scope:ward_limit ?= yes	}
		duel = {
			skill = diplomacy
			value = scope:task_contract_target.diplomacy
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
				}
				scope:task_contract_target = {
					random_relation = {
						type = ward
						save_scope_as = current_ward
					}
					remove_guardian_effect = {
						GUARDIAN = scope:task_contract_target
						WARD = scope:current_ward
						RETURN_WARD = yes
						HIDE_OPINION = yes
					}
				}
				scope:task_contract_object = {
					remove_variable = blocked_from_leaving
					visit_court_of = scope:task_contract.var:task_contract_target
					set_relation_guardian = scope:task_contract.var:task_contract_target
					save_scope_as = ward
					scope:task_contract.var:task_contract_target = {
						save_scope_as = guardian
					}
					scope:task_contract.var:task_contract_employer = {
						save_scope_as = ward_liege
					}
					trigger_event = { on_action = on_ward_arrive_at_guardian }	
				}
				save_scope_value_as = {
					name = ward_limit
					value = no
				}
			}
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = 5
				}
				scope:task_contract_target = {
					add_opinion = {
						target = root
						modifier = insulted_opinion
						opinion = -20
					}
				}
			}
		}
		#AI should always try to complete the contract
		ai_chance = {
			base = 20
		}
	}

	option = {
		name = {
			trigger = {
				any_task_contract = {
					save_temporary_scope_as = temp_contract
					task_contract_taker ?= {
						this = root
					}				
					root.current_travel_plan = {
						any_future_path_location = {
							this = scope:temp_contract.task_contract_destination
						}
					}
				}
			}
			text = ep3_contract_event.0011.d_continue
		}
		name = {
			trigger = {
				always = yes
			}
			text = ep3_contract_event.0011.d_end
		}
		if = {
			limit = {
				scope:task_contract = {
					has_task_contract_type = laamp_construction_contract
				}
			}
			scope:task_contract = {
				complete_task_contract = success_standard
			}
		}
		#AI should always complete the contract
		ai_chance = {
			base = 1
			modifier = {
				add = 1000
				#AI should keep going if other contracts are on the travel path
				any_task_contract = {
					save_temporary_scope_as = temp_contract
					task_contract_taker ?= {
						this = root
					}				
					root.current_travel_plan = {
						any_future_path_location = {
							this = scope:temp_contract.task_contract_destination
						}
					}
				}
			}
		}
	}

	after = {
		scope:task_contract = {
			switch = {
				trigger = has_task_contract_type
				laamp_transport_vip = {
					if = {
						limit = {
							var:task_contract_object ?= {
								is_alive = no
							}
						}
						complete_task_contract = failure_standard
					}
					else_if = {
						limit = {
							time_since_contract_taken > 360
						}
						complete_task_contract = success_standard
					}
					else = {
						complete_task_contract = success_critical
					}
				}
				laamp_transport_artifact = {
					if = {
						limit = {
							OR = {
								NOT = { exists = scope:task_contract.var:escorted_artifact }
								scope:task_contract.var:escorted_artifact ?= {
									artifact_durability < 1
								}
							}
						}
						complete_task_contract = transport_destroyed
					}
					else_if = {
						limit = {
							time_since_contract_taken > 360
						}
						complete_task_contract = success_standard
					}
					else = {
						complete_task_contract = success_critical
					}
				}
				laamp_transport_gold = {
					complete_task_contract = success_standard
				}
				laamp_transport_ward = {
					if = {
						limit = {
							OR = {
								scope:ward_limit ?= yes
								scope:ward_too_old ?= yes
							}
						}
						complete_task_contract = failure_standard
					}
					else = {
						complete_task_contract = success_standard
					}
				}
				laamp_transport_explorer = {
					if = {
						limit = {
							time_since_contract_taken > 360
						}
						complete_task_contract = success_standard
					}
					else = {
						complete_task_contract = success_critical
					}
				}
				laamp_transport_animal = {
					complete_task_contract = success_standard
				}
			}
		}
	}
}

#transport contract invalidated - triggered whenever a transport contract is invalidated for any reason
#on_invalidation has to specify scope:task_contract_invalidation_reason
ep3_contract_event.0012 = {
	type = letter_event
	opening = {
		triggered_desc = {
			trigger = {
				OR = {
					scope:task_contract_invalidation_reason = flag:escortee_dead
					scope:task_contract_invalidation_reason = flag:pet_dead
				}
			}
			desc = ep3_contract_event.0012.opening_angry
		}
		triggered_desc = {
			trigger = {
				OR = {
					scope:task_contract_invalidation_reason = flag:employer_dead
					scope:task_contract_invalidation_reason = flag:target_dead
					scope:task_contract_invalidation_reason = flag:prisoner_free
					scope:task_contract_invalidation_reason = flag:not_vassal
					scope:task_contract_invalidation_reason = flag:unlanded_employer_is_imprisoned
					scope:task_contract_invalidation_reason = flag:faction_disbanded
				}
			}
			desc = ep3_contract_event.0012.opening
		}
	}
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:task_contract_invalidation_reason = flag:employer_dead }
				desc = ep3_contract_event.0012.desc_employer_dead
			}
			triggered_desc = {
				trigger = { scope:task_contract_invalidation_reason = flag:target_dead	}
				desc = ep3_contract_event.0012.desc_target_dead
			}
			triggered_desc = {
				trigger = { scope:task_contract_invalidation_reason = flag:escortee_dead }
				desc = ep3_contract_event.0012.desc_escortee_dead
			}
			triggered_desc = {
				trigger = { scope:task_contract_invalidation_reason = flag:pet_dead }
				desc = ep3_contract_event.0012.desc_pet_dead
			}
			triggered_desc = {
				trigger = { scope:task_contract_invalidation_reason = flag:prisoner_free }
				desc = ep3_contract_event.0012.desc_prisoner_free
			}
			triggered_desc = {
				trigger = { scope:task_contract_invalidation_reason = flag:not_vassal }
				desc = ep3_contract_event.0012.desc_not_vassal
			}
			triggered_desc = {
				trigger = { scope:task_contract_invalidation_reason = flag:unlanded_employer_is_imprisoned }
				desc = ep3_contract_event.0012.desc_unlanded_employer_is_imprisoned
			}
			triggered_desc = {
				trigger = { scope:task_contract_invalidation_reason = flag:faction_disbanded }
				desc = ep3_contract_event.0012.desc_faction_disbanded
			}
		}
	}
	sender = scope:sender
	immediate = {
		if = {
			limit = {
				exists = current_travel_plan
				NOT = { exists = scope:travel_destination }
			}
			current_travel_plan.final_destination_province = {
				save_scope_as = travel_destination
			}
		}
		#For those with heirs
		if = {
			limit = { exists = scope:employer_heir }
			scope:employer_heir = { save_scope_as = sender }
		}
		#Or just the employer, straight up
		else = {
			scope:task_contract_employer = { save_scope_as = sender }
		}
		#Remove the treasure map
		if = {
			limit = {
				var:invalidated_task_contract_type = flag:laamp_treasure_map_contract
			}
			random_character_artifact = {
				limit = { has_variable = 1025_treasure_map }
				hidden_effect = { destroy_artifact = this }
			}
			#Remove the employer from your camp
			if = {
				limit = { 
					scope:task_contract_employer = { is_courtier_of = root }
				}
				remove_courtier_or_guest = scope:task_contract_employer
			}
			#Mysterious
			custom_tooltip = treasure_map_disappeared.tt
		}
		#stuff that would be nice to see in tooltip, but is already executed in on_invalidation
		show_as_tooltip = {
			if = {
				limit = {
					scope:task_contract_object ?= { is_alive = yes }
				}
				scope:task_contract_object = { return_to_court = yes }
			}
		}
		switch = {
			trigger = scope:task_contract_invalidation_reason
			#employer or target died, get gold compensation
			flag:employer_dead = { add_gold = task_contract_invalidated_gold_gain_value }
			flag:target_dead = { add_gold = task_contract_invalidated_gold_gain_value }
			#character or pet you were suppose to escort died
			flag:escortee_dead = {
				add_prestige = task_contract_failure_prestige_loss_full_value
				scope:task_contract_employer = {
					progress_towards_rival_effect = {
						REASON = rival_escortee_died
						CHARACTER = root
						OPINION = default_rival_opinion
					}
				}
			}
			flag:pet_dead = {
				add_prestige = task_contract_failure_prestige_loss_full_value
				scope:task_contract_employer = {
					progress_towards_rival_effect = {
						REASON = rival_escortee_died
						CHARACTER = root
						OPINION = default_rival_opinion
					}
				}
			}
			flag:prisoner_free = { add_gold = task_contract_invalidated_gold_gain_value }
			flag:unlanded_employer_is_imprisoned = {
				#Nothing for you. They're unlanded.
			}
			flag:not_vassal = {
				add_gold = task_contract_invalidated_gold_gain_value
			}
			flag:faction_disbanded = {
				add_gold = task_contract_invalidated_gold_gain_value
			}
		}
	}
	#Let's head home
	option = {
		name = {
			trigger = {
				OR = {
					scope:task_contract_invalidation_reason = flag:employer_dead
					scope:task_contract_invalidation_reason = flag:target_dead
					scope:task_contract_invalidation_reason = flag:prisoner_free
					scope:task_contract_invalidation_reason = flag:not_vassal
					scope:task_contract_invalidation_reason = flag:faction_disbanded
				}
			}
			text = ep3_contract_event.0012.a
		}
		name = {
			trigger = {
				OR = {
					scope:task_contract_invalidation_reason = flag:escortee_dead
					scope:task_contract_invalidation_reason = flag:pet_dead
					scope:task_contract_invalidation_reason = flag:unlanded_employer_is_imprisoned
				}
			}
			text = ep3_contract_event.0012.b
		}
		return_home = yes
		ai_chance = {
			base = 10
		}
	}
	#Keep going
	option = {
		name = ep3_contract_event.0012.c
		trigger = {	exists = scope:travel_destination }
		ai_chance = {
			base = 0
		}
	}
	after = {
		remove_variable = invalidated_task_contract_type
	}
}

#Join war contract success/failure = triggered when war ends in war_on_actions
ep3_contract_event.0013 = {
	type = letter_event
	sender = scope:task_contract_employer
	opening = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:task_contract_reward = flag:success_standard }
				desc = ep3_contract_event.0013.opening_success
			}
			triggered_desc = {
				trigger = { scope:task_contract_reward = flag:failure_standard }
				desc = ep3_contract_event.0013.opening_failure
			}
		}
	}
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:task_contract_reward = flag:success_standard }
				desc = ep3_contract_event.0013.desc_success
			}
			triggered_desc = {
				trigger = { scope:task_contract_reward = flag:failure_standard }
				desc = ep3_contract_event.0013.desc_failure
			}
		}
	}

	immediate = {
		#save scopes for ep3_hire_laamp_mercs_payment_value scripted value to work
		save_scope_as = laamp_temp
		scope:task_contract_employer = {
			save_scope_as = employer
		}
		save_scope_value_as = {
			name = war_contribution_value
			value = "scope:war.war_contribution(scope:laamp_temp)"
		}
	}
	option = {
		name = ep3_contract_event.0013.a
		trigger = { scope:task_contract_reward = flag:success_standard }
		scope:task_contract_employer = {
			pay_treasury_or_gold = {
				target = scope:task_contract_taker
				value = ep3_hire_laamp_mercs_payment_value
			}
		}
		scope:laamp_temp = {
			if = {
				limit = {
					faith != scope:task_contract.var:task_contract_target.faith
				}
				add_piety = {
					value = "scope:war.war_contribution(scope:laamp_temp)"
					divide = 100
					min = minor_piety_gain
					max = massive_piety_gain
				} 
			}
		}
		ai_chance = {
			base = 1
		}
	}
	option = {
		name = ep3_contract_event.0013.b
		trigger = { scope:task_contract_reward = flag:failure_standard }

		ai_chance = {
			base = 1
		}
	}
}

#Protect Heritage - start event to help getting a title revocation rights vassal contract
ep3_contract_event.0020 = {
	type = character_event
	title = ep3_contract_event.0020.t
	desc = ep3_contract_event.0020.desc
	theme = intrigue
	#contract_taker, you
	left_portrait = {
		character = root
		animation = personality_compassionate
	}
	#character giving you the contract
	lower_right_portrait = {
		character = scope:task_contract_employer
	}
	#character you have to fight in a war
	lower_left_portrait = {
		character = scope:task_contract_target
	}

	immediate = {
		set_contract_scopes_effect = yes
	}

	#use hook
	option = {
		name = ep3_contract_event.0020.a
		trigger = {
			has_hook = scope:task_contract_target
		}
		show_as_unavailable = {
			NOT = { has_hook = scope:task_contract_target }
		}
		reason = hook
		remove_hook  =  { target = scope:task_contract_target }
		scope:task_contract_employer = {
			vassal_contract_set_obligation_level = {
				type = title_revocation_rights
				level = 1
			}
		}
		scope:task_contract = {
			complete_task_contract = success_standard
		}
	}
	#intrigue
	option = {
		name = ep3_contract_event.0020.b
		trigger = {
			OR = {
				has_realm_law = camp_purpose_wanderers
				has_realm_law = camp_purpose_explorers
			}
		}
		reason = purpose_explorers_and_wanderers
		begin_contract_scheme_with_agents_effect = {
			SCHEME_TYPE = protect_minority_vassal_contract_intrigue_scheme
			TARGET_TYPE = target_character
			TARGET_SCOPE = scope:task_contract_target
			TASK_CONTRACT = scope:task_contract
			# Success.
			AGENT_1 = agent_thug
			AGENT_2 = agent_shill
			AGENT_3 = agent_wrangler
			# Speed.
			AGENT_4 = agent_infiltrator
			AGENT_5 = agent_socialite
		}
		scope:task_contract.scheme = {
			save_scope_as = scheme
		}
		trigger_event = laamp_extra_contract_schemes.0001
		custom_tooltip = ep3_contract_event.0020.agents_intrigue
		custom_tooltip = ep3_contract_event.0020.tt
	}
	#martial
	option = {
		name = ep3_contract_event.0020.c
		trigger = {
			OR = {
				has_realm_law = camp_purpose_brigands
				has_realm_law = camp_purpose_mercenaries
			}
		}
		reason = purpose_brigands_and_mercenaries
		begin_contract_scheme_with_agents_effect = {
			SCHEME_TYPE = protect_minority_vassal_contract_martial_scheme
			TARGET_TYPE = target_character
			TARGET_SCOPE = scope:task_contract_target
			TASK_CONTRACT = scope:task_contract
			# Success.
			AGENT_1 = agent_muscle
			AGENT_2 = agent_thug
			AGENT_3 = agent_bodyguard
			# Speed.
			AGENT_4 = agent_footpad
			AGENT_5 = agent_tracker
		}
		scope:task_contract.scheme = {
			save_scope_as = scheme
		}
		trigger_event = laamp_extra_contract_schemes.0001
		custom_tooltip = ep3_contract_event.0020.agents_martial
		custom_tooltip = ep3_contract_event.0020.tt
	}
	#learning
	option = {
		name = ep3_contract_event.0020.d
		trigger = {
			OR = {
				has_realm_law = camp_purpose_scholars
				has_realm_law = camp_purpose_legitimists
			}
		}
		reason = purpose_legitimists_and_scholars
		begin_contract_scheme_with_agents_effect = {
			SCHEME_TYPE = protect_minority_vassal_contract_learning_scheme
			TARGET_TYPE = target_character
			TARGET_SCOPE = scope:task_contract_target
			TASK_CONTRACT = scope:task_contract
			# Success.
			AGENT_1 = agent_bailiff
			AGENT_2 = agent_scribe
			AGENT_3 = agent_diplomat
			# Speed.
			AGENT_4 = agent_theologian
			AGENT_5 = agent_justiciar_speed
		}
		scope:task_contract.scheme = {
			save_scope_as = scheme
		}
		trigger_event = laamp_extra_contract_schemes.0001
		custom_tooltip = ep3_contract_event.0020.agents_learning
		custom_tooltip = ep3_contract_event.0020.tt
	}
	#diplomacy - always
	option = {
		name = ep3_contract_event.0020.e
		begin_contract_scheme_with_agents_effect = {
			SCHEME_TYPE = protect_minority_vassal_contract_diplomacy_scheme
			TARGET_TYPE = target_character
			TARGET_SCOPE = scope:task_contract_target
			TASK_CONTRACT = scope:task_contract
			# Success.
			AGENT_1 = agent_diplomat
			AGENT_2 = agent_shill
			AGENT_3 = agent_scribe
			# Speed.
			AGENT_4 = agent_socialite
			AGENT_5 = agent_herald
		}
		scope:task_contract.scheme = {
			save_scope_as = scheme
		}
		trigger_event = laamp_extra_contract_schemes.0001
		custom_tooltip = ep3_contract_event.0020.agents_diplomacy
		custom_tooltip = ep3_contract_event.0020.tt
	}
}

#Reward the Faithful - start event to help getting a religious rights vassal contract
ep3_contract_event.0021 = {
	type = character_event
	title = ep3_contract_event.0021.t
	desc = ep3_contract_event.0021.desc
	theme = intrigue
	#contract_taker, you
	left_portrait = {
		character = root
		animation = personality_compassionate
	}
	#character giving you the contract
	right_portrait = {
		character = scope:task_contract_employer
	}
	#character you have to fight in a war
	lower_right_portrait = {
		character = scope:task_contract_target
	}

	immediate = {
		set_contract_scopes_effect = yes
	}

	#use hook
	option = {
		name = ep3_contract_event.0021.a
		trigger = {
			has_hook = scope:task_contract_target
		}
		show_as_unavailable = {
			NOT = { has_hook = scope:task_contract_target }
		}
		reason = hook
		remove_hook  =  { target = scope:task_contract_target }
		scope:task_contract_employer = {
			vassal_contract_set_obligation_level = {
				type = religious_rights
				level = 1
			}
		}
		scope:task_contract = {
			complete_task_contract = success_standard
		}
	}
	#intrigue
	option = {
		name = ep3_contract_event.0021.b
		trigger = {
			OR = {
				has_realm_law = camp_purpose_wanderers
				has_realm_law = camp_purpose_explorers
			}
		}
		reason = purpose_explorers_and_wanderers
		begin_contract_scheme_with_agents_effect = {
			SCHEME_TYPE = protect_minority_vassal_contract_intrigue_scheme
			TARGET_TYPE = target_character
			TARGET_SCOPE = scope:task_contract_target
			TASK_CONTRACT = scope:task_contract
			# Success.
			AGENT_1 = agent_thug
			AGENT_2 = agent_shill
			AGENT_3 = agent_wrangler
			# Speed.
			AGENT_4 = agent_infiltrator
			AGENT_5 = agent_socialite
		}
		scope:task_contract.scheme = {
			save_scope_as = scheme
		}
		trigger_event = laamp_extra_contract_schemes.0001
		custom_tooltip = ep3_contract_event.0021.agents_intrigue
		custom_tooltip = ep3_contract_event.0021.tt
	}
	#martial
	option = {
		name = ep3_contract_event.0021.c
		trigger = {
			OR = {
				has_realm_law = camp_purpose_brigands
				has_realm_law = camp_purpose_mercenaries
			}
		}
		reason = purpose_brigands_and_mercenaries
		begin_contract_scheme_with_agents_effect = {
			SCHEME_TYPE = protect_minority_vassal_contract_martial_scheme
			TARGET_TYPE = target_character
			TARGET_SCOPE = scope:task_contract_target
			TASK_CONTRACT = scope:task_contract
			# Success.
			AGENT_1 = agent_muscle
			AGENT_2 = agent_thug
			AGENT_3 = agent_bodyguard
			# Speed.
			AGENT_4 = agent_footpad
			AGENT_5 = agent_tracker
		}
		scope:task_contract.scheme = {
			save_scope_as = scheme
		}
		trigger_event = laamp_extra_contract_schemes.0001
		custom_tooltip = ep3_contract_event.0021.agents_martial
		custom_tooltip = ep3_contract_event.0021.tt
	}
	#learning
	option = {
		name = ep3_contract_event.0021.d
		trigger = {
			OR = {
				has_realm_law = camp_purpose_scholars
				has_realm_law = camp_purpose_legitimists
			}
		}
		reason = purpose_legitimists_and_scholars
		begin_contract_scheme_with_agents_effect = {
			SCHEME_TYPE = protect_minority_vassal_contract_learning_scheme
			TARGET_TYPE = target_character
			TARGET_SCOPE = scope:task_contract_target
			TASK_CONTRACT = scope:task_contract
			# Success.
			AGENT_1 = agent_bailiff
			AGENT_2 = agent_scribe
			AGENT_3 = agent_diplomat
			# Speed.
			AGENT_4 = agent_theologian
			AGENT_5 = agent_justiciar_speed
		}
		scope:task_contract.scheme = {
			save_scope_as = scheme
		}
		trigger_event = laamp_extra_contract_schemes.0001
		custom_tooltip = ep3_contract_event.0021.agents_learning
		custom_tooltip = ep3_contract_event.0021.tt
	}
	#diplomacy - always
	option = {
		name = ep3_contract_event.0021.e
		begin_contract_scheme_with_agents_effect = {
			SCHEME_TYPE = protect_minority_vassal_contract_diplomacy_scheme
			TARGET_TYPE = target_character
			TARGET_SCOPE = scope:task_contract_target
			TASK_CONTRACT = scope:task_contract
			# Success.
			AGENT_1 = agent_diplomat
			AGENT_2 = agent_shill
			AGENT_3 = agent_scribe
			# Speed.
			AGENT_4 = agent_socialite
			AGENT_5 = agent_herald
		}
		scope:task_contract.scheme = {
			save_scope_as = scheme
		}
		trigger_event = laamp_extra_contract_schemes.0001
		custom_tooltip = ep3_contract_event.0021.agents_diplomacy
		custom_tooltip = ep3_contract_event.0021.tt
	}
}

#Contract to scheme a Prison Break - starting event
ep3_contract_event.0030 = {
	type = character_event
	title = ep3_contract_event.0030.t
	desc = ep3_contract_event.0030.desc
	theme = intrigue
	#contract_taker, you
	left_portrait = {
		character = root
		animation = eyeroll
	}
	#contract_object, character to rescue from prison
	right_portrait = {
		character = scope:task_contract_employer
		animation = bribing
	}
	#character giving you the contract
	lower_right_portrait = {
		character = scope:task_contract_object
	}
	#the imprisoner
	lower_left_portrait = {
		character = scope:task_contract_target
	}

	immediate = {
		set_contract_scopes_effect = yes
	}

	#use hook
	option = {
		name = ep3_contract_event.0030.a
		trigger = {
			has_hook = scope:task_contract_target
		}
		show_as_unavailable = {
			NOT = { has_hook = scope:task_contract_target }
		}
		reason = hook
		remove_hook = { target = scope:task_contract_target }
		scope:task_contract = {
			complete_task_contract = success_standard
		}
		#AI should always try to complete the contract
		ai_chance = {
			base = 100
		}
	}
	#prison break
	option = {
		name = ep3_contract_event.0030.b
		begin_contract_scheme_with_agents_effect = {
			SCHEME_TYPE = laamp_prison_break_scheme
			TARGET_TYPE = target_character
			TARGET_SCOPE = scope:task_contract_target
			TASK_CONTRACT = scope:task_contract
			# Success.
			AGENT_1 = agent_thief
			AGENT_2 = agent_thug
			# Speed.
			AGENT_3 = agent_infiltrator
			# Secrecy.
			AGENT_4 = agent_lookout
			AGENT_5 = agent_decoy
		}
		scope:task_contract.scheme = {
			save_scope_as = scheme
		}
		custom_tooltip = ep3_contract_event.0030.agents
		trigger_event = laamp_extra_contract_schemes.0011
		#AI should always try to complete the contract
		ai_chance = {
			base = 1
		}
	}
	#prison break
	option = {
		name = ep3_contract_event.0030.c
		custom_tooltip = ep3_contract_event.0030.c.tt
		reverse_add_opinion = {
			modifier = angry_opinion
			opinion = -10
			target = scope:task_contract_employer
		}
		
		#AI should always try to complete the contract
		ai_chance = {
			base = 0
		}
	}
}

#Are we actually traveling towards the treasure now?
scripted_trigger 0040_traveling_towards_treasure_with_domicile_trigger = {
	has_variable = ep3_laamp_decision_1000_is_excavating
	current_travel_plan ?= {
		is_travel_with_domicile = yes
		OR = {
			next_destination_province = scope:task_contract_destination
			final_destination_province = scope:task_contract_destination
		}
	}
}

#Your Treasure Map broke!
ep3_contract_event.0040 = {
	type = character_event
	title = ep3_contract_event.0040.t
	desc = ep3_contract_event.0040.desc
	theme = travel
	left_portrait = {
		character = root
		animation = shock
	}
	immediate = {
		#Save scopes
		random_character_task_contract = {
			task_contract_type = laamp_treasure_map_contract
			save_scope_as = task_contract
		}
		scope:task_contract = {
			task_contract_employer = { save_scope_as = task_contract_employer }
			var:contract_treasure_location = { save_scope_as = treasure_map_contract_destination }
		}
		#Remove treasure map
		destroy_artifact = scope:decayed_artifact
		#Don't need you anymore, go away
		#move_to_pool = scope:task_contract_employer
		scope:task_contract_employer = { select_and_move_to_pool_effect = yes }
	}
	#Back home we go
	option = {
		name = {
			trigger = { exists = current_travel_plan }
			text = ep3_contract_event.0040.a_travel
		}
		name = ep3_contract_event.0040.a
		#Haven't paid up?
		if = {
			limit = { 0040_traveling_towards_treasure_with_domicile_trigger = no }
			#Then back home we go
			return_home = yes
		}
		else = {
			#Keep doing what you're doing
		}
		ai_chance = {
			base = 10
		}
	}
	#Otherwise possibly stay in place
	option = {
		name = ep3_contract_event.0040.b
		trigger = { 0040_traveling_towards_treasure_with_domicile_trigger = yes }
		#Show 'em what happened
		show_as_tooltip = {
			domicile ?= { move_domicile = root.location }
		}
		#No point in traveling without the map
		current_travel_plan ?= { abort_travel_plan = yes }
		ai_chance = {
			base = 2
		}
	}
}

#Employer died or became incapable while in your camp
ep3_contract_event.0041 = {
	type = character_event
	title = {
		first_valid = {
			#Dead
			triggered_desc = {
				trigger = { 
					scope:task_contract_employer = { is_alive = no } 
				}
				desc = ep3_contract_event.0041.t_dead
			}
			#Incapable
			triggered_desc = {
				trigger = { 
					scope:task_contract_employer = { has_trait = incapable } 
				}
				desc = ep3_contract_event.0041.t_incapable
			}
		}
	}
	desc = {
		first_valid = {
			#Dead
			triggered_desc = {
				trigger = { 
					scope:task_contract_employer = { is_alive = no } 
				}
				desc = ep3_contract_event.0041.desc_dead
			}
			#Incapable
			triggered_desc = {
				trigger = { 
					scope:task_contract_employer = { has_trait = incapable } 
				}
				desc = ep3_contract_event.0041.desc_incapable
			}
		}
		desc = ep3_contract_event.0041.desc_outro
	}
	theme = travel
	override_background = { reference = ep3_relaxing_tent }
	left_portrait = {
		character = root
		animation = worry
	}
	right_portrait = {
		character = scope:task_contract_employer
		#Dead
		triggered_animation = {
			trigger = { is_alive = no }
			animation = dead
		}
		#Incapable
		animation = shiver
	}
	immediate = {
		#Scopes are carried over from when the event triggers in the invalidation block of the laamp_treasure_map_contract
		scope:task_contract_destination = { save_scope_as = travel_destination }
		#Wait, what just happened?
		scope:task_contract_employer = {
			if = {
				limit = { is_alive = no }
				#Repurposing old loc strings...
				save_scope_as = target
				custom_tooltip = seize_realm_target_died_tt
			}
			else = { custom_tooltip = treasure_map_employer_is_incapable.tt }
		}
		#Remove the treasure map
		random_character_artifact = {
			limit = { has_variable = 1025_treasure_map }
			save_scope_as = 0041_treasure_map
			hidden_effect = { destroy_artifact = this }
		}
		#Very mysterious
		custom_tooltip = treasure_map_disappeared.tt
		#Mention that it invalidated
		custom_tooltip = contract_invalidated_desc
	}
	#Staying. Here.
	option = {
		name = ep3_contract_event.0041.a
		flavor = {
			first_valid = {
				triggered_desc = {
					trigger = {
						scope:task_contract_employer = { is_alive = no } 
					}
					desc = ep3_contract_event.0041.a.flavor_dead
				}
				triggered_desc = {
					trigger = { 
						scope:task_contract_employer = { has_trait = incapable } 
					}
					desc = ep3_contract_event.0041.a.flavor_incapable
				}
			}
		}
		#No point in traveling without the map
		return_home = yes
	}
	#Already paid for my domicile to travel. We're continuing!
	option = {
		name = travel_danger_events.1011.c
		trigger = { 0040_traveling_towards_treasure_with_domicile_trigger = yes }
	}
	after = { remove_variable ?= ep3_laamp_decision_1000_is_excavating }
}

scripted_trigger 0045_artifact_will_be_reforged_trigger = {
	OR = {
		#Variables
		has_variable = ascalon
		has_variable = staff_kakusandha
		has_variable = zomorrodnegar
		has_variable = aruval
		has_variable = sword_cid
		has_variable = sword_of_muhammad
		has_variable = mmaagha_kamalu
		has_variable = sword_attila
		has_variable = iron_crown
		has_variable = crown_of_justinian
		has_variable = angelica_ring
		#Types
		artifact_type = scepter_pedestal
		artifact_type = brooch_pedestal
		artifact_type = necklace_pedestal
		artifact_type = pedestal
		artifact_type = sculpture
		artifact_type = goblet
		artifact_type = jug
		artifact_type = urn
	}
}

#You have accepted the Treasure Map contract - the employer tags along - starting event
ep3_contract_event.0043 = {
	type = character_event
	title = ep3_contract_event.0043.t
	desc = ep3_contract_event.0043.desc
	theme = travel
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = { 
				has_trait = gallowsbait
				has_trait = greedy
			}
			animation = personality_dishonorable
		}
		animation = personality_rational
	}
	right_portrait = {
		character = scope:task_contract_employer
		animation = ecstasy
	}
	artifact = {
		trigger = { exists = scope:0043_treasure_map }
		target = scope:0043_treasure_map
		position = lower_center_portrait
	}
	immediate = {
		#Save scopes
		random_character_task_contract = {
			task_contract_type = laamp_treasure_map_contract
			save_scope_as = task_contract
		}
		scope:task_contract.task_contract_employer = { save_scope_as = task_contract_employer }
		show_as_tooltip = { add_courtier = scope:task_contract_employer }
		scope:task_contract_employer = {
			reverse_add_opinion = {
		 		target = root
		 		modifier = grateful_opinion
		 		opinion = 25
		 	}
		}
		#This should always exist
		random_character_artifact = {
			limit = { has_variable = 1025_treasure_map }
			save_scope_as = 0043_treasure_map
		}
	}
	#Do it now - open Decisions screen
	option = {
		name = ep3_contract_event.0043.a
		custom_tooltip = ep3_contract_event.0043.a.tt
		#Decisions!!
		decision:treasure_map_contract_decision = {
			open_view_data = {
				view = decision_detail
				player = root
			}
		}
	}
	#Yeah, yeah, I'll get to it...
	option = {
		name = ep3_contract_event.0043.b
	}
}

#Pre-filter because on_arrival_event doesn't respect event triggers :scree:
ep3_contract_event.0044 = {
	hidden = yes 

	immediate = {
		if = {
			limit = {
				has_variable = ep3_laamp_decision_1000_is_excavating
				any_character_task_contract = { task_contract_type = laamp_treasure_map_contract }
			}
			trigger_event = ep3_contract_event.0045
		}
		else = {
			#Nothing. Zilch. Zip. Nada.
		}
	}
}

#You find the Treasure. Do you keep it?
ep3_contract_event.0045 = {
	type = character_event
	title = ep3_contract_event.0045.t
	desc = {
		first_valid = {
			#Historical artifact
			triggered_desc = {
				trigger = { exists = scope:treasure_artifact_historical }
				desc = ep3_contract_event.0045.desc_artifact_historical
			}
			#jewelry
			triggered_desc = {
				trigger = { exists = scope:treasure_artifact_jewelry }
				desc = ep3_contract_event.0045.desc_artifact_jewelry
			}
			#Great amount of gold
			triggered_desc = {
				trigger = { exists = scope:treasure_gold_great }
				desc = ep3_contract_event.0045.desc_gold_great
			}
			#Mediocre amount of gold
			triggered_desc = {
				trigger = { exists = scope:treasure_gold_mediocre }
				desc = ep3_contract_event.0045.desc_gold_mediocre
			}
			#Poor amount of gold
			triggered_desc = {
				trigger = { exists = scope:treasure_gold_poor }
				desc = ep3_contract_event.0045.desc_gold_poor
			}
			#Nice view - oasis
			triggered_desc = {
				trigger = { 
					exists = scope:treasure_riches_in_scenery
					exists = scope:is_dry_region
				}
				desc = ep3_contract_event.0045.desc_riches_in_scenery_dry
			}
			#Nice view - spring
			triggered_desc = {
				trigger = { 
					exists = scope:treasure_riches_in_scenery
					NOT = { exists = scope:is_dry_region }
				}
				desc = ep3_contract_event.0045.desc_riches_in_scenery
			}
			#Fallback
			desc = ep3_contract_event.0045.desc_pillaged
		}
	}
	theme = landless_adventurer
	#Literally anything else but that adventurer tent
	override_background = { reference = terrain }
	#The treasure of beautiful nature
	override_background = {
		trigger = {
			exists = scope:treasure_riches_in_scenery
			NOT = { exists = scope:is_dry_region }
		}
		reference = ce1_legendary_spring 
	}
	#The desert version
	override_background = {
		trigger = {
			exists = scope:treasure_riches_in_scenery
			exists = scope:is_dry_region
		}
		reference = ce1_legendary_oasis 
	}
	#A cave!
	override_background = {
		trigger = {
			OR = {
				exists = scope:treasure_gold_great
				exists = scope:treasure_gold_mediocre
				exists = scope:treasure_gold_poor
			}
		}
		reference = fp3_cave
	}
	left_portrait = {
		character = root
		#Nice view
		triggered_animation = {
			trigger = { exists = scope:treasure_riches_in_scenery }
			animation = shock
		}
		#Poor amount of gold
		triggered_animation = {
			trigger = {
				has_trait = greedy
				exists = scope:treasure_gold_poor
			}
			animation = personality_cynical
		}
		triggered_animation = {
			trigger = { exists = scope:treasure_pillaged }
			animation = disapproval
		}
		triggered_animation = {
			trigger = { has_trait = gallowsbait }
			animation = personality_dishonorable
		}
		animation = thinking
	}
	artifact = {
		trigger = { exists = scope:0045_display_artifact }
		target = scope:0045_display_artifact
		position = lower_center_portrait
	}
	trigger = {
		has_variable = ep3_laamp_decision_1000_is_excavating
		any_character_task_contract = { task_contract_type = laamp_treasure_map_contract }
	}
	immediate = {
		#Save scopes
		random_character_task_contract = {
			task_contract_type = laamp_treasure_map_contract
			save_scope_as = task_contract
		}
		scope:task_contract.task_contract_employer = { save_scope_as = task_contract_employer }
		scope:task_contract.var:contract_treasure_location = { save_scope_as = excavation_location }
		#This should always exist
		random_character_artifact = {
			limit = { has_variable = 1025_treasure_map }
			save_scope_as = 0045_treasure_map
		}
		#What did we find?
		random_list = {
			#Historical artifact
			1 = {
				trigger = { is_ai = no }
				#What artifact?
				hidden_effect_new_object = { 
					generate_historical_artifact_based_on_location_effect = { LOCATION = scope:excavation_location }
					scope:newly_created_artifact = { save_scope_as = treasure_artifact_historical }
				}
				create_character_memory = { type = treasure_map_memory }
				scope:new_memory ?= {
					set_variable = {
						name = treasure_map_historical_artifact
						value = scope:treasure_artifact_historical
					}
					set_variable = {
						name = treasure_map_historical_artifact_location
						value = scope:excavation_location
					}
					if = {
						limit = { 
							exists = var:treasure_map_historical_artifact
							exists = var:treasure_map_historical_artifact_location 
						}
						#To prevent 'unused except in loc' errors :catto:
					}
				}
				#Note that it has a historical artifact, for the Contract Success Reward
				scope:task_contract = {
					set_variable = {
						name = has_unique_historical_artifact
						value = scope:treasure_artifact_historical
					}
				}
			}
			#Jewelry
			5 = {
				#Generate jewelry
				hidden_effect_new_object = {
					random_pool_character = {
						province = root.location
						limit = { is_available_adult = yes }
						save_scope_as = 0045_smith
					}
					if = {
						limit = {
							NOT = { exists = scope:0045_smith }
						}
						create_character = {
							template = generic_peasant_character
							location = root.location
							dynasty = none
							culture = root.location.culture
							faith = root.location.faith
							save_scope_as = 0045_smith
						}
					}
					random_list = {
						10 = { set_artifact_rarity_illustrious = yes }
						20 = { set_artifact_rarity_famed = yes }
						40 = { set_artifact_rarity_masterwork = yes }
					}
					random_list = {
						50 = {
							create_artifact_brooch_effect = {
								OWNER = scope:0045_smith
								SMITH = scope:0045_smith
							}
						}
						50 = {
						 	create_artifact_ring_effect = {
								OWNER = scope:0045_smith
								SMITH = scope:0045_smith
							}
						}
						50 = {
							create_artifact_necklace_effect = {
								OWNER = scope:0045_smith
								SMITH = scope:0045_smith
							}
						}
					}
				 	#Finalization
					scope:newly_created_artifact ?= {
						add_scaled_artifact_modifier_prestige_effect = yes
						#Don't need no notification about this
						set_variable = {
							name = suppress_artifact_notifications
							value = yes
							days = 2
						}
						save_scope_as = treasure_artifact_jewelry
						set_owner = root
					}
				}
				#Note that it is jewelry, for the Contract Success Reward
				scope:task_contract = {
					set_variable = {
						name = has_jewelry_artifact
						value = scope:treasure_artifact_jewelry
					}
				}
			}
			#Great amount of gold
			20 = {
				save_scope_as = treasure_gold_great
				save_scope_value_as = {
					name = 0045_gold_gained
					value = {
						value = major_gold_laamps_value
						multiply = 2
					}
				}
				#Note that it is Great, for the Contract Success Reward
				scope:task_contract = {
					set_variable = {
						name = treasure_gold_great
						value = scope:0045_gold_gained
					}
				}
			}
			#Mediocre amount of gold
			20 = {
				save_scope_as = treasure_gold_mediocre
				save_scope_value_as = {
					name = 0045_gold_gained
					value = major_gold_laamps_value
				}
				#Note that it is Mediocre, for the Contract Success Reward
				scope:task_contract = {
					set_variable = {
						name = treasure_gold_mediocre
						value = scope:0045_gold_gained
					}
				}
			}
			#Poor amount of gold 
			30 = {
				save_scope_as = treasure_gold_poor
				save_scope_value_as = {
					name = 0045_gold_gained
					value = {
						value = medium_gold_laamps_value
						divide = 2
					}
				}
				#Note that it is Poor, for the Contract Success Reward
				scope:task_contract = {
					set_variable = {
						name = treasure_gold_poor
						value = scope:0045_gold_gained
					}
				}
			}
			#Nice view
			30 = { 
				trigger = {
					NOT = { has_character_modifier = divine_springs_modifier }
				}
				#Pretty divine, innit
				if = {
					limit = {
						has_trait = pilgrim
						has_trait_xp = {
							trait = pilgrim
							value < 100
						}
					}
					add_trait_xp = {
						trait = pilgrim
						value = {
							integer_range = {
							    min = small_lifestyle_random_xp_mid
							    max = small_lifestyle_random_xp_high
							}
						}
					}
				}
				else = {
					stress_impact = { 
						base = medium_stress_impact_loss
						zealous = minor_stress_impact_loss
					}
				}
				save_scope_as = treasure_riches_in_scenery
				create_character_memory = { type = treasure_map_memory }
				scope:new_memory ?= {
					set_variable = {
						name = treasure_map_divine_scenery
						value = scope:excavation_location
					}
					if = {
						limit = { exists = var:treasure_map_divine_scenery }
						#To prevent 'unused except in loc' errors :catto:
					}
				}
				#Note that it is scenic, for the Contract Success Reward
				scope:task_contract = {
					set_variable = {
						name = has_scenic_riches
						value = flag:yes
					}
				}
			}
			#Someone beat you to it
			20 = {
				save_scope_as = treasure_pillaged
				save_scope_value_as = {
					name = 0045_gold_gained
					value = minor_gold_laamps_value
				}
				#Note that it is Pillaged, for the Contract Success Reward
				scope:task_contract = {
					set_variable = {
						name = treasure_pillaged
						value = scope:0045_gold_gained
					}
				}
			}
		}
		#Oasis, not spring
		if = {
			limit = {
				location = {
					OR = {
						terrain = desert
						terrain = desert_mountains
						terrain = drylands
					}
				}
			}
			save_scope_as = is_dry_region
		}
		#Display the artifact
		scope:treasure_artifact_historical ?= { save_scope_as = 0045_display_artifact }
		scope:treasure_artifact_jewelry ?= { save_scope_as = 0045_display_artifact }
	}
	#Let Employer know
	option = {
		name = {
			text = {
				first_valid = {
					#Historical Artifact
					triggered_desc = {
						trigger = { exists = scope:treasure_artifact_historical }
						desc = ep3_contract_event.0045.a_artifact_historical
					}
					#Alright
					triggered_desc = {
						trigger = {
							OR = {
								exists = scope:treasure_artifact_jewelry
								exists = scope:treasure_gold_great
								exists = scope:treasure_gold_mediocre
								exists = scope:treasure_riches_in_scenery
							}
						}
						desc = ep3_contract_event.0045.a
					}
					#Meh
					triggered_desc = {
						trigger = {
							OR = {
								exists = scope:treasure_gold_poor
								exists = scope:treasure_pillaged
							}
						}
						desc = ep3_contract_event.0045.a_pillaged
					}
				}
			}
		}
		#We don't really care if the map breaks at this point
		scope:task_contract = { set_variable = 0045_used_map }
		#Trigger the concluding event
		trigger_event = ep3_contract_event.0050
		#You're doing the right thing
		stress_impact = {
			base = minor_stress_impact_loss
			honest = medium_stress_impact_loss
			greedy = minor_stress_impact_gain
		}
	}
	#Keep it for yourself
	option = {
		name = {
			text = {
				first_valid = {
					#Historical Artifact
					triggered_desc = {
						trigger = { exists = scope:treasure_artifact_historical }
						desc = ep3_contract_event.0045.b_artifact_historical
					}
					#Alright
					triggered_desc = {
						trigger = {
							OR = {
								exists = scope:treasure_artifact_jewelry
								exists = scope:treasure_gold_great
								exists = scope:treasure_gold_mediocre
							}
						}
						desc = ep3_contract_event.0045.b
					}
					#Meh
					triggered_desc = {
						trigger = {
							OR = {
								exists = scope:treasure_gold_poor
								exists = scope:treasure_pillaged
							}
						}
						desc = ep3_contract_event.0045.b_pillaged
					}
				}
			}
		}
		#... just... doesn't make sense
		trigger = {
			NOT = { exists = scope:treasure_riches_in_scenery }
		}
		flavor = {
			first_valid = {
				triggered_desc = {
					trigger = {
						scope:treasure_artifact_historical ?= { 0045_artifact_will_be_reforged_trigger = yes }
					}
					desc = ep3_contract_event.0045.b.flavor_reforged
				}
				desc = ep3_contract_event.0045.b.flavor
			}
		}
		#Historical artifact: Change it to something useful.
		if = {
			limit = { exists = scope:treasure_artifact_historical }
			scope:treasure_artifact_historical = {
				if = {
					limit = {
						OR = {
							has_variable = ascalon
							has_variable = staff_kakusandha
							has_variable = zomorrodnegar
							has_variable = aruval
							has_variable = sword_cid
							has_variable = sword_of_muhammad
							has_variable = mmaagha_kamalu
							has_variable = sword_attila
							artifact_type = scepter_pedestal
						}
					}
					reforge_artifact = { type = regalia }
				}
				else_if = {
					limit = { 
						OR = {
							has_variable = iron_crown
							has_variable = crown_of_justinian
						}
					}
					reforge_artifact = { type = helmet }			
				}
				else_if = {
					limit = { has_variable = angelica_ring }
					reforge_artifact = { type = ring }
				}
				else_if = {
					limit = { artifact_type = brooch_pedestal }
					reforge_artifact = { type = brooch }
				}
				else_if = {
					limit = { artifact_type = necklace_pedestal }
					reforge_artifact = { type = necklace }
				}
				else_if = {
					limit = { 
						OR = {
							artifact_type = pedestal
							artifact_type = sculpture
							artifact_type = goblet
							artifact_type = jug
							artifact_type = urn
						}
					}
					reforge_artifact = { type = miscellaneous }
				}
			}
			show_as_tooltip = {
				scope:treasure_artifact_historical = { set_owner = root }
			}
		}
		else_if = {
			limit = { exists = scope:treasure_artifact_jewelry }
			show_as_tooltip = {
				scope:treasure_artifact_jewelry = { set_owner = root }
			}
		}
		else = { add_short_term_gold = scope:0045_gold_gained }
		#Get rid of the contract
		scope:task_contract = { complete_task_contract = failure_standard }
		#Off ye go
		remove_courtier_or_guest = scope:task_contract_employer
		#You stole a historical treasure
		if = {
			limit = { exists = scope:treasure_artifact_historical }
			#Shame on you
			laamp_rewards_apply_criminal_xp_effect = {
				TRACK = thief
				XP_MIN = gallowsbait_xp_major_gain
				XP_MAX = gallowsbait_xp_massive_gain
			}
			stress_impact = {
				base = major_stress_impact_gain
				honest = minor_stress_impact_gain
				greedy = minor_stress_impact_loss
				callous = minor_stress_impact_loss
				sadistic = minor_stress_impact_loss
			}
		}
		#You stole something significant
		else_if = {
			limit = {
				OR = {
					exists = scope:treasure_artifact_jewelry
					exists = scope:treasure_gold_great
				}
			}
			#Shame on you	
			laamp_rewards_apply_criminal_xp_effect = {
				TRACK = thief
				XP_MIN = gallowsbait_xp_minor_gain
				XP_MAX = gallowsbait_xp_major_gain
			}
			stress_impact = {
				base = medium_stress_impact_gain
				honest = minor_stress_impact_gain
				greedy = minor_stress_impact_loss
				callous = minor_stress_impact_loss
				sadistic = minor_stress_impact_loss
			}
		}
		#Or not
		else = {
			#Ehh petty theft	
			laamp_rewards_apply_criminal_xp_effect = {
				TRACK = thief
				XP_MIN = gallowsbait_xp_minor_gain
				XP_MAX = gallowsbait_xp_minor_gain
			}
			stress_impact = {
				base = minor_stress_impact_gain
				honest = minor_stress_impact_gain
				greedy = minor_stress_impact_loss
				callous = minor_stress_impact_loss
				sadistic = minor_stress_impact_loss
			}
		}
		ai_chance = {
			base = 0
		}
	}
}

#Back at the employer. Fork over the treasure
ep3_contract_event.0050 = {
	type = character_event
	title = ep3_contract_event.0050.t
	desc = {
		first_valid = {
			#Historical artifact
			triggered_desc = {
				trigger = { exists = scope:treasure_artifact_historical }
				desc = ep3_contract_event.0050.desc_artifact_historical
			}
			#jewelry artifact
			triggered_desc = {
				trigger = { exists = scope:treasure_artifact_jewelry }
				desc = ep3_contract_event.0050.desc_artifact_jewelry
			}
			#Gold
			triggered_desc = {
				trigger = {
					OR = {
						exists = scope:treasure_gold_great
						exists = scope:treasure_gold_mediocre
						exists = scope:treasure_gold_poor
					} 
				}
				desc = ep3_contract_event.0050.desc_gold
			}
			#Scenic
			triggered_desc = {
				trigger = { exists = scope:treasure_riches_in_scenery }
				desc = ep3_contract_event.0050.desc_scenic
			}
			#Pillaged
			desc = ep3_contract_event.0050.desc_pillaged
		}
	}
	theme = inspiration_complete
	override_background = { reference = ep3_relaxing_tent }
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = { has_trait = greedy }
			animation = personality_cynical
		}
		animation = flirtation
	}
	right_portrait = {
		character = scope:task_contract_employer
		#Historical artifact
		triggered_animation = {
			trigger = { exists = scope:treasure_artifact_historical }
			animation = disbelief
		}
		#Scenic
		triggered_animation = {
			trigger = { exists = scope:treasure_riches_in_scenery }
			animation = wedding_happy_cry
		}
		#Pillaged
		triggered_animation = {
			trigger = { exists = scope:treasure_pillaged }
			animation = sadness
		}
		animation = happiness
	}
	artifact = {
		trigger = { exists = scope:0045_display_artifact }
		target = scope:0045_display_artifact
		position = lower_center_portrait
	}
	immediate = {

	}
	#Fork it over
	option = {
		name = ep3_contract_event.0050.a
		scope:task_contract = { complete_task_contract = success_standard }
		if = {
			limit = { exists = scope:treasure_riches_in_scenery }
			#Perma modifier
			add_character_modifier = { modifier = divine_springs_modifier }
		}
		#Ya did the right thing, son
		stress_impact = { honest = minor_stress_impact_loss }
		ai_chance = {
			base = 10
		}
	}
	after = {
		#Off ye go
		remove_courtier_or_guest = scope:task_contract_employer
	}
}

#To remove the variable for those who go into the travel planner but then decide not to travel to the Excavation Site
ep3_contract_event.0055 = {
	hidden = yes
	
	trigger = { has_variable = ep3_laamp_decision_1000_is_planning_excavation_trip }

	immediate = { 
		remove_variable ?= ep3_laamp_decision_1000_is_planning_excavation_trip
		#Is it our active contract?
		random_character_task_contract = {
			limit = { has_variable = contract_treasure_location }
			save_scope_as = task_contract
		}
		#Are we going to the destination?
		if = {
			limit = {
				any_character_active_contract = { task_contract_type = laamp_treasure_map_contract }
				current_travel_plan ?= {
					any_future_path_location = { this = scope:task_contract.var:contract_treasure_location }
				}
			}
			set_variable = ep3_laamp_decision_1000_is_excavating
		}
	}
}

#Help Claimant start a war contract
ep3_contract_event.0060 = {
	type = character_event
	title = ep3_contract_event.0060.t
	desc = ep3_contract_event.0060.desc
	theme = war
	#task_contract_taker, you
	left_portrait = {
		character = root
		animation = personality_bold
	}
	#commander, an envoy from employer
	right_portrait = {
		character = scope:commander
		animation = storyteller
	}
	#character giving you the contract
	lower_right_portrait = {
		character = scope:task_contract_employer
	}
	#character you have to fight in a war
	lower_left_portrait = {
		character = scope:task_contract_target
	}

	immediate = {
		set_contract_scopes_effect = yes
		scope:task_contract_employer = {
			random_knight = {
				save_scope_as = commander
			}
		}
	}

	#take the contract and start the claim war
	option = {
		name = ep3_contract_event.0060.a
		scope:task_contract_employer = {
			start_war = {
				cb = claim_cb
				target = scope:task_contract_target
				claimant = scope:task_contract_employer
				target_title = scope:task_contract.var:task_contract_title
			}
			#needs a custom tooltip as the war doesn't exist yet
			custom_tooltip = ep3_contract_event.0060.join_war
			random_character_war = {
				limit = {
					using_cb = claim_cb
					primary_attacker = scope:task_contract_employer
					primary_defender = scope:task_contract_target
				}
				save_scope_as = task_contract_war
			}
		}
		scope:task_contract = {
			set_variable = {
				name = task_contract_war
				value = scope:task_contract_war
			}
		}
		scope:task_contract_war ?= {
			hidden_effect = { set_called_to = root }
			add_attacker = root
		}

		
		#AI should always try to complete the contract
		ai_chance = {
			base = 20
		}
	}
	#invalidate the contract
	option = {
		name = ep3_contract_event.0001.invalidate
		scope:task_contract = {
			invalidate_contract = yes
		}
		#AI should always try to complete the contract
		ai_chance = {
			base = 0
		}
	}
}

#Join Faction - intro
ep3_contract_event.0070 = {
	type = character_event
	title = ep3_contract_event.0070.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:task_contract_faction = {
						faction_is_type = nation_fracturing_faction
					}
				}
				desc = ep3_contract_event.0070.desc_nation_fracturing_faction
			}
			desc = {
				first_valid = {
					triggered_desc = {
						trigger = {
							scope:task_contract_faction = {
								faction_is_type = liberty_faction
							}
						}
						desc = ep3_contract_event.0070.desc_liberty_faction
					}
					triggered_desc = {
						trigger = {
							scope:task_contract_faction = {
								faction_is_type = independence_faction
							}
						}
						desc = ep3_contract_event.0070.desc_independence_faction
					}
					triggered_desc = {
						trigger = {
							scope:task_contract_faction = {
								faction_is_type = claimant_faction
							}
						}
						desc = ep3_contract_event.0070.desc_claimant_faction
					}
					desc = ep3_contract_event.0070.desc_fallback_faction
				}
				first_valid = {
					triggered_desc = {
						trigger = {
							scope:task_contract_employer = {
								vassal_contract_has_flag = obligation_high_taxes
							}
						}
						desc = ep3_contract_event.0070.desc_liege_taxes
					}
					triggered_desc = {
						trigger = {
							scope:task_contract_employer = {
								vassal_contract_has_flag = obligation_high_levies
							}
						}
						desc = ep3_contract_event.0070.desc_liege_levies
					}
					triggered_desc = {
						trigger = {
							scope:task_contract_target.culture != scope:task_contract_employer.culture
						}
						desc = ep3_contract_event.0070.desc_liege_culture
					}
					triggered_desc = {
						trigger = {
							scope:task_contract_target.faith != scope:task_contract_employer.faith
						}
						desc = ep3_contract_event.0070.desc_liege_faith
					}
					desc = ep3_contract_event.0070.desc_liege_fallback
				}
			}
		}
		desc = ep3_contract_event.0070.desc_outro
	}
	theme = war
	#task_contract_taker, you
	left_portrait = {
		character = root
		animation = inspect_weapon
	}
	#commander, an envoy from employer
	right_portrait = {
		character = scope:commander
		animation = storyteller
	}
	#character giving you the contract
	lower_right_portrait = {
		character = scope:task_contract_employer
	}
	#character you have to fight in a war
	lower_left_portrait = {
		character = scope:task_contract_target
	}

	immediate = {
		set_contract_scopes_effect = yes
		scope:task_contract_employer = {
			random_knight = {
				save_scope_as = commander
			}
		}
		scope:task_contract_target = {
			random_held_title = {
				title_tier < kingdom
				limit = {
					trigger_if = {
						limit = {
							root.prestige_level > 3
						}
						tier >= tier_duchy
					}
					tier >= tier_county
					this != scope:task_contract_target.primary_title
					this != scope:task_contract_target.primary_title.title_capital_county
				}
				weight = {
					base = 1
					modifier = {
						add = 100
						root = {
							has_claim_on = prev
						}
					}
				}
				save_scope_as = promised_title
			}
		}
		scope:task_contract.var:task_contract_faction = {
			save_scope_as = task_contract_faction
		}
	}

	#take the contract and start the claim war, if they promise you land afterwards
	option = {
		name = ep3_contract_event.0070.a
		trigger = {
			custom_description = {
				text = adventurer_not_famous_trigger_tt
				value = 3
				prestige_level >= 3
			}
			exists = scope:promised_title
		}
		show_as_unavailable = {
			exists = scope:promised_title
		}
		join_faction_forced = {
		 	faction = scope:task_contract.var:task_contract_faction
		 	forced_by = scope:task_contract.task_contract_employer
		 	years = 1
		}
		# Give me land
		scope:task_contract = {
			set_variable = {
				name = task_contract_title
				value = scope:promised_title
			}
		}
		show_as_tooltip = {
			custom_tooltip = task_contract_tab_success
			
			create_title_and_vassal_change = {
				type = granted
				save_scope_as = title_change_vassal
			}
			scope:promised_title = {
				change_title_holder = {
					holder = scope:task_contract.task_contract_taker
					change = scope:title_change_vassal
					take_baronies = no
				}
			}
			resolve_title_and_vassal_change = scope:title_change_vassal
		}
		open_view = {
			view = factions_window
			player = root
		}
		#AI should always try to complete the contract
		ai_chance = {
			base = 20
			modifier = {
				add = 1000
				has_claim_on = scope:promised_title
			}
			modifier = {
				add = 20
				has_realm_law = camp_purpose_legitimists
			}
		}
	}
	#take the contract and start the claim war
	option = {
		name = ep3_contract_event.0070.b
		join_faction_forced = {
		 	faction = scope:task_contract.var:task_contract_faction
		 	forced_by = scope:task_contract.task_contract_employer
		 	years = 1
		}
		open_view = {
			view = factions_window
			player = root
		}
		
		#AI should always try to complete the contract
		ai_chance = {
			base = 20
		}
	}
	#invalidate the contract
	option = {
		name = ep3_contract_event.0001.invalidate
		scope:task_contract = {
			set_variable = {
				name = suppress_invalidation_event
				value = yes
			}
			invalidate_contract = yes
		}
		#AI should always try to complete the contract
		ai_chance = {
			base = 0
		}
	}
}

### Help out in a council task contract

scripted_effect set_council_scopes_effect = {
	scope:task_contract = {
		var:task_contract_councillor = {
			save_scope_as = task_contract_councillor
		}
		var:task_contract_councillor_liege = {
			save_scope_as = task_contract_councillor_liege
		}
	}
}

## Court Chaplain
# Fabricate claim - intro
ep3_contract_event.0080 = {
	type = character_event
	title = ep3_contract_event.0080.t
	desc = ep3_contract_event.0080.desc
	theme = faith
	left_portrait = {
		character = root
		animation = interested_left
	}
	right_portrait = {
		character = scope:task_contract_councillor
		animation = storyteller
	}
	lower_right_portrait = {
		character = scope:task_contract_councillor_liege
	}

	trigger = {
	}
	
	immediate = {
		set_contract_scopes_effect = yes
		set_council_scopes_effect = yes
	}
	
	#Open intetactin to fabricate claim
	option = {
		name = ep3_contract_event.0080.a
		custom_tooltip = ep3_contract_event.0080.open_start_generate_claim_interaction
		open_interaction_window = {
			interaction = start_generate_claim_interaction
			actor = root
			recipient = scope:task_contract_target
		}	
		if = {
			limit = {
				is_ai = yes
			}
			begin_contract_scheme_with_agents_effect = {
				SCHEME_TYPE = generate_claim
				TARGET_TYPE = target_title
				TARGET_SCOPE = scope:task_contract_target
				TASK_CONTRACT = scope:task_contract
				# Success.
				AGENT_1 = agent_scribe
				AGENT_2 = agent_diplomat
				# Speed.
				AGENT_3 = agent_justiciar
				AGENT_4 = agent_socialite
				# Secrecy.
				AGENT_5 = agent_decoy
			}
		}
		ai_chance = {
			base = 100
		}
	}
	#invalidate the contract
	option = {
		name = ep3_contract_event.0001.invalidate
		scope:task_contract = {
			invalidate_contract = yes
		}
		#AI should always try to complete the contract
		ai_chance = {
			base = 0
		}
	}
}

# Fight Faith conversion - intro
ep3_contract_event.0082 = {
	type = character_event
	title = ep3_contract_event.0082.t
	desc = ep3_contract_event.0082.desc
	theme = faith
	left_portrait = {
		character = root
		animation = menacing
	}
	lower_left_portrait = {
		character = scope:task_contract_councillor_liege
	}
	lower_right_portrait = {
		character = scope:task_contract_employer
	}

	trigger = {
	}
	
	immediate = {
		set_contract_scopes_effect = yes
		set_council_scopes_effect = yes
	}
	
	#help at the location
	option = {
		name = ep3_contract_event.0082.a
		custom_tooltip = ep3_contract_event.0082.to_destination
		if = {
			limit = {
				location = scope:task_contract_destination
			}
			trigger_event = ep3_contract_event.0083
		}
		else = {
			start_travel_plan = {
				destination = scope:task_contract_destination
				on_arrival_destinations = all
				on_arrival_event = ep3_contract_event.0083
			}
		}
		ai_chance = {
			base = 100
		}
	}
	#talk to the liege
	option = {
		name = ep3_contract_event.0082.b
		custom_tooltip = ep3_contract_event.0082.to_liege
		if = {
			limit = {
				location = scope:task_contract_councillor_liege.capital_province
			}
			trigger_event = ep3_contract_event.0084
		}
		else = {
			start_travel_plan = {
				destination = scope:task_contract_councillor_liege.capital_province
				on_arrival_destinations = all
				on_arrival_event = ep3_contract_event.0084
			}
		}
		ai_chance = {
			base = 100
		}
	}
	#invalidate the contract
	option = {
		name = ep3_contract_event.0001.invalidate
		scope:task_contract = {
			invalidate_contract = yes
		}
		#AI should always try to complete the contract
		ai_chance = {
			base = 0
		}
	}
}

scripted_effect protect_county_from_conversion_effect = {
	scope:task_contract_councillor_liege = {
		set_variable = {
			name = hold_court_8120_religion_block
			value = scope:task_contract_destination.faith
			years = 15
		}
		add_character_modifier = {
			modifier = hold_court_8120_tolerance_modifier
			years = 10
		}
	}
	scope:task_contract_destination.county = {
		add_county_modifier = {
			modifier = hold_court_8120_stopped_modifier
			years = 15
		}
	}
	scope:task_contract_councillor = {
		start_default_task = yes
	}	
}

# Fight Faith conversion - deal with it at location
ep3_contract_event.0083 = {
	type = character_event
	title = ep3_contract_event.0083.t
	desc = ep3_contract_event.0083.desc
	theme = faith
	override_background = {
		reference = temple_scope
	}
   	override_effect_2d = {
   		reference = smoke	
   	}
	left_portrait = {
		character = root
		animation = shock
	}
	right_portrait = {
		character = scope:task_contract_employer
		animation = rage
	}
	lower_left_portrait = {
		character = scope:task_contract_councillor
	}
	lower_right_portrait = {
		character = scope:task_contract_councillor_liege
	}

	trigger = {
	}
	
	immediate = {
		set_contract_scopes_effect = yes
		set_council_scopes_effect = yes
	}
	
	#capture the chaplain
	option = {
		name = ep3_contract_event.0083.a
		duel = {
			skill = intrigue
			target = scope:task_contract_councillor
			25 = {
				desc = ep3_contract_event.0083.a_win
				send_interface_toast = {
					title = ep3_contract_event.0083.a_win
					left_icon = root
					right_icon = scope:task_contract_employer
					prisoner_of_war_capture_effect = {
						TARGET = scope:task_contract_councillor
						IMPRISONER = root
					}
					scope:task_contract_councillor_liege = {
						add_opinion = {
							modifier = fp3_wrongful_imprisonment_opinion
							opinion = -30
							target = root
						}
					}
				}
				scope:task_contract = {
					complete_task_contract = success_standard
				}
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
				}
			}
			25 = {
				desc = ep3_contract_event.0083.a_lose
				send_interface_toast = {
					title = ep3_contract_event.0083.a_lose
					left_icon = root
					right_icon = scope:task_contract_employer
					scope:task_contract = {
						complete_task_contract = failure_standard
					}
				}
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = 5
				}
			}
		}
		stress_impact = {
			callous = minor_stress_impact_loss
			just = minor_stress_impact_loss
			vengeful = minor_stress_impact_loss
			lazy = minor_stress_impact_gain
			calm = minor_stress_impact_gain
		}
		
		ai_chance = {
			base = 100
		}
	}
	#force it through
	option = {
		name = ep3_contract_event.0083.b
		duel = {
			skills = { martial prowess }
			target = scope:task_contract_councillor
			25 = {
				desc = ep3_contract_event.0083.b_win
				send_interface_toast = {
					title = ep3_contract_event.0083.b_win
					left_icon = root
					right_icon = scope:task_contract_employer
					protect_county_from_conversion_effect = yes
					scope:task_contract_councillor_liege = {
						add_opinion = {
							modifier = fp2_questioned_my_faith_opinion
							target = root
						}
					}
				}
				scope:task_contract = {
					complete_task_contract = success_standard
				}
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
				}
			}
			25 = {
				desc = ep3_contract_event.0083.b_lose
				send_interface_toast = {
					title = ep3_contract_event.0083.b_lose
					left_icon = root
					right_icon = scope:task_contract_employer
					scope:task_contract = {
						complete_task_contract = failure_standard
					}
				}
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = 5
				}	
			}
		}
		stress_impact = {
			wrathful = minor_stress_impact_loss
			craven = minor_stress_impact_gain
		}
		
		ai_chance = {
			base = 10
			modifier = {
				add = 100
				OR = {
					highest_skill = martial
					prowess > scope:task_contract_councillor.prowess
				}
			}
		}
	}
	#talk it through
	option = {
		name = ep3_contract_event.0083.c
		duel = {
			skills = { diplomacy learning }
			target = scope:task_contract_councillor
			25 = {
				desc = ep3_contract_event.0083.c_win
				send_interface_toast = {
					title = ep3_contract_event.0083.c_win
					left_icon = root
					right_icon = scope:task_contract_employer
					protect_county_from_conversion_effect = yes
					scope:task_contract_councillor_liege = {
						add_opinion = {
							modifier = fp2_questioned_my_faith_opinion
							target = root
						}
					}
				}
				scope:task_contract = {
					complete_task_contract = success_standard
				}
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
				}
			}
			25 = {
				desc = ep3_contract_event.0083.c_lose
				send_interface_toast = {
					title = ep3_contract_event.0083.c_lose
					left_icon = root
					right_icon = scope:task_contract_employer
					scope:task_contract = {
						complete_task_contract = failure_standard
					}
				}
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = 5
				}	
			}
		}
		stress_impact = {
			gregarious = minor_stress_impact_loss
			zealous = minor_stress_impact_loss
			shy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			modifier = {
				add = 100
				OR = {
					highest_skill = diplomacy
					highest_skill = learning
				}
			}
		}
	}
	#come with me
	option = {
		name = ep3_contract_event.0083.d
		scope:task_contract = {
			complete_task_contract = failure_standard
		}
		if = {
			limit = {
				scope:task_contract_employer = {
					is_landed = yes
				}
			}
			random_list = {
				110 = {
					modifier = {
						add = scope:task_contract_employer.ai_rationality
					}
					hidden_effect = {
						scope:task_contract_employer = {
							depose = yes
							if = {
								limit = {
									any_traveling_family_member = { }
								}
								every_traveling_family_member = {
									save_temporary_scope_as = family_to_move
									root = { add_courtier = scope:family_to_move }
								}
							}
						}
					}
					add_courtier = scope:task_contract_employer
					reverse_add_opinion = {
						modifier = helped_me_in_time_of_need
						target = scope:task_contract_employer
					}
				}
				110 = {
					modifier = {
						add = scope:task_contract_employer.ai_honor
					}
					reverse_add_opinion = {
						modifier = mocked_me_in_time_of_need
						target = scope:task_contract_employer
					}
				}
			}
		}
		else = {
			add_courtier = scope:task_contract_employer
			reverse_add_opinion = {
				modifier = helped_me_in_time_of_need
				target = scope:task_contract_employer
			}
			hidden_effect = {
				if = {
					limit = {
						any_traveling_family_member = { }
					}
					every_traveling_family_member = {
						save_temporary_scope_as = family_to_move
						root = { add_courtier = scope:family_to_move }
					}
				}
			}
		}
		stress_impact = {
			compassionate = minor_stress_impact_loss
			just = minor_stress_impact_gain
			zealous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 0
			modifier = {
				add = 10
				scope:task_contract_employer = {
					is_landed = no
				}
			}
		}
	}
}

# Fight Faith conversion - deal with it at liege
ep3_contract_event.0084 = {
	type = character_event
	title = ep3_contract_event.0084.t
	desc = ep3_contract_event.0084.desc
	theme = faith
	override_background = {
		reference = throne_room
	}
	left_portrait = {
		character = root
		animation = debating
	}
	right_portrait = {
		character = scope:task_contract_councillor_liege
		animation = thinking
	}
	lower_left_portrait = {
		character = scope:task_contract_employer
	}
	lower_right_portrait = {
		character = scope:task_contract_councillor
	}

	trigger = {
	}
	
	immediate = {
		set_contract_scopes_effect = yes
		set_council_scopes_effect = yes
	}

	#suggest new management
	option = {
		name = ep3_contract_event.0084.a
		duel = {
			skills = { intrigue prowess }
			target = scope:task_contract_target
			0 = {
				desc = ep3_contract_event.0084.a_win_rights
				compare_modifier = {
					value = scope:duel_value
					multiplier = 1
				}
				modifier = {
					factor = root.prestige_level
				}
				send_interface_toast = {
					title = ep3_contract_event.0084.a_win_rights
					left_icon = root
					right_icon = scope:task_contract_employer
					create_title_and_vassal_change = {
						type = granted
						save_scope_as = title_change_vassal
					}
					scope:task_contract.var:task_contract_destination.county = {
						change_title_holder = {
							holder = scope:task_contract_employer
							change = scope:title_change_vassal
							take_baronies = no
						}
					}
					resolve_title_and_vassal_change = scope:title_change_vassal
					scope:task_contract_employer = {
						custom_tooltip = ep3_contract_event.0084.a_win_rights.tt
						if = {
							limit = {
								is_vassal_of = scope:task_contract_target
							}
							vassal_contract_set_obligation_level = {
								type = religious_rights
								level = 1
							}
						}
					}
				}
				scope:task_contract = {
					complete_task_contract = success_standard
				}
			}
			25 = {
				desc = ep3_contract_event.0084.a_win
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
				}
				send_interface_toast = {
					title = ep3_contract_event.0084.a_win
					left_icon = root
					right_icon = scope:task_contract_employer
					create_title_and_vassal_change = {
						type = granted
						save_scope_as = title_change_vassal
					}
					scope:task_contract.var:task_contract_destination.county = {
						change_title_holder = {
							holder = scope:task_contract_employer
							change = scope:title_change_vassal
							take_baronies = no
						}
					}
					resolve_title_and_vassal_change = scope:title_change_vassal
				}
				scope:task_contract = {
					complete_task_contract = success_standard
				}
			}
			25 = {
				desc = ep3_contract_event.0084.a_lost
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = 5
				}
				send_interface_toast = {
					title = ep3_contract_event.0084.a_lost
					left_icon = root
					right_icon = scope:task_contract_employer
					scope:task_contract = {
						complete_task_contract = failure_standard
					}
					scope:task_contract_councillor_liege = {
						add_opinion = {
							modifier = fp2_questioned_my_faith_opinion
							opinion = -30
							target = root
						}
					}
				}
			}
		}
		stress_impact = {
			ambitious = minor_stress_impact_loss
			impatient = minor_stress_impact_loss
			arrogant = minor_stress_impact_loss
			craven = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			modifier = {
				add = 100
				OR = {
					highest_skill = intrigue
					prowess > scope:task_contract_target.prowess
				}
			}
		}
	}

	#talk it through
	option = {
		name = ep3_contract_event.0084.b
		duel = {
			skills = { diplomacy learning }
			target = scope:task_contract_target
			25 = {
				desc = ep3_contract_event.0084.b_win
				send_interface_toast = {
					title = ep3_contract_event.0084.b_win
					left_icon = root
					right_icon = scope:task_contract_employer
					protect_county_from_conversion_effect = yes
				}
				scope:task_contract = {
					complete_task_contract = success_standard
				}
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
				}
			}
			25 = {
				desc = ep3_contract_event.0084.b_lost
				scope:task_contract = {
					complete_task_contract = failure_standard
				}
				send_interface_toast = {
					title = ep3_contract_event.0084.b_lost
					left_icon = root
					right_icon = scope:task_contract_employer
					scope:task_contract_councillor_liege = {
						add_opinion = {
							modifier = fp2_questioned_my_faith_opinion
							opinion = -30
							target = root
						}
					}
				}
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = 5
				}
			}
		}
		stress_impact = {
			gregarious = minor_stress_impact_loss
			zealous = minor_stress_impact_loss
			shy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			modifier = {
				add = 100
				OR = {
					highest_skill = diplomacy
					highest_skill = learning
				}
			}
		}
	}
}

# Help Faith conversion - intro
ep3_contract_event.0085 = {
	type = character_event
	title = ep3_contract_event.0085.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:task_contract_councillor = {
						has_personality_malicious_trigger = yes
					}
				}
				desc = ep3_contract_event.0085.desc_bad
			}
			desc = ep3_contract_event.0085.desc_good
		}
	}
	theme = faith
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = {
				scope:task_contract_councillor = {
					has_personality_malicious_trigger = yes
				}
			}
			animation = stunned
		}
		animation = prayer
	}
	right_portrait = {
		character = scope:task_contract_councillor
		animation = storyteller
	}
	lower_right_portrait = {
		character = scope:task_contract_councillor_liege
	}

	trigger = {
	}
	
	immediate = {
		set_contract_scopes_effect = yes
		set_council_scopes_effect = yes
	}

	#you condemn the evil chaplain methods
	option = {
		name = ep3_contract_event.0085.a
		trigger = {
			scope:task_contract_councillor = {
				has_personality_malicious_trigger = yes
			}
		}
		duel = {
			skills = { prowess diplomacy }
			target = scope:task_contract_councillor
			0 = {
				desc = ep3_contract_event.0085.a_win_critical
				compare_modifier = {
					value = scope:duel_value
					multiplier = 1
				}
				modifier = {
					factor = root.prestige_level
				}
				send_interface_toast = {
					title = ep3_contract_event.0085.a_win_critical
					left_icon = root
					right_icon = scope:task_contract_employer
					prisoner_of_war_capture_effect = {
						TARGET = scope:task_contract_councillor
						IMPRISONER = root
					}
					scope:task_contract_councillor_liege = {
						add_opinion = {
							modifier = fp3_wrongful_imprisonment_opinion
							opinion = -30
							target = root
						}
					}
				}
				scope:task_contract = {
					complete_task_contract = failure_standard
				}
			}
			25 = {
				desc = ep3_contract_event.0085.a_win
				send_interface_toast = {
					title = ep3_contract_event.0085.a_win
					left_icon = root
					right_icon = scope:task_contract_employer
					protect_county_from_conversion_effect = yes
					scope:task_contract = {
						complete_task_contract = failure_standard
					}
					scope:task_contract_councillor_liege = {
						add_opinion = {
							modifier = fp3_wrongful_imprisonment_opinion
							opinion = -30
							target = root
						}
					}
				}
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
				}
			}
			25 = {
				desc = ep3_contract_event.0085.a_lose
				send_interface_toast = {
					title = ep3_contract_event.0085.a_lose
					left_icon = root
					right_icon = scope:task_contract_employer
					scope:task_contract = {
						complete_task_contract = failure_standard
					}
					scope:task_contract_councillor_liege = {
						add_opinion = {
							modifier = fp3_wrongful_imprisonment_opinion
							opinion = -30
							target = root
						}
					}
				}
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = 5
				}
			}
		}
		stress_impact = {
			honest = minor_stress_impact_loss
			zealous = minor_stress_impact_loss
			compassionate = minor_stress_impact_loss
			sadistic = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			modifier = {
				add = 100
				OR = {
					highest_skill = diplomacy
					prowess > scope:task_contract_councillor.prowess
				}
			}
		}
	}

	#you agree with the evil chaplain methods
	option = {
		name = ep3_contract_event.0085.b
		trigger = {
			scope:task_contract_councillor = {
				has_personality_malicious_trigger = yes
			}
		}
		scope:task_contract = {
			complete_task_contract = success_standard
		}
		stress_impact = {
			honest = minor_stress_impact_gain
			compassionate = minor_stress_impact_gain
			sadistic = major_stress_impact_loss
		}
		ai_chance = {
			base = 10
			modifier = {
				add = 100
				OR = {
					highest_skill = diplomacy
					prowess > scope:task_contract_councillor.prowess
				}
			}
		}
	}

	#you tell a story about the good gods
	option = {
		name = ep3_contract_event.0085.c
		trigger = {
			scope:task_contract_councillor = {
				has_personality_malicious_trigger = no
			}
		}
		duel = {
			skill = learning
			value = high_skill_rating
			25 = {
				desc = ep3_contract_event.0085.c_win
				send_interface_toast = {
					title = ep3_contract_event.0085.c_win
					left_icon = root
					right_icon = scope:task_contract_employer
					scope:task_contract = {
						complete_task_contract = success_standard
					}
				}
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
				}
			}
			25 = {
				desc = ep3_contract_event.0085.c_lose
				send_interface_toast = {
					title = ep3_contract_event.0085.a_lose
					left_icon = root
					right_icon = scope:task_contract_employer
					scope:task_contract = {
						complete_task_contract = failure_standard
					}
				}
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = 5
				}
			}
		}
		stress_impact = {
			gregarious = minor_stress_impact_loss
			zealous = minor_stress_impact_loss
			compassionate = minor_stress_impact_loss
			shy = minor_stress_impact_gain
			cynical = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			modifier = {
				add = 100
				highest_skill = learning
			}
		}
	}

	#you tell a story about the evil gods
	option = {
		name = ep3_contract_event.0085.d
		trigger = {
			scope:task_contract_councillor = {
				has_personality_malicious_trigger = no
			}
		}
		duel = {
			skill = intrigue
			value = high_skill_rating
			25 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
				}
				desc = ep3_contract_event.0085.d_win
				send_interface_toast = {
					title = ep3_contract_event.0085.d_win
					left_icon = root
					right_icon = scope:task_contract_employer
					scope:task_contract = {
						complete_task_contract = success_standard
					}
				}
			}
			25 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = 5
				}
				desc = ep3_contract_event.0085.d_lose
				send_interface_toast = {
					title = ep3_contract_event.0085.d_lose
					left_icon = root
					right_icon = scope:task_contract_employer
					scope:task_contract = {
						complete_task_contract = failure_standard
					}
				}
			}
		}
		stress_impact = {
			gregarious = minor_stress_impact_loss
			zealous = minor_stress_impact_gain
			shy = minor_stress_impact_gain
			cynical = minor_stress_impact_loss
		}
		ai_chance = {
			base = 10
			modifier = {
				add = 100
				highest_skill = intrigue
			}
		}
	}

	#invalidate the contract
	option = {
		name = ep3_contract_event.0001.invalidate
		scope:task_contract = {
			invalidate_contract = yes
		}
		#AI should always try to complete the contract
		ai_chance = {
			base = 0
		}
	}
}

## Marshal
# train commanders - intro
ep3_contract_event.0090 = {
	type = character_event
	title = ep3_contract_event.0090.t
	desc = ep3_contract_event.0090.desc
	theme = landless_adventurer
	#task_contract_taker, you
	left_portrait = {
		character = root
		animation = inspect_weapon
	}
	#marshal
	right_portrait = {
		character = scope:task_contract_councillor
		animation = storyteller
	}
	#marshal's liege
	lower_right_portrait = {
		character = scope:task_contract_councillor_liege
	}

	immediate = {
		set_contract_scopes_effect = yes
		set_council_scopes_effect = yes
	}

	option = {
		name = ep3_contract_event.0090.a
		custom_tooltip = ep3_contract_event.0090.opens_task_contract_train_knight_interaction
		open_interaction_window = {
			interaction = task_contract_train_knight_interaction
			actor = root
			recipient = scope:task_contract_employer
		}	
		if = {
			limit = {
				is_ai = yes
			}
			run_interaction = {
				interaction = task_contract_train_knight_interaction
				actor = root
				recipient = scope:task_contract_employer
				execute_threshold = decline
			}
		}
		#AI should always try to complete the contract
		ai_chance = {
			base = 20
		}
	}
	#invalidate the contract
	option = {
		name = ep3_contract_event.0001.invalidate
		scope:task_contract = {
			invalidate_contract = yes
		}
		#AI should always try to complete the contract
		ai_chance = {
			base = 0
		}
	}
}

scripted_effect count_knights_trained_effect = {
	scope:task_contract = {
		if = {
			limit = {
				$RESULT$ = yes
			}
			change_variable = {
				name = knights_trained
				add = 1
			}
			if = {
				limit = {
					NOT = {
						scope:task_contract = {
							has_variable_list = knights_to_train
							any_in_list = {
								variable = knights_to_train
								is_alive = yes
								is_knight = yes
							}
						}
					}
				}
				scope:task_contract = {
					if = {
						limit = {
							scope:task_contract.var:knights_trained >= scope:task_contract.var:knights_limit
						}
						complete_task_contract = success_critical
					}
					else_if = {
						limit = {
							scope:task_contract.var:knights_trained >= scope:task_contract.var:knights_failed
						}
						complete_task_contract = success_standard
					}
					else = {
						complete_task_contract = failure_standard
					}
				}
			}
		}
		if = {
			limit = {
				$RESULT$ = no
			}
			change_variable = {
				name = knights_failed
				add = 1
			}
			if = {
				limit = {
					NOT = {
						scope:task_contract = {
							has_variable_list = knights_to_train
							any_in_list = {
								variable = knights_to_train
								is_alive = yes
								is_knight = yes
							}
						}
					}
				}
				scope:task_contract = {
					if = {
						limit = {
							NOT = { scope:task_contract.var:knights_trained = 0 }
							scope:task_contract.var:knights_trained >= scope:task_contract.var:knights_failed
						}
						complete_task_contract = success_standard
					}
					else = {
						complete_task_contract = failure_standard
					}
				}
			}
		}
	}
}

# train commanders - interaction event
ep3_contract_event.0091 = {
	type = character_event
	title = ep3_contract_event.0091.t
	desc = {
		desc = ep3_contract_event.0091.desc
		first_valid = {
			triggered_desc = {
				trigger = { scope:helper = root }
				desc = {
					desc = ep3_contract_event.0091.desc_me
					first_valid = {
						triggered_desc = {
							trigger = {root.prowess < high_skill_rating }
							desc = ep3_contract_event.0091.desc_me_high_prowess
						}
						desc = ep3_contract_event.0091.desc_me_low_prowess
					}
				}
			}
			desc = {
				desc = ep3_contract_event.0091.desc_helper
				first_valid = {
					triggered_desc = {
						trigger = {scope:helper.prowess < high_skill_rating }
						desc = ep3_contract_event.0091.desc_high_prowess
					}
					desc = ep3_contract_event.0091.desc_low_prowess
				}
			}
		}
		desc = ep3_contract_event.0091.desc_outro
	}
	theme = war
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = {
				scope:helper = root
				root.prowess < high_skill_rating
			}
			animation = random_weapon_yield
		}
		triggered_animation = {
			trigger = {
				scope:helper = root
				root.prowess >= high_skill_rating
			}
			animation = inspect_weapon
		}
		triggered_animation = {
			trigger = {
				scope:helper != root
				scope:helper.prowess < high_skill_rating
			}
			animation = stunned
		}
		triggered_animation = {
			trigger = {
				scope:helper != root
				scope:helper.prowess >= high_skill_rating
			}
			animation = disappointed
		}
	}
	right_portrait = {
		character = scope:knight
		triggered_animation = {
			trigger = {
				scope:helper = root
				root.prowess < high_skill_rating
			}
			animation = random_weapon_celebrate
		}
		triggered_animation = {
			trigger = {
				scope:helper = root
				root.prowess >= high_skill_rating
			}
			animation = random_weapon_yield
		}
		triggered_animation = {
			trigger = {
				scope:helper != root
				scope:helper.prowess < high_skill_rating
			}
			animation = random_weapon_celebrate
		}
		triggered_animation = {
			trigger = {
				scope:helper != root
				scope:helper.prowess >= high_skill_rating
			}
			animation = random_weapon_yield
		}
	}
	lower_left_portrait = {
		trigger = { scope:helper != root }
		character = scope:helper
	}
	lower_right_portrait = {
		character = scope:task_contract_councillor
	}
	lower_center_portrait = {
		character = scope:task_contract_councillor_liege
	}
	
	immediate = {
		set_contract_scopes_effect = yes
		set_council_scopes_effect = yes
		# search for anyone that could help you train them
		random_court_position_holder = {
			type = second_camp_officer
			add_to_list = helpers_list
		}
		random_court_position_holder = {
			type = master_of_arms_camp_officer
			add_to_list = helpers_list
		}
		random_court_position_holder = {
			type = light_cavalry_captain_camp_officer
			add_to_list = helpers_list
		}
		random_court_position_holder = {
			type = camelry_captain_camp_officer
			add_to_list = helpers_list
		}
		random_court_position_holder = {
			type = elephantry_captain_camp_officer
			add_to_list = helpers_list
		}
		random_court_position_holder = {
			type = heavy_cavalry_captain_camp_officer
			add_to_list = helpers_list
		}
		random_court_position_holder = {
			type = horse_archer_captain_camp_officer
			add_to_list = helpers_list
		}
		random_court_position_holder = {
			type = archer_captain_camp_officer
			add_to_list = helpers_list
		}
		random_court_position_holder = {
			type = heavy_infantry_captain_camp_officer
			add_to_list = helpers_list
		}
		random_court_position_holder = {
			type = light_infantry_captain_camp_officer
			add_to_list = helpers_list
		}
		random_court_position_holder = {
			type = pike_captain_camp_officer
			add_to_list = helpers_list
		}
		random_in_list = {
			list = helpers_list
			save_scope_as = helper
		}
		if = {
			limit = {
				exists = scope:helper
			}
			scope:helper = {
				every_character_trait = {
					limit = {
						has_trait_category = commander
					}
					scope:task_contract = {
						add_to_variable_list = {
							name = takers_commander_traits
							target = prev
						}
					}
				}
			}
		}
		else = {
			save_scope_as = helper
		}
		scope:task_contract = {
			random_in_list = {
				variable = takers_commander_traits
				save_scope_as = trait_to_teach
			}
		}
		scope:helper = {
			set_signature_weapon_effect = yes
		}
		scope:knight = {
			set_signature_weapon_effect = yes
		}
		scope:task_contract = {
			remove_list_variable = {
				name = knights_to_train
				target = scope:knight
			}
		}
	}

	# steal the knight
	option = {
		name = ep3_contract_event.0091.a
		trigger = { scope:knight = { is_landed = no } }
		duel = {
			skill = diplomacy
			target = scope:knight
			25 = {
				desc = ep3_contract_event.0091_won_recruit
				modifier = {
					add = root.prestige_level
					factor = 5
				}
				send_interface_toast = {
					title = ep3_contract_event.0091_won_recruit
					left_icon = root
					right_icon = scope:knight
					add_courtier = scope:knight
					domicile = {
						change_provisions = {
							value = scope:knight.prowess
							multiply = -4
						}
					}
					pay_short_term_gold = {
						target = scope:task_contract_employer
						gold = {
							value = scope:knight.prowess
							multiply = 5
						}
					}
				}
				count_knights_trained_effect = { RESULT = no }
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
				}
			}
			25 = {
				desc = ep3_contract_event.0091_lost_recruit
				send_interface_toast = {
					title = ep3_contract_event.0091_lost_recruit
					left_icon = root
					right_icon = scope:knight
				}
				count_knights_trained_effect = { RESULT = no }
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = 5
				}
			}
		}
		stress_impact = {
			impatient = minor_stress_impact_loss
			just = minor_stress_impact_gain
			honest = minor_stress_impact_gain
			callous = minor_stress_impact_loss
			deceitful = minor_stress_impact_loss
		}
		ai_chance = {
			base = 10
			modifier = {
				add = 100
				highest_skill = diplomacy
			}
		}
	}

	# teach them a trait you know
	option = {
		name = ep3_contract_event.0091.b
		trigger = {
			exists = scope:trait_to_teach
			scope:knight = {
				NOT = { has_trait = scope:trait_to_teach }
			}
		}
		duel = {
			skill = martial
			target = scope:knight
			25 = {
				desc = ep3_contract_event.0091_won_trait
				modifier = {
					add = root.learning
				}
				send_interface_toast = {
					title = ep3_contract_event.0091_won_trait
					left_icon = root
					right_icon = scope:knight
					scope:knight = {
						add_trait = scope:trait_to_teach
					}
				}
				count_knights_trained_effect = { RESULT = yes }
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
				}
			}
			25 = {
				desc = ep3_contract_event.0091_lost
				send_interface_toast = {
					title = ep3_contract_event.0091_lost
					left_icon = root
					right_icon = scope:knight
				}
				count_knights_trained_effect = { RESULT = no }
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = 5
				}
			}
		}
		stress_impact = {
			brave = minor_stress_impact_loss
			craven = minor_stress_impact_gain
			humble = minor_stress_impact_gain
			arrogant = minor_stress_impact_loss
			stubborn = minor_stress_impact_loss
		}
		ai_chance = {
			base = 10
			modifier = {
				add = 100
				highest_skill = martial
			}
		}
	}

	# let helper teach them some prowess
	option = {
		name = ep3_contract_event.0091.c
		trigger = {
			exists = scope:helper
			scope:helper != root
		}
		scope:helper = {
			duel = {
				skill = prowess
				target = scope:knight
				25 = {
					desc = ep3_contract_event.0091_won_helper
					send_interface_toast = {
						title = ep3_contract_event.0091_won_helper
						left_icon = root
						right_icon = scope:knight
						scope:knight = {
							add_prowess_skill = {
								value = scope:helper.prowess
								subtract = scope:knight.prowess
								divide = 4
								add = {
									value = scope:knight.ai_boldness
									divide = 10
								}
								add = {
									value = scope:helper.ai_boldness
									divide = 10
								}
								min = 2
								max = 5
							}
							force_character_skill_recalculation = yes
						}
					}
					count_knights_trained_effect = { RESULT = yes }
					compare_modifier = {
						value = scope:duel_value
						multiplier = 1
					}
				}
				25 = {
					desc = ep3_contract_event.0091_lost
					count_knights_trained_effect = { RESULT = no }
					send_interface_toast = {
						title = ep3_contract_event.0091_lost
						left_icon = root
						right_icon = scope:knight
					}
					compare_modifier = {
						value = scope:duel_value
						multiplier = -3.5
						min = 5
					}
				}
			}
		}
		stress_impact = {
			arrogant = minor_stress_impact_gain
			ambitious = minor_stress_impact_gain
			humble = minor_stress_impact_loss
			shy = minor_stress_impact_loss
		}
		ai_chance = {
			base = 10
			modifier = {
				add = 100
				scope:helper.prowess > scope:knight.prowess
			}
		}
	}

	# teach them some prowess yourself
	option = {
		name = ep3_contract_event.0091.d
		duel = {
			skill = prowess
			target = scope:knight
			50 = {
				desc = ep3_contract_event.0091_won
				send_interface_toast = {
					title = ep3_contract_event.0091_won
					left_icon = root
					right_icon = scope:knight
					scope:knight = {
						add_prowess_skill = {
							value = root.prowess
							subtract = scope:knight.prowess
							divide = 4
							add = {
								value = scope:knight.ai_boldness
								divide = 10
							}
							add = {
								value = root.ai_boldness
								divide = 10
							}		
							min = 1
							max = 4
						}
						force_character_skill_recalculation = yes
					}
				}
				count_knights_trained_effect = { RESULT = yes }
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
				}
				modifier = {
					add = {
						value = scope:knight.ai_energy
						divide = -10
					}
				}
				modifier = {
					add = {
						value = root.ai_energy
						divide = -10
					}
				}
			}
			50 = {
				desc = ep3_contract_event.0091_lost
				send_interface_toast = {
					title = ep3_contract_event.0091_lost
					left_icon = root
					right_icon = scope:knight
				}
				count_knights_trained_effect = { RESULT = no }
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = 5
				}
				modifier = {
					add = {
						value = scope:knight.ai_energy
						divide = 10
					}
				}
				modifier = {
					add = {
						value = root.ai_energy
						divide = 10
					}
				}
			}
		}
		stress_impact = {
			arrogant = minor_stress_impact_loss
			ambitious = minor_stress_impact_loss
			humble = minor_stress_impact_gain
			shy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			modifier = {
				add = 100
				prowess > scope:knight.prowess
			}
		}
	}

	after = {
		hidden_effect = {
			if = {
				limit = {
					exists = scope:trait_to_teach
				}
				scope:task_contract = {
					remove_list_variable = {
						name = takers_commander_traits
						target = scope:trait_to_teach
					}
				}
			}
			if = {
				limit = {
					scope:task_contract = {
						has_variable_list = knights_to_train
						any_in_list = {
							variable = knights_to_train
							is_alive = yes
							is_knight = yes
						}
					}
				}
				if = {
					limit = {
						is_ai = yes
					}
					#save new knight for the ai, as they can't use the interaction to do it
					ordered_in_list = {
						variable = knights_to_train
						order_by = {
							value = prowess
							multiply = -1
						}
						save_scope_as = knight
					}
					#run the event directly
					root = {
						trigger_event = {
							id = ep3_contract_event.0091
							days = 1
						}
					}
				}
				#open the interaction for human players
				else = {
					open_interaction_window = {
						interaction = task_contract_train_knight_interaction 
						actor = root
						recipient = scope:task_contract_employer
					}
				}
			}
		}
	}
}

scripted_effect set_corruption_reason_effect = {
	scope:corrupt_province.county = {
		switch = {
			trigger = has_county_modifier
			county_corruption_inefficient_tax_collection_modifier = {
				save_scope_value_as = {
					name = corruption_reason
					value = flag:taxes
				}
			}
			county_corruption_deserting_levies_modifier = {
				save_scope_value_as = {
					name = corruption_reason
					value = flag:riots
				}
			}
			county_corruption_smuggling_ring_modifier = {
				save_scope_value_as = {
					name = corruption_reason
					value = flag:bandits
				}
			}
			county_corruption_bandits_rampant_modifier = {
				save_scope_value_as = {
					name = corruption_reason
					value = flag:bandits
				}
			}
			county_corruption_inefficient_census_modifier = {
				save_scope_value_as = {
					name = corruption_reason
					value = flag:taxes
				}
			}
			county_corruption_lack_of_sheriffs_modifier = {
				save_scope_value_as = {
					name = corruption_reason
					value = flag:bandits
				}
			}
			county_corruption_lack_of_courts_modifier = {
				save_scope_value_as = {
					name = corruption_reason
					value = flag:bandits
				}
			}
			county_corruption_thieves_guild_modifier = {
				save_scope_value_as = {
					name = corruption_reason
					value = flag:bandits
				}
			}
			county_corruption_unsafe_highways_modifier = {
				save_scope_value_as = {
					name = corruption_reason
					value = flag:bandits
				}
			}
			county_corruption_uncooperative_guilds_modifier = {
				save_scope_value_as = {
					name = corruption_reason
					value = flag:taxes
				}
			}
			county_corruption_lackluster_administration_modifier = {
				save_scope_value_as = {
					name = corruption_reason
					value = flag:taxes
				}
			}
			small_investment_in_revolt_modifier = {
				save_scope_value_as = {
					name = corruption_reason
					value = flag:riots
				}
			}
			medium_investment_in_revolt_modifier = {
				save_scope_value_as = {
					name = corruption_reason
					value = flag:riots
				}
			}
			high_investment_in_revolt_modifier = {
				save_scope_value_as = {
					name = corruption_reason
					value = flag:riots
				}
			}
		}
		#fallback if the county have no modifier
		if = {
			limit = {
				NOT = { exists = scope:corruption_reason }
			}
			save_scope_value_as = {
				name = corruption_reason
				value = flag:low_control
			}
		}
	}
}

# increase control - intro
ep3_contract_event.0092 = {
	type = character_event
	title = ep3_contract_event.0092.t
	desc = {
		desc = ep3_contract_event.0092.desc
		first_valid = {
			triggered_desc = {
				trigger = { scope:corruption_reason = flag:taxes }
				desc = ep3_contract_event.0092.desc_taxes
			}
			triggered_desc = {
				trigger = { scope:corruption_reason = flag:bandits }
				desc = ep3_contract_event.0092.desc_bandits
			}
			triggered_desc = {
				trigger = { scope:corruption_reason = flag:riots }
				desc = ep3_contract_event.0092.desc_riots
			}
			triggered_desc = {
				trigger = { scope:corruption_reason = flag:low_control }
				desc = ep3_contract_event.0092.desc_low_control
			}
		}
	}
	theme = landless_adventurer
	#task_contract_taker, you
	left_portrait = {
		character = root
		animation = disbelief
	}
	#marshal
	right_portrait = {
		character = scope:task_contract_councillor
		animation = shame
	}
	#marshal's liege
	lower_right_portrait = {
		character = scope:task_contract_councillor_liege
	}
	widget = {
		gui = "event_window_widget_peasant_leader"
		container = "custom_widgets_container"
	}

	immediate = {
		ep3_peasant_leader_widget_setup_effect = yes
		set_contract_scopes_effect = yes
		set_council_scopes_effect = yes
		#saving scope for custom localization and corruption reason
		scope:task_contract_destination = {
			save_scope_as = corrupt_province
		}
		set_corruption_reason_effect = yes
	}

	#just travel there
	option = {
		name = ep3_contract_event.0092.a
		#trigger the event immediately if you are already there
		if = {
			limit = {
				scope:task_contract_destination = root.location
			}
			trigger_event = ep3_contract_event.0093
		}
		#otherwise, tirgger a travel plan
		else = {
			custom_tooltip = ep3_contract_event.0092.a_tt
			start_travel_plan = {
				destination = scope:task_contract_destination
				on_arrival_event = ep3_contract_event.0093
				on_arrival_destinations = all_but_last
				can_cancel_planning = no
			}
		}
		
		#AI should always try to complete the contract
		ai_chance = {
			base = 20
		}
	}

	#move your camp there
	option = {
		name = ep3_contract_event.0092.b
		trigger = {
			NOR = {
				scope:task_contract_destination = root.domicile.domicile_location
				scope:task_contract_destination = root.location
			}
		}
		custom_tooltip = ep3_contract_event.0092.b_tt
		custom_tooltip = ep3_contract_event.0001.with_domicile.tt
		start_travel_plan = {
			destination = scope:task_contract_destination
			on_arrival_event = ep3_contract_event.0093
			on_arrival_destinations = all
			travel_with_domicile = yes
			return_trip = no
			can_cancel_planning = no
		}
		
		#AI shouldn't move camps in events
		ai_chance = {
			base = 0
		}
	}
	#invalidate the contract
	option = {
		name = ep3_contract_event.0001.invalidate
		scope:task_contract = {
			invalidate_contract = yes
		}
		#AI should always try to complete the contract
		ai_chance = {
			base = 0
		}
	}
	after = {
		ep3_peasant_leader_widget_clear_effect = yes
	}
}

# increase control - arrival
ep3_contract_event.0093 = {
	type = character_event
	title = ep3_contract_event.0093.t
	desc = {
		desc = ep3_contract_event.0093.desc
		first_valid = {
			triggered_desc = {
				trigger = { scope:corruption_reason = flag:taxes }
				desc = ep3_contract_event.0093.desc_taxes
			}
			triggered_desc = {
				trigger = { scope:corruption_reason = flag:bandits }
				desc = ep3_contract_event.0093.desc_bandits
			}
			triggered_desc = {
				trigger = { scope:corruption_reason = flag:riots }
				desc = ep3_contract_event.0093.desc_riots
			}
			triggered_desc = {
				trigger = { scope:corruption_reason = flag:low_control }
				desc = ep3_contract_event.0093.desc_low_control
			}
		}
	}
	theme = landless_adventurer
	override_background = {
		reference = terrain_travel
	}
	#task_contract_taker, you
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = {
				scope:task_contract.var:control <= scope:task_contract.var:support
				scope:corruption_reason = flag:taxes
			}
			animation = personality_compassionate
		}
		triggered_animation = {
			trigger = {
				scope:task_contract.var:control <= scope:task_contract.var:support
				scope:corruption_reason = flag:bandits
			}
			animation = shock
		}
		triggered_animation = {
			trigger = {
				scope:task_contract.var:control <= scope:task_contract.var:support
				scope:corruption_reason = flag:riots
			}
			animation = interested_left
		}
		triggered_animation = {
			trigger = {
				scope:task_contract.var:control <= scope:task_contract.var:support
				scope:corruption_reason = flag:low_control
			}
			animation = shame
		}
		triggered_animation = {
			trigger = {
				scope:task_contract.var:control > scope:task_contract.var:support
				scope:corruption_reason = flag:taxes
			}
			animation = dismissal
		}
		triggered_animation = {
			trigger = {
				scope:task_contract.var:control > scope:task_contract.var:support
				scope:corruption_reason = flag:bandits
			}
			animation = disbelief
		}
		triggered_animation = {
			trigger = {
				scope:task_contract.var:control > scope:task_contract.var:support
				scope:corruption_reason = flag:riots
			}
			animation = disappointed
		}
		triggered_animation = {
			trigger = {
				scope:task_contract.var:control > scope:task_contract.var:support
				scope:corruption_reason = flag:low_control
			}
			animation = eyeroll
		}
	}
	#peasant spokeperson
	right_portrait = {
		character = scope:corrupt_province_peasant
		animation = beg
	}
	#marshal
	lower_left_portrait = {
		character = scope:task_contract_councillor
	}
	#marshal's liege
	lower_right_portrait = {
		character = scope:task_contract_councillor_liege
	}
	widget = {
		gui = "event_window_widget_peasant_leader"
		container = "custom_widgets_container"
	}
	cooldown = { days = 1 }

	trigger = {
		any_character_active_contract = {
			has_task_contract_type = laamp_help_increase_control_contract
		}
	}

	immediate = {
		set_contract_scopes_effect = yes
		set_council_scopes_effect = yes
		ep3_peasant_leader_widget_setup_effect = yes
		if = {
			limit = {
				NOT = { exists = scope:corrupt_province }
			}
			location = {
				save_scope_as = corrupt_province
			}
		}
		#remove the visited county from the list of corrupt counties, so you don't have to visit it anymore
		scope:task_contract = {
			remove_list_variable = {
				name = corrupt_counties
				target = scope:corrupt_province.county
			}		
		}
		#find a local peasant
		random_pool_character = {
			province = scope:corrupt_province
			limit = {
				is_available_healthy_ai_adult = yes
				faith = scope:corrupt_province.county.faith
				culture = scope:corrupt_province.county.culture
			}
			save_scope_as = corrupt_province_peasant
		}
		if = {
			limit = {
				NOT = { exists = scope:corrupt_province_peasant }
			}
			create_character = {
				location = scope:corrupt_province
				template = peasant_character
				gender_female_chance = 50
				faith = scope:corrupt_province.county.faith
				culture = scope:corrupt_province.county.culture
				save_scope_as = corrupt_province_peasant
			}
		}
		#add them to a list, they will become army leaders if a war breaks out
		scope:task_contract = {
			add_to_variable_list = {
				name = met_peasant_leaders
				target = scope:corrupt_province_peasant
			}
		}
		#set flag with reason for localization
		if = {
			limit = {
				NOT = { exists = scope:corruption_reason }
			}
			set_corruption_reason_effect = yes
		}
	}

	#help the marshal
	option = {
		name = ep3_contract_event.0093.a
		duel = {
			skill = martial
			value = high_skill_rating
			25 = {
				desc = ep3_contract_event.0093.a_win
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
				}
				add_dread = 5
				scope:corrupt_province.county = {
					add_county_modifier = {
						modifier = marshal_task_increase_control_increased_opinion_modifier
						years = 5
					}
				}
			}
			25 = {
				desc = ep3_contract_event.0093.a_lose
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = 5
				}
				scope:corrupt_province.county = {
					add_county_modifier = {
						modifier = marshal_task_military_presence_modifier
						years = 5
					}
				}
				if = {
					limit = {
						any_maa_regiment = { }
					}
					random_maa_regiment = {
						change_maa_troops_count = {
							value = maa_current_troops_count
							multiply = laamp_base_contract_schemes_1301_maa_damage_moderate_value
						}
					}
				}
				else_if = {
					limit = {
						any_courtier = {
							is_adult = yes
							NOR = {
								is_close_family_of = root
								is_spouse_of = root
							}
						}
					}
					ordered_courtier = {
						order_by = martial
						limit = {
							is_adult = yes
							NOR = {
								is_close_family_of = root
								is_spouse_of = root
							}
						}
						scope:corrupt_province.province_owner = {
							add_courtier = prev
						}
					}
				}
				else = {
					pay_short_term_gold = {
						target = scope:corrupt_province.province_owner
						gold = root.minor_gold_value
					}
					domicile = {
						change_provisions = {
							integer_range = {
								min = miniscule_provisions_value
								max = minor_provisions_value
							}
						}
					}
				}
			}
		}
		if = {
			limit = {
				scope:task_contract.var:num_of_corrupt_counties = 1
				scope:task_contract.var:control = 0
				scope:task_contract.var:support = 0
			}
			custom_tooltip = ep3_contract_event.0094_success
			scope:task_contract = {
				complete_task_contract = success_critical
			}
		}
		ep3_increase_peasant_control_effect = yes
		stress_impact = {
			compassionate = minor_stress_impact_gain
			calm = minor_stress_impact_gain
			just = minor_stress_impact_gain
			impatient = minor_stress_impact_loss
			wrathful = minor_stress_impact_loss
		}
		#AI should always try to complete the contract
		ai_chance = {
			base = 20
		}
	}

	#side with peasants
	option = {
		name = ep3_contract_event.0093.b
		every_courtier = {
			limit = {
				is_lowborn = yes
				NOT = {
					has_opinion_modifier = {
						modifier = sided_with_peasants_opinion
						target = root
					}
				}
			}
			custom = every_lowborn_follower
			add_opinion = {
				modifier = sided_with_peasants_opinion
				target = root
				years = 3
			}
		}
		if = {
			limit = {
				scope:task_contract.var:num_of_corrupt_counties = 1
				scope:task_contract.var:control = 0
				scope:task_contract.var:support = 0
			}
			custom_tooltip = ep3_contract_event.0094_fail
			show_as_tooltip = {
				scope:task_contract = {
					complete_task_contract = failure_standard
				}
			}
			trigger_event = {
				id = ep3_contract_event.0095
				delayed = yes
			}
		}
		ep3_increase_peasant_support_effect = yes
		stress_impact = {
			compassionate = minor_stress_impact_loss
			fickle = minor_stress_impact_loss
			just = minor_stress_impact_loss
			wrathful = minor_stress_impact_gain
		}
		#AI should always try to complete the contract
		ai_chance = {
			base = 0
		}
	}

	after = {
		ep3_peasant_leader_widget_clear_effect = yes
		#check if there are more corrupt counties to visit
		if = {
			limit = {
				scope:task_contract = {
					has_variable_list = corrupt_counties
					variable_list_size = {
						name = corrupt_counties
						value >= 1
					}
				}
			}
			#follow up event to keep going
			trigger_event = {
				id = ep3_contract_event.0094
				delayed = yes
			}
		}
		#else complete the contract
		else = {
			if = {
				limit = {
					scope:task_contract.var:control > scope:task_contract.var:support
					NAND = {
						scope:task_contract.var:control = 0
						scope:task_contract.var:support = 0
					}
				}
				custom_tooltip = ep3_contract_event.0094_success
				scope:task_contract = {
					if = {
						limit = {
							scope:task_contract.var:control = scope:task_contract.var:num_of_corrupt_counties
						}
						complete_task_contract = success_critical
					}
					else = {
						complete_task_contract = success_standard
					}
				}
			}
			else_if = {
				limit = {
					scope:task_contract.var:control <= scope:task_contract.var:support
					NAND = {
						scope:task_contract.var:control = 0
						scope:task_contract.var:support = 0
					}
				}
				custom_tooltip = ep3_contract_event.0094_fail
				show_as_tooltip = {
					scope:task_contract = {
						complete_task_contract = failure_standard
					}
				}
				trigger_event = {
					id = ep3_contract_event.0095
					delayed = yes
				}
			}
		}
	}
}

# increase control - keep going
ep3_contract_event.0094 = {
	type = character_event
	title = ep3_contract_event.0094.t
	desc = {
		desc = ep3_contract_event.0094.desc
		first_valid = {
			triggered_desc = {
				trigger = { scope:corruption_reason = flag:taxes }
				desc = ep3_contract_event.0094.desc_taxes
			}
			triggered_desc = {
				trigger = { scope:corruption_reason = flag:bandits }
				desc = ep3_contract_event.0094.desc_bandits
			}
			triggered_desc = {
				trigger = { scope:corruption_reason = flag:riots }
				desc = ep3_contract_event.0094.desc_riots
			}
			triggered_desc = {
				trigger = { scope:corruption_reason = flag:low_control }
				desc = ep3_contract_event.0094.desc_low_control
			}
		}
	}
	theme = landless_adventurer
	#task_contract_taker, you
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = {
				scope:task_contract.var:control <= scope:task_contract.var:support
				scope:corruption_reason = flag:taxes
			}
			animation = personality_rational
		}
		triggered_animation = {
			trigger = {
				scope:task_contract.var:control <= scope:task_contract.var:support
				scope:corruption_reason = flag:bandits
			}
			animation = worry
		}
		triggered_animation = {
			trigger = {
				scope:task_contract.var:control <= scope:task_contract.var:support
				scope:corruption_reason = flag:riots
			}
			animation = personality_honorable
		}
		triggered_animation = {
			trigger = {
				scope:task_contract.var:control <= scope:task_contract.var:support
				scope:corruption_reason = flag:low_control
			}
			animation = stunned
		}
		triggered_animation = {
			trigger = {
				scope:task_contract.var:control > scope:task_contract.var:support
				scope:corruption_reason = flag:taxes
			}
			animation = personality_greedy
		}
		triggered_animation = {
			trigger = {
				scope:task_contract.var:control > scope:task_contract.var:support
				scope:corruption_reason = flag:bandits
			}
			animation = schadenfreude
		}
		triggered_animation = {
			trigger = {
				scope:task_contract.var:control > scope:task_contract.var:support
				scope:corruption_reason = flag:riots
			}
			animation = eyeroll
		}
		triggered_animation = {
			trigger = {
				scope:task_contract.var:control > scope:task_contract.var:support
				scope:corruption_reason = flag:low_control
			}
			animation = boredom
		}
	}
	#marshal
	right_portrait = {
		character = scope:task_contract_councillor
		animation = debating
	}
	#marshal's liege
	lower_right_portrait = {
		character = scope:task_contract_councillor_liege
	}
	widget = {
		gui = "event_window_widget_peasant_leader"
		container = "custom_widgets_container"
	}

	immediate = {
		if = {
			limit = {
				NOT = { has_variable = contract_094_travel_fallback_true }
			}
			ep3_peasant_leader_widget_setup_effect = yes
			scope:task_contract = {
				#set a county from the corrupt counties list as the corrupt county to visit next
				random_in_list = {
					variable = corrupt_counties
					title_province = {
						save_scope_as = corrupt_province
					}
				}
				#update the destination variable for proper tooltips and descriptions in other UIs
				set_variable = {
					name = task_contract_destination
					value = scope:corrupt_province
				}
			}
			set_corruption_reason_effect = yes
		}
		else = {
			remove_variable = contract_094_travel_fallback_true
		}
	}

	#travel without camp
	option = {
		name = ep3_contract_event.0094.a
		hidden_effect = {
			current_travel_plan ?= {
				abort_travel_plan = yes
			}
			start_travel_plan = {
				destination = scope:corrupt_province
				on_arrival_event = ep3_contract_event.0093
				on_arrival_destinations = all_but_last
				on_travel_planner_cancel_on_action = ep3_contract_094_travel_fallback
				can_cancel_planning = no
			}
		}
		custom_tooltip = ep3_contract_event.0094.travel_without_domicile
		
		#AI should always try to complete the contract
		ai_chance = {
			base = 20
		}
	}

	# travel with camp - only if you traveled with it here
	option = {
		name = ep3_contract_event.0094.b
		trigger = {
			domicile.domicile_location = root.location
		}
		hidden_effect = {
			current_travel_plan ?= {
				abort_travel_plan = yes
			}
			start_travel_plan = {
				destination = scope:corrupt_province
				on_arrival_event = ep3_contract_event.0093
				on_arrival_destinations = all
				travel_with_domicile = yes
				return_trip = no
				can_cancel_planning = no
			}
		}
		custom_tooltip = ep3_contract_event.0094.travel_with_domicile
		custom_tooltip = ep3_contract_event.0001.with_domicile.tt
		
		#AI shouldn't move their camp in events
		ai_chance = {
			base = 0
		}
	}

	# I had enough, fail contract
	option = {
		name = ep3_contract_event.0094.c
		trigger = {
			scope:task_contract.var:control <= scope:task_contract.var:support
		}
		flavor = ep3_contract_event.0094_fail
		show_as_tooltip = {
			scope:task_contract = {
				complete_task_contract = failure_standard
			}
		}
		trigger_event = ep3_contract_event.0095
		stress_impact = {
			ambitious = major_stress_impact_gain
			lazy = minor_stress_impact_loss
		}
		#AI should always try to complete the contract
		ai_chance = {
			base = 0
		}
	}

	# I had enough, succeed contract
	option = {
		name = ep3_contract_event.0094.c
		trigger = {
			scope:task_contract.var:control > scope:task_contract.var:support
		}
		flavor = ep3_contract_event.0094_success
		scope:task_contract = {
			if = {
				limit = {
					scope:task_contract.var:control = scope:task_contract.var:num_of_corrupt_counties
				}
				complete_task_contract = success_critical
			}
			else = {
				complete_task_contract = success_standard
			}
		}
		return_home = yes
		stress_impact = {
			ambitious = minor_stress_impact_gain
			lazy = minor_stress_impact_loss
		}
		#AI should always try to complete the contract
		ai_chance = {
			base = 20
		}
	}

	after = {
		ep3_peasant_leader_widget_clear_effect = yes
	}
}

# increase control - follow up
ep3_contract_event.0095 = {
	type = character_event
	title = ep3_contract_event.0095.t
	desc = ep3_contract_event.0095.desc
	theme = landless_adventurer
	#task_contract_taker, you
	left_portrait = {
		character = root
		animation = schadenfreude
	}
	#marshal
	right_portrait = {
		character = scope:task_contract_councillor
		animation = rage
	}
	#marshal's liege
	lower_right_portrait = {
		character = scope:task_contract_councillor_liege
	}
	widget = {
		gui = "event_window_widget_peasant_leader"
		container = "custom_widgets_container"
	}
	cooldown = { days = 1 }

	immediate = {
		# transfer the list of supported counties from contract to root, as the contract will be destroyed after this event, so that you will have access to the ep3_laamp_peasant_war cb, even if you didn't choose war in this event
		scope:task_contract = {
			every_in_list = {
				variable = supported_counties
				root = {
					add_to_variable_list = {
						name = war_supported_counties_list
						target = prev
					}
				}
			}
			every_in_list = {
				variable = met_peasant_leaders
				root = {
					add_to_variable_list = {
						name = war_met_peasant_leaders_list
						target = prev
					}
				}
			}
		}
		scope:task_contract_taker = {
			ep3_peasant_leader_widget_setup_effect = yes
		}
	}

	#lead an independence peasant war
	option = {
		name = ep3_contract_event.0095.a
		#start a freedom war!
		start_war = {
			cb = ep3_laamp_peasant_war
			target = scope:task_contract_councillor_liege.top_liege
		}
		#try to capture the marshal, as they standing right next to you
		duel = {
			skills = { prowess intrigue }
			target = scope:task_contract_councillor
			25 = {
				desc = ep3_contract_event.0095.a_win
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
				}
				prisoner_of_war_capture_effect = {
					TARGET = scope:task_contract_councillor
					IMPRISONER = root
				}
				scope:task_contract_councillor_liege = {
					add_opinion = {
						modifier = fp3_wrongful_imprisonment_opinion
						opinion = -30
						target = root
					}
				}
			}
			25 = {
				desc = ep3_contract_event.0095.a_lose
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = 5
				}
				scope:task_contract_councillor = {
					add_opinion = {
						target = root
						modifier = attempted_imprisonment_opinion
					}
				}
			}
		}
		#fail the contract, obivously
		scope:task_contract = {
			complete_task_contract = failure_standard
		}
		return_home = yes
		stress_impact = {
			craven = minor_stress_impact_gain
			lazy = minor_stress_impact_gain
			brave = minor_stress_impact_loss
			compassionate = minor_stress_impact_loss
			arrogant = minor_stress_impact_loss
		}
		ai_chance = {
			base = 20

		}
	}

	# they are on their own, for now
	option = {
		name = ep3_contract_event.0095.b
		scope:task_contract = {
			every_in_list = {
				variable = supported_counties
				custom = laamp_peasant_revolt_every_county
				random_list = {
					1 = {
						add_county_modifier = small_investment_in_revolt_modifier
					}
					1 = {
						add_county_modifier = medium_investment_in_revolt_modifier
					}
					1 = {
						add_county_modifier = high_investment_in_revolt_modifier
					}
				}
			}
		}
		#this also fails the contract
		scope:task_contract = {
			complete_task_contract = failure_standard
		}
		return_home = yes
		stress_impact = {
			craven = minor_stress_impact_loss
			lazy = minor_stress_impact_loss
			brave = minor_stress_impact_gain
		}
		#AI should always try to complete the contract
		ai_chance = {
			base = 0
		}
	}

	# try to weasel out of it
	option = {
		name = ep3_contract_event.0095.c
		duel = {
			skills = { diplomacy intrigue }
			target = scope:task_contract_councillor
			1 = {
				desc = ep3_contract_event.0095.c_win
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
				}
				scope:task_contract = {
					complete_task_contract = success_standard
				}
			}
			25 = {
				desc = ep3_contract_event.0095.c_tie
				scope:task_contract = {
					invalidate_contract = yes
				}
			}
			25 = {
				desc = ep3_contract_event.0095.c_lose
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = 5
				}
				scope:task_contract = {
					complete_task_contract = failure_standard
				}
			}
		}
		return_home = yes
		stress_impact = {
			honest = minor_stress_impact_gain
			brave = minor_stress_impact_gain
			compassionate = minor_stress_impact_gain
			deceitful = minor_stress_impact_loss
			cynical = minor_stress_impact_loss
		}
		#AI should always try to complete the contract
		ai_chance = {
			base = 20
		}
	}

	after = {
		ep3_peasant_leader_widget_clear_effect = yes
	}
}

## Spymaster
#Contract to scheme find secrets - starting event
ep3_contract_event.0100 = {
	type = character_event
	title = ep3_contract_event.0100.t
	desc = ep3_contract_event.0100.desc
	theme = intrigue
	#task_contract_taker, you
	left_portrait = {
		character = root
		animation = stunned
	}
	#spymaster
	right_portrait = {
		character = scope:task_contract_councillor
		animation = scheme
	}
	#spymaster's liege
	lower_right_portrait = {
		character = scope:task_contract_councillor_liege
	}

	immediate = {
		set_contract_scopes_effect = yes
		set_council_scopes_effect = yes
	}

	#start scheme to find secrets
	option = {
		name = ep3_contract_event.0030.b
		begin_contract_scheme_with_agents_effect = {
			SCHEME_TYPE = laamp_help_find_secrets_scheme
			TARGET_TYPE = target_character
			TARGET_SCOPE = scope:task_contract_target
			TASK_CONTRACT = scope:task_contract
			# Success.
			AGENT_1 = agent_diplomat
			AGENT_2 = agent_shill
			AGENT_3 = agent_gabbler
			# Speed.
			AGENT_4 = agent_theologian
			# Secrecy.
			AGENT_5 = agent_justiciar
		}
		#AI should always try to complete the contract
		ai_chance = {
			base = 1
		}
	}

	#invalidate the contract
	option = {
		name = ep3_contract_event.0001.invalidate
		scope:task_contract = {
			invalidate_contract = yes
		}
		#AI should always try to complete the contract
		ai_chance = {
			base = 0
		}
	}
}

# Boost Legitimacy - intro
ep3_contract_event.0510 = {
	type = character_event
	title = ep3_contract_event.0510.t
	desc = ep3_contract_event.0510.desc
	theme = diplomacy
	override_background = {
		reference = alley_day
	}
	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		character = scope:peasant
		animation = debating
	}
	lower_right_portrait = {
		character = scope:task_contract_employer
	}
	
	immediate = {
		set_contract_scopes_effect = yes
		set_council_scopes_effect = yes
		create_character = {
			template = generic_peasant_character
			location = this.location
			faith = location.faith
			culture = location.culture
			random_traits = yes
			trait = peasant_leader
			save_scope_as = peasant
		}
		location = {
			save_scope_as = location
		}
	}

	#You attempt to debate the local
	option = {
		name = ep3_contract_event.0510.a

		duel = {
			skills = { diplomacy learning }
			target = scope:peasant
			
			50 = { #You win the debate
				desc = ep3_contract_event.0510.a.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 2.5
					min = -49
				}
				min = 5
				scope:task_contract = {
					complete_task_contract = success_standard
				}
				add_character_flag = contract_success_flag
				trigger_event = ep3_contract_event.0520
			}
			40 = { #You are unconvincing
				desc = ep3_contract_event.0510.a.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -2.5
					min = -49
				}
				min = 5
				scope:task_contract = {
					complete_task_contract = failure_standard
				}
				add_character_flag = contract_failure_flag
				trigger_event = ep3_contract_event.0520
			}
			10 = { #You actively damage your employer in the eyes of his subjects
				desc = ep3_contract_event.0510.a.critfailure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -2.5
					min = -49
				}
				min = 1
				scope:task_contract = {
					complete_task_contract = failure_critical
				}
				add_character_flag = contract_crit_failure_flag
				trigger_event = ep3_contract_event.0520
			}
		}
		stress_impact = {
			honest = minor_stress_impact_loss
			arrogant = minor_stress_impact_loss
			compassionate = minor_stress_impact_loss
			sadistic = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			modifier = {
				add = 100
				OR = {
					highest_skill = diplomacy
					learning > scope:peasant.learning
				}
			}
		}
	}

	#Threaten the local
	option = {
		name = ep3_contract_event.0510.b
		duel = {
			skills = { diplomacy prowess }
			target = scope:peasant
			
			30 = { #You win the 'debate'
				desc = ep3_contract_event.0510.b.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 2.5
					min = -49
				}
				min = 3
				scope:task_contract = {
					complete_task_contract = success_standard
				}
				add_character_flag = contract_success_flag
				trigger_event = ep3_contract_event.0520
			}
			50 = { #You are unconvincing
				desc = ep3_contract_event.0510.b.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -2.5
					min = -49
				}
				min = 5
				scope:task_contract = {
					complete_task_contract = failure_standard
				}
				add_character_flag = contract_failure_flag
				trigger_event = ep3_contract_event.0520
			}
			20 = { #You actively damage your employer in the eyes of his subjects
				desc = ep3_contract_event.0510.b.critfailure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -2.5
					min = -49
				}
				min = 1
				scope:peasant = {
					create_faction = {
						type = peasant_faction
						target = scope:task_contract_employer
					}
				}
				scope:task_contract = {
					complete_task_contract = failure_critical
				}
				add_character_flag = contract_crit_failure_flag
				trigger_event = ep3_contract_event.0520
			}
		}
		stress_impact = {
			honest = minor_stress_impact_gain
			compassionate = minor_stress_impact_gain
			sadistic = major_stress_impact_loss
		}
		ai_chance = {
			base = 10
			modifier = {
				add = 100
				highest_skill_including_prowess = prowess
			}
		}
	}

	#Pay him off to support your cause
	option = {
		name = ep3_contract_event.0510.c

		pay_short_term_gold = {
			target = scope:peasant
			gold = minor_gold_value
		}

		random_list = {
			75 = {
				modifier = {
					add = 15
					scope:peasant = {
						OR = {
							has_trait = greedy
							has_trait = arbitrary
						}
					}
				}
				scope:task_contract = {
					complete_task_contract = success_standard
				}
				add_character_flag = contract_success_flag
				trigger_event = ep3_contract_event.0520
			}
			25 = {
				modifier = {
					add = 25
					scope:peasant = {
						OR = {
							has_trait = stubborn
							has_trait = ambitious
						}
					}
				}
				scope:task_contract = {
					complete_task_contract = failure_standard
				}
				add_character_flag = contract_failure_flag
				trigger_event = ep3_contract_event.0520
			}
		}


		stress_impact = {
			gregarious = minor_stress_impact_loss
			zealous = minor_stress_impact_loss
			compassionate = minor_stress_impact_loss
			shy = minor_stress_impact_gain
			cynical = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			modifier = {
				add = 100
				gold > 100
			}
		}
	}

	#invalidate the contract
	option = {
		name = ep3_contract_event.0001.invalidate
		scope:task_contract = {
			invalidate_contract = yes
		}
		#AI should always try to complete the contract
		ai_chance = {
			base = 0
		}
	}
}

# Boost Legitimacy - resolution
ep3_contract_event.0520 = {
	type = character_event
	title = {
		first_valid = {
			triggered_desc = {
				trigger = { has_character_flag = contract_success_flag }
				desc = ep3_contract_event.0520.t.success
			}
			triggered_desc = {
				trigger = { has_character_flag = contract_failure_flag }
				desc = ep3_contract_event.0520.t.failure
			}
			triggered_desc = {
				trigger = { has_character_flag = contract_crit_failure_flag }
				desc = ep3_contract_event.0520.t.critfailure
			}
		}
	}
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { has_character_flag = contract_success_flag }
				desc = ep3_contract_event.0520.desc.success
			}
			triggered_desc = {
				trigger = { has_character_flag = contract_failure_flag }
				desc = ep3_contract_event.0520.desc.failure
			}
			triggered_desc = {
				trigger = { has_character_flag = contract_crit_failure_flag }
				desc = ep3_contract_event.0520.desc.critfailure
			}
		}
	}
	theme = diplomacy
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = {
				has_character_flag = contract_success_flag
			}
			animation = personality_honorable
		}
		animation = stress
	}
	right_portrait = {
		character = scope:task_contract_employer
		triggered_animation = {
			trigger = {
				has_character_flag = contract_success_flag
			}
			animation = ecstasy
		}
		animation = anger
	}
	
	immediate = {
		set_contract_scopes_effect = yes
		set_council_scopes_effect = yes
		location = {
			save_scope_as = location
		}
		show_as_tooltip = {
			if = {
				limit = {
					has_character_flag = contract_success_flag
				}
				scope:task_contract = {
					complete_task_contract = success_standard
				}
			}
			else_if = {
				limit = {
					has_character_flag = contract_failure_flag
				}
				scope:task_contract = {
					complete_task_contract = failure_standard
				}
			}
			else = {
				scope:task_contract = {
					complete_task_contract = failure_critical
				}
			}
		}
	}

	option = {
		name = ep3_contract_event.0520.a

		trigger = {
			has_character_flag = contract_success_flag
		}

		stress_impact = {
			base = miniscule_stress_impact_loss
		}
		ai_chance = {
			base = 10
		}
	}

	option = {
		name = ep3_contract_event.0520.b

		trigger = {
			NOT = {
				has_character_flag = contract_success_flag
			}
		}

		stress_impact = {
			base = miniscule_stress_impact_gain
		}
		ai_chance = {
			base = 10
		}
	}

	after = {
		remove_character_flag = contract_crit_success_flag
		remove_character_flag = contract_success_flag
		remove_character_flag = contract_failure_flag
		remove_character_flag = contract_crit_failure_flag
	}
}

# Turbulent Priest - intro
ep3_contract_event.0550 = {
	type = character_event
	title = ep3_contract_event.0550.t
	desc = ep3_contract_event.0550.desc
	theme = martial
	override_background = {
		reference = alley_night
	}
	left_portrait = {
		character = root
		animation = lantern
	}
	right_portrait = {
		character = scope:messenger
		outfit_tags = { travel_cloak }
		animation = scheme
		hide_info = yes
	}
	lower_right_portrait = {
		character = scope:task_contract_employer
	}

	immediate = {
		set_contract_scopes_effect = yes
		set_council_scopes_effect = yes
		location = {
			save_scope_as = location
		}
		scope:task_contract_employer = {
			random_councillor = { #Has a councillor who they hate
				limit = {
					is_ai = yes
					reverse_opinion = {
						target = scope:task_contract_employer
						value <= high_negative_opinion
					}
				}
				save_scope_as = councillor
			}
		}
		if = {
			limit = {
				any_pool_character = {
					province = root.location
					is_physically_able_ai_adult = yes
					has_no_particular_noble_roots_trigger = yes
					age >= 25
					age <= 75
				}
			}
			random_pool_character = {
				province = root.location
				limit = {
					is_physically_able_ai_adult = yes
					has_no_particular_noble_roots_trigger = yes
					age >= 25
					age <= 75
				}
				save_scope_as = messenger
			}
		}
		else = {
			create_character = {
				template = generic_peasant_character
				location = this.location
				faith = location.faith
				culture = location.culture
				random_traits = yes
				save_scope_as = messenger
			}
		}
	}

	#Open the letter
	option = {
		name = ep3_contract_event.0550.a

		custom_tooltip = ep3_contract_event.0550.a.tt

		trigger_event = ep3_contract_event.0555

		stress_impact = {
			honest = miniscule_stress_impact_gain
			deceitful = miniscule_stress_impact_loss
			craven = miniscule_stress_impact_gain
			brave = miniscule_stress_impact_loss
		}

		ai_chance = {
			base = 100
		}
	}

	#invalidate the contract
	option = {
		name = ep3_contract_event.0001.invalidate
		scope:task_contract = {
			invalidate_contract = yes
		}
		#AI should always try to complete the contract
		ai_chance = {
			base = 0
		}
	}
}

# Turbulent Priest - Letter
ep3_contract_event.0555 = {
	type = character_event
	window = anonymous_letter_event
	title = debug.0002.t
	desc = ep3_contract_event.0555.desc
	theme = martial

	#Okie doke
	option = {
		name = ep3_contract_event.0555.a

		trigger_event = {
			id = ep3_contract_event.0560
			days = 1
		}

		stress_impact = {
			honest = miniscule_stress_impact_gain
			deceitful = miniscule_stress_impact_loss
			craven = miniscule_stress_impact_gain
			brave = miniscule_stress_impact_loss
		}

		ai_chance = {
			base = 100
		}
	}
}

# Turbulent Priest - decision
ep3_contract_event.0560 = {
	type = character_event
	title = ep3_contract_event.0560.t
	desc = ep3_contract_event.0560.desc
	theme = martial
	override_background = {
		reference = alley_night
	}
	left_portrait = {
		character = root
		animation = hunting_knife_start
	}
	right_portrait = {
		character = scope:councillor
		animation = drink_goblet
	}
	
	immediate = {
		set_contract_scopes_effect = yes
		location = {
			save_scope_as = location
		}
		scope:task_contract_employer = {
			random_sub_realm_barony = { #Save a place for the exile to go
				limit = {
					this != root.capital_province
				}
				save_scope_as = exile_barony
			}
		}
	}

	option = { #Slaughter them
		name = ep3_contract_event.0560.a

		duel = {
			skills = { prowess martial }
			target = scope:councillor
			
			30 = { #You break in and kill everyone inside
				desc = ep3_contract_event.0560.a.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 2.5
					min = -49
				}
				min = 3
				add_character_flag = contract_success_flag
				custom_tooltip = ep3_contract_event.0560.contractsuccess
				trigger_event = {
					id = ep3_contract_event.0565
					days = { 1 2 }
				}
				scope:councillor = { death = { death_reason = death_murder } }
			}
			50 = { #You break in, kill the target, but suffer wounds
				desc = ep3_contract_event.0560.a.neutral
				compare_modifier = {
					value = scope:duel_value
					multiplier = -2.5
					min = -49
				}
				min = 5
				increase_wounds_no_death_effect = { REASON = fight }
				add_character_flag = contract_success_flag
				custom_tooltip = ep3_contract_event.0560.contractsuccess
				trigger_event = {
					id = ep3_contract_event.0565
					days = { 1 2 }
				}
				scope:councillor = { death = { killer = root death_reason = death_duel } }
			}
			30 = { #You fail to even kill the target
				desc = ep3_contract_event.0560.a.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -2.5
					min = -49
				}
				min = 3
				increase_wounds_no_death_effect = { REASON = fight }
				add_character_flag = contract_crit_failure_flag
				custom_tooltip = ep3_contract_event.0560.contractfailure
				trigger_event = {
					id = ep3_contract_event.0565
					days = { 1 2 }
				}
			}
			10 = { #You are killed!
				desc = ep3_contract_event.0560.a.critfailure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -2.5
					min = -49
				}
				min = 1
				death = { killer = scope:councillor death_reason = death_duel }
			}
		}

		stress_impact = {
			brave = miniscule_stress_impact_loss
			craven = minor_stress_impact_gain
			impatient = miniscule_stress_impact_loss
			patient = minor_stress_impact_gain
		}

		ai_chance = {
			base = 10
			modifier = {
				add = 100
				highest_skill_including_prowess = prowess
			}
		}
	}

	option = { #Knife him in the loo
		name = ep3_contract_event.0560.b

		duel = {
			skills = { prowess intrigue }
			target = scope:councillor
			
			40 = { #It works perfectly
				desc = ep3_contract_event.0560.b.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 2.5
					min = -49
				}
				min = 4
				add_character_flag = contract_success_flag
				custom_tooltip = ep3_contract_event.0560.contractcritsuccess
				trigger_event = {
					id = ep3_contract_event.0565
					days = { 1 2 }
				}
				scope:councillor = { death = { death_reason = death_murder } }
			}
			40 = { #There is a scuffle, and people notice as you escape
				desc = ep3_contract_event.0560.b.neutral
				compare_modifier = {
					value = scope:duel_value
					multiplier = -2.5
					min = -49
				}
				min = 4
				add_character_flag = contract_success_flag
				custom_tooltip = ep3_contract_event.0560.contractsuccess
				trigger_event = {
					id = ep3_contract_event.0565
					days = { 1 2 }
				}
				scope:councillor = { death = { killer = root death_reason = death_murder_known } }
			}
			20 = { #He doesn't even go to the toilet
				desc = ep3_contract_event.0560.b.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -2.5
					min = -49
				}
				min = 2
				increase_wounds_no_death_effect = { REASON = fight }
				add_character_flag = contract_failure_flag
				custom_tooltip = ep3_contract_event.0560.contractcritfailure
				trigger_event = {
					id = ep3_contract_event.0565
					days = { 1 2 }
				}
			}
		}

		stress_impact = {
			sadistic = minor_stress_impact_loss
			compassionate = medium_stress_impact_gain
			impatient = minor_stress_impact_gain
			patient = miniscule_stress_impact_loss
		}

		ai_chance = {
			base = 10
			modifier = {
				add = 50
				highest_skill = intrigue
			}
		}
	}

	option = { #Poison his drink
		name = ep3_contract_event.0560.c

		duel = {
			skill = intrigue
			value = very_high_skill_rating
			
			20 = { #It works perfectly
				desc = ep3_contract_event.0560.c.critsuccess
				compare_modifier = {
					value = scope:duel_value
					multiplier = 2.5
					min = -49
				}
				min = 2
				add_character_flag = contract_crit_success_flag
				custom_tooltip = ep3_contract_event.0560.contractcritsuccess
				trigger_event = {
					id = ep3_contract_event.0565
					days = { 1 2 }
				}
			}
			50 = { #By the time they realise it was you, he is already dead
				desc = ep3_contract_event.0560.c.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = -2.5
					min = -49
				}
				min = 5
				add_character_flag = contract_success_flag
				custom_tooltip = ep3_contract_event.0560.contractsuccess
				trigger_event = {
					id = ep3_contract_event.0565
					days = { 1 2 }
				}
				scope:councillor = { death = { killer = root death_reason = death_poison } }
			}
			50 = { #It merely makes him sick
				desc = ep3_contract_event.0560.c.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -2.5
					min = -49
				}
				min = 5
				add_character_flag = contract_failure_flag
				custom_tooltip = ep3_contract_event.0560.contractfailure
				trigger_event = {
					id = ep3_contract_event.0565
					days = { 1 2 }
				}
				scope:councillor = { contract_disease_effect = { DISEASE = ill TREATMENT_EVENT = no } }
			}
			20 = { #He sees you spiking the drink
				desc = ep3_contract_event.0560.c.critfailure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -2.5
					min = -49
				}
				min = 2
				add_character_flag = contract_crit_failure_flag
				custom_tooltip = ep3_contract_event.0560.contractcritfailure
				trigger_event = {
					id = ep3_contract_event.0565
					days = { 1 2 }
				}
			}
		}

		stress_impact = {
			brave = minor_stress_impact_gain
			craven = miniscule_stress_impact_loss
			deceitful = miniscule_stress_impact_loss
			honest = minor_stress_impact_gain
		}

		ai_chance = {
			base = 10
			modifier = {
				add = 100
				highest_skill = intrigue
			}
		}
	}

	option = { #Lady Boyle 'em
		name = ep3_contract_event.0560.d

		duel = {
			skills = { intrigue learning }
			target = scope:councillor
			
			25 = { #It works perfectly
				desc = ep3_contract_event.0560.d.critsuccess
				compare_modifier = {
					value = scope:duel_value
					multiplier = 2.5
					min = -49
				}
				min = 2
				add_character_flag = contract_crit_success_flag
				custom_tooltip = ep3_contract_event.0560.contractcritsuccess
				scope:task_contract_employer = {
					fire_councillor = scope:councillor
				}
				scope:councillor = { 
					if = {
						limit = {
							is_landed = no
						}
						banish = yes
					}
					else = {
						banish = yes
						create_title_and_vassal_change = {
							type = revoked
							save_scope_as = change
							add_claim_on_loss = yes
						}
						create_landless_adventurer_title_effect = {
							REASON = flag:exile
							FLAVOR_CHAR = root
						}
					}
				}
				trigger_event = {
					id = ep3_contract_event.0565
					days = { 1 2 }
				}
			}
			50 = { #You have to knock him out before abduction
				desc = ep3_contract_event.0560.d.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = -2.5
					min = -49
				}
				min = 5
				add_character_flag = contract_success_flag
				custom_tooltip = ep3_contract_event.0560.contractsuccess
				trigger_event = {
					id = ep3_contract_event.0565
					days = { 1 2 }
				}
				scope:task_contract_employer = {
					fire_councillor = scope:councillor
				}
				scope:councillor = { 
					increase_wounds_no_death_effect = { REASON = fight } 
					if = {
						limit = {
							is_landed = no
						}
						banish = yes
					}
					else = {
						banish = yes
						create_title_and_vassal_change = {
							type = revoked
							save_scope_as = change
							add_claim_on_loss = yes
						}
						create_landless_adventurer_title_effect = {
							REASON = flag:exile
							FLAVOR_CHAR = root
						}
					}
				}
			}
			35 = { #He escapes from your clutches
				desc = ep3_contract_event.0560.d.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -2.5
					min = -49
				}
				min = 3
				add_character_flag = contract_crit_failure_flag
				custom_tooltip = ep3_contract_event.0560.contractcritfailure
				trigger_event = {
					id = ep3_contract_event.0565
					days = { 1 2 }
				}
			}
		}

		stress_impact = {
			brave = minor_stress_impact_gain
			craven = miniscule_stress_impact_loss
			sadistic = medium_stress_impact_gain
			compassionate = minor_stress_impact_loss
		}

		ai_chance = {
			base = 10
			modifier = {
				add = 25
				highest_skill = intrigue
			}
			modifier = {
				add = 100
				highest_skill = learning
			}
		}
	}
}

# Turbulent Priest - resolution
ep3_contract_event.0565 = {
	type = character_event
	title = {
		first_valid = {
			triggered_desc = {
				trigger = { has_character_flag = contract_crit_success_flag }
				desc = ep3_contract_event.0565.t.critsuccess
			}
			triggered_desc = {
				trigger = { has_character_flag = contract_success_flag }
				desc = ep3_contract_event.0565.t.success
			}
			triggered_desc = {
				trigger = { has_character_flag = contract_failure_flag }
				desc = ep3_contract_event.0565.t.failure
			}
			triggered_desc = {
				trigger = { has_character_flag = contract_crit_failure_flag }
				desc = ep3_contract_event.0565.t.critfailure
			}
		}
	}
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { has_character_flag = contract_crit_success_flag }
				desc = ep3_contract_event.0565.desc.critsuccess
			}
			triggered_desc = {
				trigger = { has_character_flag = contract_success_flag }
				desc = ep3_contract_event.0565.desc.success
			}
			triggered_desc = {
				trigger = { has_character_flag = contract_failure_flag }
				desc = ep3_contract_event.0565.desc.failure
			}
			triggered_desc = {
				trigger = { has_character_flag = contract_crit_failure_flag }
				desc = ep3_contract_event.0565.desc.critfailure
			}
		}
	}
	theme = martial
	override_background = {
		reference = ep2_travel_bridge
	}
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = {
				OR = {
					has_character_flag = contract_success_flag
					has_character_flag = contract_crit_success_flag
				}
			}
			animation = steward
		}
		outfit_tags = { nightgown }
		animation = stress
	}
	right_portrait = {
		trigger = {
			OR = {
				has_character_flag = contract_success_flag
				has_character_flag = contract_crit_success_flag
			}
		}
		character = scope:messenger
		animation = jockey_idle
		outfit_tags = { travel_cloak }
		hide_info = yes
		camera = camera_event_horse_right
	}
	lower_center_portrait = {
		character = scope:councillor
	}

	immediate = {
		set_contract_scopes_effect = yes
		if = {
			limit = {
				any_pool_character = {
					province = root.location
					is_physically_able_ai_adult = yes
					has_no_particular_noble_roots_trigger = yes
					age >= 25
					age <= 75
				}
			}
			random_pool_character = {
				province = root.location
				limit = {
					is_physically_able_ai_adult = yes
					has_no_particular_noble_roots_trigger = yes
					age >= 25
					age <= 75
				}
				save_scope_as = messenger
			}
		}
		else = {
			create_character = {
				template = generic_peasant_character
				location = this.location
				faith = location.faith
				culture = location.culture
				random_traits = yes
				save_scope_as = messenger
			}
		}
		if = {
			limit = {
				has_character_flag = contract_crit_success_flag
			}
			scope:task_contract = {
				complete_task_contract = success_critical
			}
		}
		else_if = {
			limit = {
				has_character_flag = contract_success_flag
			}
			scope:task_contract = {
				complete_task_contract = success_standard
			}
		}
		else_if = {
			limit = {
				has_character_flag = contract_failure_flag
			}
			scope:task_contract = {
				complete_task_contract = failure_standard
			}
		}
		else = {
			scope:task_contract = {
				complete_task_contract = failure_critical
			}
		}
	}

	option = {
		name = ep3_contract_event.0565.a

		trigger = {
			OR = {
				has_character_flag = contract_crit_success_flag
				has_character_flag = contract_success_flag
			}
		}

		stress_impact = {
			base = miniscule_stress_impact_loss
		}
		ai_chance = {
			base = 10
		}
	}

	option = {
		name = ep3_contract_event.0565.b

		trigger = {
			NOR = {
				has_character_flag = contract_crit_success_flag
				has_character_flag = contract_success_flag
			}
		}

		stress_impact = {
			base = miniscule_stress_impact_gain
		}
		ai_chance = {
			base = 10
		}
	}

	after = {
		remove_character_flag = contract_crit_success_flag
		remove_character_flag = contract_success_flag
		remove_character_flag = contract_failure_flag
		remove_character_flag = contract_crit_failure_flag
	}
}

# Rescue Wanderer - Intro
ep3_contract_event.0570 = {
	type = character_event
	title = ep3_contract_event.0570.t
	desc = ep3_contract_event.0570.desc
	theme = intrigue
	override_background = {
		reference = dungeon
	}
	left_portrait = {
		character = root
		animation = inspect_weapon
	}
	right_portrait = {
		character = scope:task_contract_employer
		animation = prisondungeon
	}
	lower_right_portrait = {
		character = scope:prisonguard
	}
	
	immediate = {
		set_contract_scopes_effect = yes
		save_scope_as = root_for_loc
		create_character = {
			template = mercenary
			location = this.location
			faith = location.faith
			culture = location.culture
			gender_female_chance = root_soldier_female_chance
			random_traits = yes
			save_scope_as = prisonguard
		}
		location = {
			save_scope_as = location
		}

		save_scope_value_as = {
			name = lockpick_range
			value = {
				integer_range = {
					min = 1
					max = 10
				}
			}
		}
	}

	#Duel the guard to get them out
	option = {
		name = ep3_contract_event.0570.a

		trigger = {
			can_start_single_combat_trigger = yes
		}

		add_internal_flag = dangerous

		custom_tooltip = ep3_contract_event.0570.a.tt

		configure_start_single_combat_effect = {
			SC_INITIATOR = root
			SC_ATTACKER = root
			SC_DEFENDER = scope:prisonguard
			FATALITY = always
			FIXED = no
			LOCALE = terrain_scope
			OUTPUT_EVENT = ep3_contract_event.0571
			INVALIDATION_EVENT = single_combat.1006
		}

		stress_impact = {
			brave = minor_stress_impact_loss
			craven = minor_stress_impact_gain
			compassionate = minor_stress_impact_gain
			sadistic = minor_stress_impact_loss
		}

		ai_chance = {
			base = 10
			modifier = {
				add = 50
				highest_skill_including_prowess = prowess
			}
		}
	}

	#Make a distraction
	option = {
		name = ep3_contract_event.0570.b

		duel = {
			skill = intrigue
			value = decent_skill_rating
			
			50 = { #The distraction works
				desc = ep3_contract_event.0570.b.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 2.5
					min = -49
				}
				min = 5
				custom_tooltip = ep3_contract_event.0560.contractsuccess
				add_character_flag = contract_success_flag
				trigger_event = {
					id = ep3_contract_event.0575
					days = 1
				}
			}
			50 = { #It doesn't work and you have to escape
				desc = ep3_contract_event.0570.b.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -2.5
					min = -49
				}
				min = 5
				custom_tooltip = ep3_contract_event.0560.contractfailure
				add_character_flag = contract_failure_flag
				random = {
					chance = 30
					send_interface_toast = {
						type = event_toast_effect_bad
						title = ep3_contract_event.0570.b.failure.tt
						desc = ep3_contract_event.0570.b.failure.tt
						left_icon = root
						right_icon = scope:prisonguard
						increase_wounds_no_death_effect = { REASON = fight }
					}
				}
				trigger_event = {
					id = ep3_contract_event.0575
					days = 1
				}
			}
		}
		stress_impact = {
			deceitful = miniscule_stress_impact_loss
			honest = miniscule_stress_impact_gain
		}
		ai_chance = {
			base = 10
			modifier = {
				add = 100
				highest_skill = intrigue
			}
		}
	}

	#Try to pick the lock
	option = {
		name = ep3_contract_event.0570.c

		random_list = {
			35 = {
				modifier = {
					add = 20
					has_trait = gallowsbait
				}
				modifier = {
					add = 20
					has_trait_xp = {
						trait = gallowsbait
						track = thief
						value >= 25
					}
				}
				modifier = {
					add = 20
					has_trait_xp = {
						trait = gallowsbait
						track = thief
						value >= 75
					}
				}
				add_character_flag = contract_success_flag
				custom_tooltip = ep3_contract_event.0560.contractsuccess
				trigger_event = {
					id = ep3_contract_event.0575
					days = 1
				}
			}
			65 = {
				modifier = {
					add = scope:lockpick_range
				}
				add_character_flag = contract_failure_flag
				custom_tooltip = ep3_contract_event.0560.contractfailure
				trigger_event = {
					id = ep3_contract_event.0575
					days = 1
				}
			}
		}

		stress_impact = {
			patient = minor_stress_impact_loss
			impatient = medium_stress_impact_loss
		}

		ai_chance = {
			base = 25
		}
	}

	#invalidate the contract
	option = {
		name = ep3_contract_event.0001.invalidate
		scope:task_contract = {
			invalidate_contract = yes
		}
		#AI should always try to complete the contract
		ai_chance = {
			base = 0
		}
	}
}

#Add relevant flags
ep3_contract_event.0571 = {
	hidden = yes
	immediate = {
		add_character_flag = contract_duel_success_flag
		add_character_flag = contract_success_flag
		trigger_event = {
			id = ep3_contract_event.0575
			days = 1
		}
	}
}

# Rescue Wanderer - resolution
ep3_contract_event.0575 = {
	type = character_event
	title = {
		first_valid = {
			triggered_desc = {
				trigger = { has_character_flag = contract_success_flag }
				desc = ep3_contract_event.0575.t.success
			}
			triggered_desc = {
				trigger = { has_character_flag = contract_failure_flag }
				desc = ep3_contract_event.0575.t.failure
			}
		}
	}
	desc = {
		triggered_desc = {
			trigger = { has_character_flag = contract_duel_success_flag }
			desc = ep3_contract_event.0575.desc.duel
		}
		first_valid = {
			triggered_desc = {
				trigger = { has_character_flag = contract_success_flag }
				desc = ep3_contract_event.0575.desc.success
			}
			triggered_desc = {
				trigger = { has_character_flag = contract_failure_flag }
				desc = ep3_contract_event.0575.desc.failure
			}
		}
	}
	theme = intrigue
	override_background = {
		reference = alley_day
	}
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = {
				NOT = {
					has_character_flag = contract_failure_flag
				}
			}
			animation = personality_honorable
		}
		animation = stress
	}
	right_portrait = {
		trigger = {
			root = {
				has_character_flag = contract_success_flag
			}
		}
		character = scope:task_contract_employer
		animation = ecstasy
	}
	artifact = {
		trigger = { exists = scope:newly_created_artifact }
		target = scope:newly_created_artifact
		position = lower_center_portrait
	}

	immediate = {
		set_contract_scopes_effect = yes
		hidden_effect = {
			scope:task_contract_employer.primary_title = {
				save_scope_as = title
			}
			destroy_title = scope:title
		}
		add_courtier = scope:task_contract_employer
		if = {
			limit = {
				has_character_flag = contract_failure_flag
			}
			scope:task_contract = {
				complete_task_contract = failure_standard
			}
		}
		else = {
			scope:task_contract = {
				complete_task_contract = success_standard
			}
		}
		if = {
			limit = {
				has_character_flag = contract_duel_success_flag
			}
			add_gold = { 15 40 }
			hidden_effect = {
				random_dummy_gender_effect = yes
				create_artifact_brooch_effect = {
					OWNER = scope:dummy_gender
					SMITH = scope:dummy_gender
				}
				scope:newly_created_artifact = {
					add_artifact_modifier = artifact_negate_prowess_penalty_add_3_modifier
					add_artifact_modifier = artifact_monthly_prestige_2_modifier
					add_artifact_modifier = artifact_dynasty_opinion_1_modifier
					set_artifact_rarity = masterwork
					set_artifact_name = ep3_pilfered_brooch
					add_artifact_history = {
						type = stolen
						actor = scope:prisonguard
						recipient = root
					}
				}
			}
		}		
	}

	option = {
		name = ep3_contract_event.0575.a

		trigger = {
			NOT = {
				has_character_flag = contract_failure_flag
			}
		}

		stress_impact = {
			base = miniscule_stress_impact_loss
		}
		ai_chance = {
			base = 10
		}
	}

	option = {
		name = ep3_contract_event.0575.b

		trigger = {
			has_character_flag = contract_failure_flag
		}

		ai_chance = {
			base = 10
		}
	}

	after = {
		remove_character_flag = contract_success_flag
		remove_character_flag = contract_failure_flag
		remove_character_flag = contract_duel_success_flag
	}
}

# Find Secret - Intro
ep3_contract_event.0580 = {
	type = character_event
	title = ep3_contract_event.0580.t
	desc = ep3_contract_event.0580.desc
	theme = intrigue
	override_background = {
		reference = temple
	}
	left_portrait = {
		character = root
		animation = eavesdrop
	}
	right_portrait = {
		character = scope:secret_haver
		animation = paranoia
	}
	lower_center_portrait = {
		character = scope:task_contract_employer
	}
	
	immediate = {
		set_contract_scopes_effect = yes
		scope:task_contract_employer = {
			if = {
				limit = {
					any_vassal = {
						any_secret = {
							count > 0
							NOT = { is_known_by = scope:task_contract_employer }
						}
					}
				}
				random_vassal = {
					limit = {
						any_secret = {
							count > 0
							NOT = { is_known_by = scope:task_contract_employer }
						}
					}
					save_scope_as = secret_haver
					random_secret = {
						limit = {
							NOT = { is_known_by = scope:task_contract_employer }
						}
						save_scope_as = secret
					}
				}
			}
			else_if = {
				limit = {
					any_courtier_or_guest = {
						any_secret = {
							count > 0
							NOT = { is_known_by = scope:task_contract_employer }
						}
					}
				}
				random_courtier_or_guest = {
					limit = {
						any_secret = {
							count > 0
							NOT = { is_known_by = scope:task_contract_employer }
						}
					}
					save_scope_as = secret_haver
					random_secret = {
						limit = {
							NOT = { is_known_by = scope:task_contract_employer }
						}
						save_scope_as = secret
					}
				}
			}
			else = {
				random_courtier_or_guest = {
					limit = {
						is_available_adult = yes
					}
					save_scope_as = secret_haver
					give_random_likely_secret_effect = yes
					random_secret = {
						limit = {
							NOT = { is_known_by = scope:task_contract_employer }
						}
						save_scope_as = secret
					}
				}
			}
			if = {
				limit = {
					NOT = {
						exists = scope:secret_haver
					}
				}
				create_character = {
					employer = scope:task_contract_employer
					template = pool_repopulate_stewardship
					faith = scope:task_contract_employer.faith
					culture = scope:task_contract_employer.culture
					save_scope_as = secret_haver
				}
				scope:secret_haver = {
					give_random_likely_secret_effect = yes
					random_secret = {
						save_scope_as = secret
					}
				}
			}
		}
	}

	#Investigate
	option = {
		name = ep3_contract_event.0580.a

		duel = {
			skill = intrigue
			value = decent_skill_rating
			
			50 = { #You learn their secret
				desc = ep3_contract_event.0580.a.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 2.5
					min = -49
				}
				min = 5
				custom_tooltip = ep3_contract_event.0560.contractsuccess
				add_character_flag = contract_success_flag
				scope:secret = {
					reveal_to_without_events_effect = {
						CHARACTER = root
					}
				}
				trigger_event = {
					id = ep3_contract_event.0585
					days = 1
				}
			}
			50 = { #Turns out they don't have one...?
				desc = ep3_contract_event.0580.a.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -2.5
					min = -49
				}
				min = 5
				custom_tooltip = ep3_contract_event.0560.contractfailure
				add_character_flag = contract_failure_flag
				trigger_event = {
					id = ep3_contract_event.0585
					days = 1
				}
			}
		}

		stress_impact = {
			patient = miniscule_stress_impact_loss
			impatient = minor_stress_impact_gain
		}

		ai_chance = {
			base = 10
			modifier = {
				add = 20
				highest_skill = intrigue
				intrigue >= decent_skill_rating
			}
			modifier = {
				add = 70
				highest_skill = intrigue
				intrigue >= 16
			}
		}
	}

	#Try to lie about it
	option = {
		name = ep3_contract_event.0580.b

		duel = {
			skills = { diplomacy intrigue }
			target = scope:task_contract_employer
			
			50 = { #Your lie works
				desc = ep3_contract_event.0580.b.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 2.5
					min = -49
				}
				min = 5
				custom_tooltip = ep3_contract_event.0560.contractsuccess
				add_character_flag = contract_success_flag
				add_character_flag = lied_about_secret_flag
				trigger_event = {
					id = ep3_contract_event.0585
					days = 1
				}
			}
			50 = { #They know you're lying
				desc = ep3_contract_event.0580.b.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -2.5
					min = -49
				}
				min = 5
				custom_tooltip = ep3_contract_event.0560.contractfailure
				add_character_flag = contract_failure_flag
				trigger_event = {
					id = ep3_contract_event.0585
					days = 1
				}
			}
		}

		stress_impact = {
			deceitful = minor_stress_impact_loss
			honest = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			modifier = {
				add = 90
				diplomacy >= scope:task_contract_employer.diplomacy
				intrigue >= scope:task_contract_employer.intrigue
			}
		}
	}

	#Threaten them
	option = {
		name = ep3_contract_event.0580.c

		flavor = ep3_contract_event.0580.c.tt

		if = {
			limit = {
				scope:task_contract_employer = {
					NOT = {
						any_secret = { }
					}
				}
			}
			duel = {
				skill = prowess
				target = scope:secret_haver
				
				50 = { #Your intimidation works
					desc = ep3_contract_event.0580.c.success
					compare_modifier = {
						value = scope:duel_value
						multiplier = 2.5
						min = -49
					}
					modifier = {
						dread > 25
						add = 10
					}
					modifier = {
						dread > 50
						add = 10
					}
					modifier = {
						dread > 75
						add = 10
					}
					min = 5
					custom_tooltip = ep3_contract_event.0560.contractsuccess
					add_character_flag = contract_success_flag
					scope:secret = {
						reveal_to_without_events_effect = {
							CHARACTER = root
						}
					}
					trigger_event = {
						id = ep3_contract_event.0585
						days = 1
					}
				}
				50 = { #They aren't impressed
					desc = ep3_contract_event.0580.c.failure
					compare_modifier = {
						value = scope:duel_value
						multiplier = -2.5
						min = -49
					}
					min = 5
					custom_tooltip = ep3_contract_event.0560.contractfailure
					add_character_flag = contract_failure_flag
					trigger_event = {
						id = ep3_contract_event.0585
						days = 1
					}
				}
			}
		}
		else = {
			duel = {
				skill = prowess
				target = scope:secret_haver
				
				10 = { #Your intimidation works
					desc = ep3_contract_event.0580.c.success
					compare_modifier = {
						value = scope:duel_value
						multiplier = 2.5
						min = -49
					}
					min = 1
					custom_tooltip = ep3_contract_event.0560.contractsuccess
					add_character_flag = contract_success_flag
					scope:secret = {
						reveal_to_without_events_effect = {
							CHARACTER = root
						}
					}
					trigger_event = {
						id = ep3_contract_event.0585
						days = 1
					}
				}
				80 = { #They try to cut a deal...
					desc = ep3_contract_event.0580.c.neutral
					compare_modifier = {
						value = scope:duel_value
						multiplier = 2.5
						min = -49
					}
					min = 10
					hidden_effect = { #For a decent reward
						scope:secret_haver = {
							add_gold = { 50 100 }
						}
					}
					custom_tooltip = ep3_contract_event.0580.c.neutral.tt
					trigger_event = {
						id = ep3_contract_event.0581
						days = 1
					}
				}
				10 = { #They aren't impressed
					desc = ep3_contract_event.0580.c.failure
					compare_modifier = {
						value = scope:duel_value
						multiplier = -2.5
						min = -49
					}
					min = 1
					custom_tooltip = ep3_contract_event.0560.contractfailure
					add_character_flag = contract_failure_flag
					trigger_event = {
						id = ep3_contract_event.0585
						days = 1
					}
				}
			}		
		}

		stress_impact = {
			brave = miniscule_stress_impact_loss
			craven = miniscule_stress_impact_gain
		}
		ai_chance = {
			base = 0
			modifier = {
				add = 100
				prowess > {
					value = scope:secret_haver.prowess
					add = 3
				}
			}
		}
	}

	#invalidate the contract
	option = {
		name = ep3_contract_event.0001.invalidate
		scope:task_contract = {
			invalidate_contract = yes
		}
		#AI should always try to complete the contract
		ai_chance = {
			base = 0
		}
	}
}

# Find Secret - Secret Haver Deal Proposal
ep3_contract_event.0581 = {
	type = character_event
	title = ep3_contract_event.0581.t
	desc = ep3_contract_event.0581.desc
	theme = intrigue
	override_background = {
		reference = temple
	}
	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		character = scope:secret_haver
		animation = scheme
	}
	lower_center_portrait = {
		character = scope:task_contract_employer
	}
	
	immediate = {
		set_contract_scopes_effect = yes
		scope:task_contract_employer = {
			random_secret = {
				save_scope_as = employer_secret
			}
		}
		hidden_effect = {
			scope:secret_haver = {
				random_dummy_gender_effect = yes
				create_artifact_ring_effect = {
					OWNER = scope:dummy_gender
					SMITH = scope:dummy_gender
				}
			}
		}
	}

	#Turn down the deal
	option = {
		name = ep3_contract_event.0581.a

		custom_tooltip = ep3_contract_event.0560.contractsuccess
		add_character_flag = contract_success_flag

		scope:secret = {
			reveal_to_without_events_effect = {
				CHARACTER = root
			}
		}

		trigger_event = {
			id = ep3_contract_event.0585
			days = 1
		}

		stress_impact = {
			honest = miniscule_stress_impact_loss
			deceitful = minor_stress_impact_gain
		}

		ai_chance = {
			base = 10
		}
	}

	#Leave with his rewards
	option = {
		name = ep3_contract_event.0581.b

		scope:secret_haver = {
			pay_short_term_gold = {
				target = root
				gold = scope:secret_haver.gold
			}
		}

		scope:newly_created_artifact = {
			set_owner = root
		}

		scope:employer_secret = {
			reveal_to_without_events_effect = {
				CHARACTER = root
			}
		}

		custom_tooltip = ep3_contract_event.0560.contractfailure

		scope:task_contract = {
			complete_task_contract = failure_standard
		}

		stress_impact = {
			arbitrary = minor_stress_impact_loss
			just = medium_stress_impact_gain
		}

		ai_chance = {
			base = 10
		}
	}
}

# Find Secret - Resolution
ep3_contract_event.0585 = {
	type = character_event
	title = {
		first_valid = {
			triggered_desc = {
				trigger = { has_character_flag = contract_success_flag }
				desc = ep3_contract_event.0585.t.success
			}
			triggered_desc = {
				trigger = { has_character_flag = contract_failure_flag }
				desc = ep3_contract_event.0585.t.failure
			}
		}
	}
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { has_character_flag = lied_about_secret_flag }
				desc = ep3_contract_event.0585.desc.liedsuccessfully
			}
			triggered_desc = {
				trigger = { has_character_flag = contract_success_flag }
				desc = ep3_contract_event.0585.desc.success
			}
			triggered_desc = {
				trigger = { has_character_flag = contract_failure_flag }
				desc = ep3_contract_event.0585.desc.failure
			}
		}
	}
	theme = intrigue
	override_background = {
		reference = council_chamber
	}
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = {
				NOT = {
					has_character_flag = contract_failure_flag
				}
			}
			animation = steward
		}
		animation = stress
	}
	right_portrait = {
		character = scope:task_contract_employer
		triggered_animation = {
			trigger = {
				root = {
					has_character_flag = contract_success_flag
				}
			}
			animation = ecstasy
		}
		animation = anger
	}
	
	immediate = {
		set_contract_scopes_effect = yes
		if = {
			limit = {
				has_character_flag = contract_failure_flag
			}
			scope:task_contract = {
				complete_task_contract = failure_standard
			}
		}
		else = {
			scope:task_contract = {
				complete_task_contract = success_standard
			}
		}
	}

	option = {
		name = ep3_contract_event.0585.a

		trigger = {
			NOT = {
				has_character_flag = contract_failure_flag
			}
		}

		if = {
			limit = {
				NOT = {
					has_character_flag = lied_about_secret_flag
				}
			}
			scope:secret = {
				reveal_to_without_events_effect = {
					CHARACTER = scope:task_contract_employer
				}
			}
		}
		else = {
			hidden_effect = {
				scope:secret_haver = {
					random_list = {
						1 = { add_secret = { type = secret_cannibal } }
						1 = { add_secret = { type = secret_witch } }
						1 = { add_secret = { type = secret_non_believer } }
					}
				}
			}
			scope:secret_haver = {
				random_secret = {
					limit = {
						this != scope:secret
					}
					reveal_to_without_events_effect = {
						CHARACTER = scope:task_contract_employer
					}
				}
			}
		}

		stress_impact = {
			base = miniscule_stress_impact_loss
		}
		ai_chance = {
			base = 10
		}
	}

	option = {
		name = ep3_contract_event.0585.b

		trigger = {
			has_character_flag = contract_failure_flag
		}

		ai_chance = {
			base = 10
		}
	}

	after = {
		remove_character_flag = contract_success_flag
		remove_character_flag = contract_failure_flag
		remove_character_flag = lied_about_secret_flag
	}
}

# Eliminate Heir - Intro
ep3_contract_event.0590 = {
	type = character_event
	title = ep3_contract_event.0590.t
	desc = ep3_contract_event.0590.desc
	theme = intrigue
	override_background = {
		reference = alley_night
	}
	left_portrait = {
		character = root
		animation = spymaster
	}
	right_portrait = {
		character = scope:heir
		animation = paranoia
	}
	lower_center_portrait = {
		character = scope:task_contract_employer
	}
	
	immediate = {
		set_contract_scopes_effect = yes
		scope:task_contract_employer = {
			random_heir = {
				limit = {
					is_primary_heir_of = scope:task_contract_employer
					reverse_opinion = {
						target = scope:task_contract_employer
						value <= high_negative_opinion
					}
					age > 16 #No murderin' babies
				}
				save_scope_as = heir
			}
		}
		location = {
			save_scope_as = location
		}
	}

	#A knife in the dark...
	option = {
		name = ep3_contract_event.0590.a

		duel = {
			skill = prowess
			target = scope:heir
			
			50 = { #Stabby stab
				desc = ep3_contract_event.0590.a.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 2.5
					min = -49
				}
				min = 5
				custom_tooltip = ep3_contract_event.0560.contractsuccess
				scope:heir = {
					death = {
						death_reason = death_disappearance
						killer = root
					}
				}
				scope:task_contract = {
					complete_task_contract = success_standard
				}
			}
			50 = { #They get away, oh no
				desc = ep3_contract_event.0590.a.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -2.5
					min = -49
				}
				min = 5
				custom_tooltip = ep3_contract_event.0560.contractfailure
				add_character_flag = contract_failure_flag
				scope:heir = {
					add_character_modifier = {
						modifier = watchful_modifier
						years = 5
					}
				}
				scope:task_contract_employer = {
					add_character_modifier = {
						modifier = ep3_under_suspicion_modifier
						years = 5
					}				
				}
				trigger_event = {
					id = ep3_contract_event.0595
					days = 1
				}
			}
		}

		stress_impact = {
			sadistic = miniscule_stress_impact_loss
			compassionate = medium_stress_impact_gain
		}

		ai_chance = {
			base = 10
			modifier = {
				add = 50
				highest_skill_including_prowess = prowess
			}
		}
	}

	#Maybe just bonk 'em on the head and drag them away somewhere?
	option = {
		name = ep3_contract_event.0590.b

		duel = {
			skills = { prowess intrigue }
			value = decent_skill_rating
			
			50 = { #Get bonked, nerd
				desc = ep3_contract_event.0590.b.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 2.5
					min = -49
				}
				min = 5
				custom_tooltip = ep3_contract_event.0560.contractsuccess
				add_character_flag = contract_success_flag
				add_character_flag = knockedout_flag
				trigger_event = {
					id = ep3_contract_event.0591
					days = 1
				}
			}
			50 = { #They get away
				desc = ep3_contract_event.0590.b.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -2.5
					min = -49
				}
				min = 5
				custom_tooltip = ep3_contract_event.0560.contractfailure
				add_character_flag = contract_failure_flag
				trigger_event = {
					id = ep3_contract_event.0595
					days = 1
				}
			}
			10 = { #You, uh, bonk a lil hard
				desc = ep3_contract_event.0590.b.fatalbonk
				compare_modifier = {
					value = scope:duel_value
					multiplier = -2.5
					min = -49
				}
				min = 1
				custom_tooltip = ep3_contract_event.0560.contractsuccess
				add_character_flag = contract_success_flag
				scope:heir = {
					death = {
						death_reason = death_disappearance
						killer = root
					}
				}
				add_stress = minor_stress_gain
				scope:task_contract = {
					complete_task_contract = success_standard
				}
			}
		}

		stress_impact = {
			sadistic = medium_stress_impact_gain
			compassionate = miniscule_stress_impact_loss
		}

		ai_chance = {
			base = 10
			modifier = {
				add = 50
				highest_skill = intrigue
			}
		}
	}

	#Try to explain
	option = {
		name = ep3_contract_event.0590.c

		duel = {
			skill = diplomacy
			target = scope:heir
			
			50 = { #You persuade them to leave
				desc = ep3_contract_event.0590.c.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 2.5
					min = -49
				}
				min = 5
				custom_tooltip = ep3_contract_event.0560.contractsuccess
				add_character_flag = contract_success_flag
				add_character_flag = camewillingly_flag
				scope:secret = {
					reveal_to_without_events_effect = {
						CHARACTER = root
					}
				}
				trigger_event = {
					id = ep3_contract_event.0591
					days = 1
				}
			}
			50 = { #They refuse to go
				desc = ep3_contract_event.0590.c.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = 2.5
					min = -49
				}
				min = 5
				hidden_effect = { #For a decent reward
					scope:secret_haver = {
						add_gold = { 50 100 }
					}
				}
				custom_tooltip = ep3_contract_event.0560.contractfailure
				trigger_event = {
					id = ep3_contract_event.0595
					days = 1
				}
			}
			10 = { #You let slip who put you up to this
				desc = ep3_contract_event.0590.c.critfailure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -2.5
					min = -49
				}
				min = 1
				custom_tooltip = ep3_contract_event.0560.contractfailure
				add_character_flag = contract_failure_flag
				scope:heir = {
					set_relation_rival = {
						target = scope:task_contract_employer
						reason = rival_historical
					}
				}
				trigger_event = {
					id = ep3_contract_event.0595
					days = 1
				}
			}
		}		

		stress_impact = {
			sadistic = major_stress_impact_gain
			callous = medium_stress_impact_gain
			compassionate = medium_stress_impact_loss
		}

		ai_chance = {
			base = 10
			modifier = {
				add = 100
				highest_skill = diplomacy
			}
		}
	}

	#invalidate the contract
	option = {
		name = ep3_contract_event.0001.invalidate
		scope:task_contract = {
			invalidate_contract = yes
		}
		#AI should always try to complete the contract
		ai_chance = {
			base = 0
		}
	}
}

# Eliminate Heir - Transition Event
ep3_contract_event.0591 = {
	type = character_event
	title = ep3_contract_event.0591.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { has_character_flag = knockedout_flag }
				desc = ep3_contract_event.0591.desc.knockedout
			}
			triggered_desc = {
				trigger = { has_character_flag = camewillingly_flag }
				desc = ep3_contract_event.0591.desc.camewillingly
			}
		}
	}
	theme = intrigue
	override_background = {
		reference = terrain_scope
	}
	left_portrait = {
		character = root
		animation = personality_honorable
	}
	right_portrait = {
		character = scope:heir
		animation = thinking
	}
	lower_center_portrait = {
		character = scope:task_contract_employer
	}
	
	immediate = {
		set_contract_scopes_effect = yes

		scope:task_contract_employer = {
			random_sub_realm_barony = {
				limit = {
					exists = holder
				}
				save_scope_as = random_barony
			}
		}

		scope:heir = {
			add_trait = gallivanter
		}
	}

	#Best of luck!
	option = {
		name = ep3_contract_event.0591.a

		scope:heir = {
			add_hook = {
				target = root
				type = favor_hook
			}
			start_travel_plan = {
				destination = scope:random_barony
			}
		}

		scope:task_contract = {
			complete_task_contract = success_standard
		}

		ai_chance = {
			base = 10
		}
	}
}

# Eliminate Heir - Resolution
ep3_contract_event.0595 = {
	type = character_event
	title = ep3_contract_event.0595.t
	desc = ep3_contract_event.0595.desc
	theme = intrigue
	override_background = {
		reference = council_chamber
	}
	left_portrait = {
		character = root
		animation = stress
	}
	right_portrait = {
		character = scope:task_contract_employer
		animation = anger
	}
	
	immediate = {
		set_contract_scopes_effect = yes
		scope:task_contract = {
			complete_task_contract = failure_standard
		}
	}

	option = {
		name = ep3_contract_event.0595.a

		stress_impact = {
			base = miniscule_stress_impact_gain
		}
		ai_chance = {
			base = 10
		}
	}

	after = {
		remove_character_flag = contract_success_flag
		remove_character_flag = contract_failure_flag
	}
}
