﻿namespace = laamp_base_learning_contract_events



#####################################
# Learning Base Contracts
#
#######################
# laamp_base_learning_contract_events.4001 - Copy text for ruler
# laamp_base_learning_contract_events.4015 - Help settle theological arguments
# laamp_base_learning_contract_events.4021 - Create a work of learning for a ruler
# laamp_base_learning_contract_events.4100 - Act as a tutor for ruler's child



##################################################
# Copy text for ruler
# 4001 - 4005
############################################

scripted_trigger 4001_option_is_available_trigger = {
	#Do we have an additional language available?
	trigger_if = {
		limit = { 
			$TRAIT$ = no
			$LANGUAGE$ = yes
		}
		exists = scope:additional_language_culture
		NOT = {
			scope:task_contract ?= { has_variable = used_additional_language_var }
		}
	}
	trigger_else_if = {
		limit = { $TRAIT$ = yes }
		#Do we have any Diplomacy supporting trait available?
		trigger_if = {
			limit = { scope:task_contract.var:passage_topic ?= flag:diplomacy_topic }
			OR = {
				4001_trait_option_is_available_trigger = { TRAIT = diplomat }
				4001_trait_option_is_available_trigger = { TRAIT = family_first }
				4001_trait_option_is_available_trigger = { TRAIT = august }
				4001_trait_option_is_available_trigger = { TRAIT = reveler }
			}
		}
		#Do we have any Martial supporting trait available?
		trigger_if = {
			limit = { scope:task_contract.var:passage_topic ?= flag:martial_topic }
			OR = {
				4001_trait_option_is_available_trigger = { TRAIT = strategist }
				4001_trait_option_is_available_trigger = { TRAIT = overseer }
				4001_trait_option_is_available_trigger = { TRAIT = gallant }
				4001_trait_option_is_available_trigger = { TRAIT = blademaster }
				4001_trait_option_is_available_trigger = { TRAIT = commander }
			}
		}
		#Do we have any Stewardship supporting trait available?
		trigger_if = {
			limit = { scope:task_contract.var:passage_topic ?= flag:stewardship_topic }
			OR = {
				4001_trait_option_is_available_trigger = { TRAIT = architect }
				4001_trait_option_is_available_trigger = { TRAIT = administrator }
				4001_trait_option_is_available_trigger = { TRAIT = avaricious }
				4001_trait_option_is_available_trigger = { TRAIT = gardener }
			}
		}
		#Do we have any Intrigue supporting trait available?
		trigger_if = {
			limit = { scope:task_contract.var:passage_topic ?= flag:intrigue_topic }
			OR = {
				4001_trait_option_is_available_trigger = { TRAIT = schemer }
				4001_trait_option_is_available_trigger = { TRAIT = seducer }
				4001_trait_option_is_available_trigger = { TRAIT = torturer }
			}
		}
		#Do we have any Learning supporting trait available?
		trigger_if = {
			limit = { scope:task_contract.var:passage_topic ?= flag:learning_topic }
			OR = {
				4001_trait_option_is_available_trigger = { TRAIT = whole_of_body }
				4001_trait_option_is_available_trigger = { TRAIT = scholar }
				4001_trait_option_is_available_trigger = { TRAIT = theologian }
				4001_trait_option_is_available_trigger = { TRAIT = physician }
				4001_trait_option_is_available_trigger = { TRAIT = mystic }
				4001_trait_option_is_available_trigger = { TRAIT = herbalist }	
			}
		}
	}
	trigger_else = { always = no }
}

scripted_trigger 4001_trait_option_is_available_trigger = {
	AND = {
		scope:lifestyle_trait ?= flag:$TRAIT$
		trigger_if = {
			limit = { scope:lifestyle_trait = flag:none }
			always = no
		}
		trigger_else = {
			NOT = {
				scope:task_contract = { has_variable = used_$TRAIT$_trait_var }
			}
		}
	}
}

scripted_trigger 4001_better_option_is_available_trigger = {
	OR = {
		trigger_if = {
			limit = { exists = scope:additional_language_culture }
			4001_option_is_available_trigger = { TRAIT = no LANGUAGE = yes }
		}
		trigger_if = {
			limit = { 
				exists = scope:lifestyle_trait
				NOT = { scope:lifestyle_trait = flag:none }
			}	
			4001_option_is_available_trigger = { TRAIT = yes LANGUAGE = no }
		}
		trigger_if = {
			limit = {
				NOT = { exists = scope:lifestyle_trait }
				NOT = { exists = scope:additional_language_culture }
			}
			always = no
		}
	}
}

#Is this the final opportunity, and do we have literally 0 score, without any way out?
scripted_trigger 4001_final_shot_trigger = {
	scope:task_contract.var:text_passages_left = 1
	scope:task_contract.var:score_tally = 0
	4001_better_option_is_available_trigger = no
}

scripted_trigger 4001_shoddy_situation_trigger = {
	scope:task_contract.var:text_passages_left = 1
	scope:task_contract.var:score_tally < 2
	4001_better_option_is_available_trigger = no
}

scripted_trigger 4001_secret_is_active_trigger = {
	exists = scope:potential_secret
	#A feeble attempt at controlling when you can investigate the secret
	NOT = { scope:secret_check = root }
}

scripted_effect 4001_show_score_effect = {
	if = {
		limit = { scope:task_contract.var:score_tally < scope:task_contract.var:win_t1_threshold }
		custom_tooltip = laamp_base_learning_contract_events.4001.tt.current_total.sub_t1
	}
	else_if = {
		limit = { scope:task_contract.var:score_tally < scope:task_contract.var:win_t2_threshold }
		custom_tooltip = laamp_base_learning_contract_events.4001.tt.current_total.sub_t2
	}
	else_if = {
		limit = { scope:task_contract.var:score_tally < scope:task_contract.var:win_t3_threshold }
		custom_tooltip = laamp_base_learning_contract_events.4001.tt.current_total.sub_t3
	}
}

scripted_effect 4001_success_effect = {
	if = {
		limit = { $VAL$ = learning_task_contract_major_score_value }
		custom_tooltip = laamp_base_learning_contract_events.4001.tt.progress_towards_success_3
	}
	else_if = {
		limit = { $VAL$ = learning_task_contract_medium_score_value }
		custom_tooltip = laamp_base_learning_contract_events.4001.tt.progress_towards_success_2
	}
	else = { custom_tooltip = laamp_base_learning_contract_events.4001.tt.progress_towards_success_1 }
	scope:task_contract = {
		increment_variable_effect = {
			VAR = score_tally
			VAL = $VAL$
		}
	}
}

scripted_effect 4001_failure_effect = { custom_tooltip = laamp_base_learning_contract_events.4001.tt.no_progress }

scripted_effect 4001_duel_generic_effect = {
	duel = {
		skill = $SKILL$
		value = $DIFF$
		# Victory!
		50 = {
			trigger = { $EMBELLISHMENT$ = yes } #All of this for a lousy desc
			compare_modifier = {
				value = scope:duel_value
				multiplier = 3.5
				min = -49
			}
			modifier = {
				knows_language_of_culture = scope:employer.culture
				add = 20
			}
			min = $MIN_WIN$
			desc = laamp_base_learning_contract_events.4001.success.tt.embellishment
			send_interface_toast = {
				title = laamp_base_learning_contract_events.4001.success.t
				left_icon = root
				4001_success_effect = { VAL = $VAL$ }
			}
			random = {
				chance = chance_to_be_educated_while_educating_value
				add_learning_skill = 1
			}
		}
		50 = {
			trigger = { $EMBELLISHMENT$ = no }
			compare_modifier = {
				value = scope:duel_value
				multiplier = 3.5
				min = -49
			}
			modifier = {
				knows_language_of_culture = scope:employer.culture
				add = 20
			}
			min = $MIN_WIN$
			desc = laamp_base_learning_contract_events.4001.success.tt
			send_interface_toast = {
				title = laamp_base_learning_contract_events.4001.success.t
				left_icon = root
				4001_success_effect = { VAL = $VAL$ }
			}
		}
		# Defeat!
		50 = {
			compare_modifier = {
				value = scope:duel_value
				multiplier = -3.5
				min = -49
			}
			min = $MIN_LOSE$
			desc = laamp_base_learning_contract_events.4001.failure.tt
			send_interface_toast = {
				title = laamp_base_learning_contract_events.4001.failure.t
				left_icon = root
				4001_failure_effect = yes
			}
		}
	}
}

#Copy text for ruler
laamp_base_learning_contract_events.4001 = {
	type = character_event
	title = {
		first_valid = {
			triggered_desc = {
				trigger = { 4001_final_shot_trigger = yes }
				desc = laamp_base_learning_contract_events.4001.t
			}
			triggered_desc = {
				trigger = { scope:task_contract.var:passage_topic ?= flag:diplomacy_topic }
				desc = laamp_base_learning_contract_events.4001.t.diplomacy
			}
			triggered_desc = {
				trigger = { scope:task_contract.var:passage_topic ?= flag:martial_topic }
				desc = laamp_base_learning_contract_events.4001.t.martial
			}
			triggered_desc = {
				trigger = { scope:task_contract.var:passage_topic ?= flag:stewardship_topic }
				desc = laamp_base_learning_contract_events.4001.t.stewardship
			}
			triggered_desc = {
				trigger = { scope:task_contract.var:passage_topic ?= flag:intrigue_topic }
				desc = laamp_base_learning_contract_events.4001.t.intrigue
			}
			triggered_desc = {
				trigger = { scope:task_contract.var:passage_topic ?= flag:learning_topic }
				desc = laamp_base_learning_contract_events.4001.t.learning
			}
		}
	}	
	window = big_event_window
	desc = {
		#Which occurrence is this?
		first_valid = {
			#Final shot
			triggered_desc = {
				trigger = { 4001_final_shot_trigger = yes }
				desc = laamp_base_learning_contract_events.4001.desc.final_shot
			}
			#Third time
			triggered_desc = {
				trigger = { scope:task_contract.var:text_passages_left = 1 }
				desc = laamp_base_learning_contract_events.4001.desc.03
			}
			#Second time
			triggered_desc = {
				trigger = { scope:task_contract.var:text_passages_left = 2 }
				desc = laamp_base_learning_contract_events.4001.desc.02
			}
			#First time
			triggered_desc = {
				trigger = { scope:task_contract.var:text_passages_left = 3 }
				desc = laamp_base_learning_contract_events.4001.desc.01
			}
		}
		#Do we have a secret?
		first_valid = {
			triggered_desc = {
				trigger = { 
					4001_final_shot_trigger = no
					4001_secret_is_active_trigger = yes
				}
				desc = laamp_base_learning_contract_events.4001.outro.secret
			}
			triggered_desc = {
				trigger = {
					4001_final_shot_trigger = no
					scope:task_contract.var:text_passages_left = 1
				}
				desc = laamp_base_learning_contract_events.4001.outro.03
			}
			triggered_desc = {
				trigger = {
					4001_final_shot_trigger = no
					scope:task_contract.var:text_passages_left = 2
				}
				desc = laamp_base_learning_contract_events.4001.outro.02
			}
			triggered_desc = {
				trigger = {
					4001_final_shot_trigger = no
					scope:task_contract.var:text_passages_left = 3
				}
				desc = laamp_base_learning_contract_events.4001.outro.01
			}
		}	
	}
	theme = learning
	#Random attendee of the employer
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = { 4001_secret_is_active_trigger = yes }
			animation = stressed_teacher
		}
		triggered_animation = {
			trigger = { 
				OR = {
					learning < average_skill_rating
					4001_final_shot_trigger = yes
				}
			}
			animation = stressed_teacher
		}
		animation = page_flipping
	}
	right_portrait = {
		character = scope:attendant
		camera = camera_event_scheme_center_look_right
		hide_info = yes
		triggered_animation = {
			trigger = { 4001_final_shot_trigger = yes }
			animation = scheme
		}
		animation = writing
	}
	override_background = { reference = relaxing_room }
	trigger = {
		# Standard triggers.
		scope:task_contract = {
			valid_laamp_basic_trigger = {
				EMPLOYER = scope:employer
				LAAMP = root
			}
		}
	}
	on_trigger_fail = {
		send_interface_message = {
			title = contract_invalidated_title
			type = diplo_contract_scheme_invalidated_message
			right_icon = scope:task_contract.task_contract_employer
			scope:task_contract = { invalidate_contract = yes }
		}
	}
	immediate = {
		#No distractions
		if = {
			limit = {
				NOT = { has_character_flag = is_in_task_contract_event_chain }
			}
			add_character_flag = is_in_task_contract_event_chain
		}
		#Still in the running
		if = {
			limit = { 4001_final_shot_trigger = no }
			#What's the topic?
			random_list = {
				#Diplomacy
				10 = {
					trigger = {
						NOT = {
							scope:task_contract = { has_variable = used_diplomacy_topic_var }
						}
					}
					modifier = { 
						highest_skill = diplomacy
						add = 5
					}
					scope:task_contract = {
						set_variable = {
							name = passage_topic
							value = flag:diplomacy_topic
						}
						set_variable = used_diplomacy_topic_var 
					}
					#Got any trait to help us out?
					random_list = {
						10 = {
							trigger = { has_trait = diplomat }
							save_scope_value_as = {
								name = lifestyle_trait
								value = flag:diplomat
							}
						}
						10 = {
							trigger = { has_trait = family_first }
							save_scope_value_as = {
								name = lifestyle_trait
								value = flag:family_first
							}
						}
						10 = {
							trigger = { has_trait = august }
							save_scope_value_as = {
								name = lifestyle_trait
								value = flag:august
							}
						}
						10 = {
							trigger = { has_trait = lifestyle_reveler }
							save_scope_value_as = {
								name = lifestyle_trait
								value = flag:reveler
							}
						}
					}
				}
				#Martial
				10 = {
					trigger = {
						NOT = { 
							scope:task_contract = { has_variable = used_martial_topic_var }
						}
					}
					modifier = {
						highest_skill = martial
						add = 5
					}
					scope:task_contract = {
						set_variable = {
							name = passage_topic
							value = flag:martial_topic
						}
						set_variable = used_martial_topic_var 
					}
					#Got any trait to help us out?
					random_list = {
						10 = {
							trigger = { has_trait = strategist }
							save_scope_value_as = {
								name = lifestyle_trait
								value = flag:strategist
							}
						}
						10 = {
							trigger = { has_trait = overseer }
							save_scope_value_as = {
								name = lifestyle_trait
								value = flag:overseer
							}
						}
						10 = {
							trigger = { has_trait = gallant }
							save_scope_value_as = {
								name = lifestyle_trait
								value = flag:gallant
							}
						}
						10 = {
							trigger = { has_trait = lifestyle_blademaster }
							save_scope_value_as = {
								name = lifestyle_trait
								value = flag:blademaster
							}
						}
						10 = {
							trigger = {
								OR = {
									has_trait = logistician
									has_trait = military_engineer
									has_trait = aggressive_attacker
									has_trait = unyielding_defender
									has_trait = forder
									has_trait = flexible_leader
									has_trait = desert_warrior
									has_trait = jungle_stalker
									has_trait = reaver
									has_trait = reckless
									has_trait = holy_warrior
									has_trait = open_terrain_expert
									has_trait = rough_terrain_expert
									has_trait = forest_fighter
									has_trait = cautious_leader
									has_trait = organizer
									has_trait = winter_soldier
								}  
							}
							save_scope_value_as = {
								name = lifestyle_trait
								value = flag:commander
							}
						}
					}
				}
				#Stewardship
				10 = {
					trigger = {
						NOT = { 
							scope:task_contract = { has_variable = used_stewardship_topic_var }
						}
					}
					modifier = {
						highest_skill = stewardship
						add = 5
					}
					scope:task_contract = {
						set_variable = {
							name = passage_topic
							value = flag:stewardship_topic
						}
						set_variable = used_stewardship_topic_var 
					}
					#Got any trait to help us out?
					random_list = {
						10 = {
							trigger = { has_trait = architect }
							save_scope_value_as = {
								name = lifestyle_trait
								value = flag:architect
							}
						}
						10 = {
							trigger = { has_trait = administrator }
							save_scope_value_as = {
								name = lifestyle_trait
								value = flag:administrator
							}
						}
						10 = {
							trigger = { has_trait = avaricious }
							save_scope_value_as = {
								name = lifestyle_trait
								value = flag:avaricious
							}
						}
						10 = {
							trigger = { has_trait = lifestyle_gardener }
							save_scope_value_as = {
								name = lifestyle_trait
								value = flag:gardener
							}
						}
					}
				}
				#Intrigue
				10 = {
					trigger = {
						NOT = { 
							scope:task_contract = { has_variable = used_intrigue_topic_var }
						}
					}
					modifier = {
						highest_skill = intrigue
						add = 5
					}
					scope:task_contract = {
						set_variable = {
							name = passage_topic
							value = flag:intrigue_topic
						}
						set_variable = used_intrigue_topic_var 
					}
					#Got any trait to help us out?
					random_list = {
						10 = {
							trigger = { has_trait = schemer }
							save_scope_value_as = {
								name = lifestyle_trait
								value = flag:schemer
							}
						}
						10 = {
							trigger = { has_trait = seducer }
							save_scope_value_as = {
								name = lifestyle_trait
								value = flag:seducer
							}
						}
						10 = {
							trigger = { has_trait = torturer }
							save_scope_value_as = {
								name = lifestyle_trait
								value = flag:torturer
							}
						}
					}
				}
				#Learning
				10 = {
					trigger = {
						NOT = { 
							scope:task_contract = { has_variable = used_learning_topic_var }
						}
					}
					modifier = {
						highest_skill = learning
						add = 5
					}
					scope:task_contract = {
						set_variable = {
							name = passage_topic
							value = flag:learning_topic
						}
						set_variable = used_learning_topic_var 
					}
					#Got any trait to help us out?
					random_list = {
						10 = {
							trigger = { has_trait = whole_of_body }
							save_scope_value_as = {
								name = lifestyle_trait
								value = flag:whole_of_body
							}
						}
						10 = {
							trigger = { has_trait = scholar }
							save_scope_value_as = {
								name = lifestyle_trait
								value = flag:scholar
							}
						}
						10 = {
							trigger = { has_trait = theologian }
							save_scope_value_as = {
								name = lifestyle_trait
								value = flag:theologian
							}
						}
						10 = {
							trigger = { has_trait = lifestyle_physician }
							save_scope_value_as = {
								name = lifestyle_trait
								value = flag:physician
							}
						}
						10 = {
							trigger = { has_trait = lifestyle_mystic }
							save_scope_value_as = {
								name = lifestyle_trait
								value = flag:mystic
							}
						}
						10 = {
							trigger = { has_trait = lifestyle_herbalist }
							save_scope_value_as = {
								name = lifestyle_trait
								value = flag:herbalist
							}
						}
					}
				}
			}
			#Are we a cunning linguist?
			if = {
				limit = { is_ai = no }
				if = {
					limit = {
						num_of_known_languages >= 2
						NOT = { exists = scope:additional_language_culture }
					}
					random_culture_global = {
						limit = { 
							root = { knows_language_of_culture = prev }
							NOT = { this = root.culture }
						}
						save_scope_as = additional_language_culture
					}
				}
			}
			#Is there actually a secret scribbled somewhere in the book... ?
			scope:employer = {
				random_list = {
					85 = {
						#Nothing happens
					}
					15 = {
						random_secret = {
							limit = {
								NOT = { is_known_by = root }
							}
							save_scope_as = potential_secret
						}
						#Apparently the script doesn't like comparing secrets to flags, so let's try something different...
						save_scope_as = secret_check
					}
				}
			}
		}
		# Generate a local to use.
		if = {
			limit = {
				NOT = { exists = scope:attendant }
			}
			create_character = {
				template = merchant_template
				location = root.location
				culture = root.location.culture
				faith = root.location.faith
				save_scope_as = attendant
			}
			scope:attendant = {
				if = {
					limit = {
						is_ruler = no
						exists = court_owner
					}
					court_owner = { save_scope_as = bg_override_char }
				}
				else = {
					save_scope_as = bg_override_char
				}
			}
		}
		# Plus, stop us whilst we're here.
		hidden_effect = {
			current_travel_plan ?= { pause_travel_plan = yes }
		}
		# Finally, tell us where our total is at.
		4001_show_score_effect = yes
		custom_tooltip = laamp_base_learning_contract_events.4001.tt.passages_left
	}
	#TOPIC: Time to embellish
	option = {
		name = laamp_base_learning_contract_events.4001.a
		trigger = { 4001_final_shot_trigger = no }
		skill = learning
		4001_duel_generic_effect = {
			SKILL = learning
			DIFF = extremely_high_skill_rating
			MIN_WIN = 5
			MIN_LOSE = 20
			EMBELLISHMENT = yes
			VAL = learning_task_contract_major_score_value
		}
		ai_chance = {
			base = 0
		}
	}
	#Triggered: Draw from a Diplomacy Lifestyle trait
	option = {
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = {
							NOT = { exists = scope:lifestyle_trait }
						}
						desc = laamp_base_learning_contract_events.4001.b.unavailable
					}
					desc = laamp_base_learning_contract_events.4001.b
				}
			}
		}
		trigger = {
			#How to get around a nebulous custom_tooltip ...
			trigger_if = {
				limit = { 4001_final_shot_trigger = yes }
				always = no
			}
			scope:task_contract.var:passage_topic ?= flag:diplomacy_topic
			trigger_if = {
				limit = {
					NOT = { exists = scope:lifestyle_trait }
				}
				custom_tooltip = {
					text = laamp_base_learning_contract_events.4001.b.tt.used
					exists = scope:lifestyle_trait
				}
			}
			trigger_else = {
				custom_tooltip = {
					text = laamp_base_learning_contract_events.4001.b.tt.unavailable
					OR = {
						4001_trait_option_is_available_trigger = { TRAIT = diplomat }
						4001_trait_option_is_available_trigger = { TRAIT = family_first }
						4001_trait_option_is_available_trigger = { TRAIT = august }
						4001_trait_option_is_available_trigger = { TRAIT = reveler }
					}
				}
			}	
		}
		show_as_unavailable = { scope:task_contract.var:passage_topic ?= flag:diplomacy_topic }
		flavor = {
			triggered_desc = {
				trigger = { learning <= average_skill_rating }
				desc = laamp_base_learning_contract_events.4001.b.flavor.unlearned
			}
		}
		reason = has_diplomacy_trait
		if = {
			limit = { exists = scope:lifestyle_trait }
			switch = {
				trigger = scope:lifestyle_trait
				flag:diplomat = {
					scope:task_contract = { 
						set_variable = {
							name = used_diplomat_trait_var
							value = flag:yes
						}
					}
				}
				flag:family_first = {
					scope:task_contract = { 
						set_variable = {
							name = used_family_first_trait_var
							value = flag:yes
						}
					}
				}
				flag:august = {
					scope:task_contract = { 
						set_variable = {
							name = used_august_trait_var
							value = flag:yes
						}
					}
				}
				flag:reveler = {
					scope:task_contract = { 
						set_variable = {
							name = used_reveler_trait_var
							value = flag:yes
						}
					}
				}
			}
		}
		#Ye be dim, aight?	
		if = {
			limit = { learning <= average_skill_rating }
			4001_duel_generic_effect = {
				SKILL = learning
				DIFF = average_skill_rating
				MIN_WIN = 50
				MIN_LOSE = 5
				EMBELLISHMENT = no
				VAL = learning_task_contract_medium_score_value
			}
		}
		else = {
			4001_success_effect = { VAL = learning_task_contract_medium_score_value }
		}
		# No stress here.
		ai_chance = {
			base = 1
			modifier = {
				exists = scope:lifestyle_trait
				NOT = { scope:lifestyle_trait = flag:none }
				factor = 2
			}
		}
	}
	#Triggered: Draw from a Martial Lifestyle trait
	option = {
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = {
							NOT = { exists = scope:lifestyle_trait }
						}
						desc = laamp_base_learning_contract_events.4001.b.unavailable
					}
					desc = laamp_base_learning_contract_events.4001.b
				}
			}
		}
		trigger = {
			trigger_if = {
				limit = { 4001_final_shot_trigger = yes }
				always = no
			}
			scope:task_contract.var:passage_topic ?= flag:martial_topic
			trigger_if = {
				limit = {
					NOT = { exists = scope:lifestyle_trait }
				}
				custom_tooltip = {
					text = laamp_base_learning_contract_events.4001.b.tt.used
					exists = scope:lifestyle_trait
				}
			}
			trigger_else = {
				custom_tooltip = {
					text = laamp_base_learning_contract_events.4001.b.tt.unavailable
					OR = {
						4001_trait_option_is_available_trigger = { TRAIT = strategist }
						4001_trait_option_is_available_trigger = { TRAIT = overseer }
						4001_trait_option_is_available_trigger = { TRAIT = gallant }
						4001_trait_option_is_available_trigger = { TRAIT = blademaster }
					}
				}
			}		
		}
		show_as_unavailable = { 
			scope:task_contract.var:passage_topic ?= flag:martial_topic
			NOT = { scope:lifestyle_trait = flag:commander }
		}
		flavor = {
			triggered_desc = {
				trigger = { learning <= average_skill_rating }
				desc = laamp_base_learning_contract_events.4001.b.flavor.unlearned
			}
		}
		reason = has_martial_trait
		if = {
			limit = { exists = scope:lifestyle_trait }
			switch = {
				trigger = scope:lifestyle_trait
				flag:strategist = {
					scope:task_contract = { 
						set_variable = {
							name = used_strategist_trait_var
							value = flag:yes
						}
					}
				}
				flag:overseer = {
					scope:task_contract = { 
						set_variable = {
							name = used_overseer_trait_var
							value = flag:yes
						}
					}
				}
				flag:gallant = {
					scope:task_contract = { 
						set_variable = {
							name = used_gallant_trait_var
							value = flag:yes
						}
					}
				}
				flag:blademaster = {
					scope:task_contract = { 
						set_variable = {
							name = used_blademaster_trait_var
							value = flag:yes
						}
					}
				}
			}
		}
		#Ye be dim, aight?	
		if = {
			limit = { learning <= average_skill_rating }
			4001_duel_generic_effect = {
				SKILL = learning
				DIFF = average_skill_rating
				MIN_WIN = 50
				MIN_LOSE = 5
				EMBELLISHMENT = no
				VAL = learning_task_contract_medium_score_value
			}
		}
		else = {
			4001_success_effect = { VAL = learning_task_contract_medium_score_value }
		}
		#Some flavor
		add_prestige = minor_prestige_gain

		ai_chance = {
			base = 1
			modifier = {
				exists = scope:lifestyle_trait
				NOT = { scope:lifestyle_trait = flag:none }
				factor = 2
			}
		}
	}
	#Triggered: Draw from a Commander trait for Martial Lifestyle
	option = {
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = {
							NOT = { exists = scope:lifestyle_trait }
						}
						desc = laamp_base_learning_contract_events.4001.b.unavailable
					}
					desc = laamp_base_learning_contract_events.4001.b
				}
			}
		}
		trigger = {
			trigger_if = {
				limit = { 4001_final_shot_trigger = yes }
				always = no
			}
			scope:task_contract.var:passage_topic ?= flag:martial_topic
			trigger_if = {
				limit = {
					NOT = { exists = scope:lifestyle_trait }
				}
				custom_tooltip = {
					text = laamp_base_learning_contract_events.4001.b.tt.used
					exists = scope:lifestyle_trait
				}
			}
			trigger_else = {
				custom_tooltip = {
					text = laamp_base_learning_contract_events.4001.b.tt.unavailable
					scope:lifestyle_trait = flag:commander
					NOT = {
						scope:task_contract = { has_variable = used_commander_trait_var }
					}
				}
			}
		}
		show_as_unavailable = { 
			scope:task_contract.var:passage_topic ?= flag:martial_topic
			scope:lifestyle_trait = flag:commander
		}
		flavor = {
			triggered_desc = {
				trigger = { learning <= average_skill_rating }
				desc = laamp_base_learning_contract_events.4001.b.flavor.unlearned
			}
		}
		reason = has_commander_trait
		if = {
			limit = { exists = scope:lifestyle_trait }
			scope:task_contract = { 
				set_variable = {
					name = used_commander_trait_var
					value = flag:yes
				}
			}
		}
		#Ye be dim, aight?	
		if = {
			limit = { learning <= average_skill_rating }
			4001_duel_generic_effect = {
				SKILL = learning
				DIFF = average_skill_rating
				MIN_WIN = 50
				MIN_LOSE = 5
				EMBELLISHMENT = no
				VAL = learning_task_contract_medium_score_value
			}
		}
		else = {
			4001_success_effect = { VAL = learning_task_contract_medium_score_value }
		}
		#Some flavor
		add_prestige = minor_prestige_gain

		ai_chance = {
			base = 1
			modifier = {
				exists = scope:lifestyle_trait
				NOT = { scope:lifestyle_trait = flag:none }
				factor = 2
			}
		}
	}
	#Triggered: Draw from a Stewardship Lifestyle trait
	option = {
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = {
							NOT = { exists = scope:lifestyle_trait }
						}
						desc = laamp_base_learning_contract_events.4001.b.unavailable
					}
					desc = laamp_base_learning_contract_events.4001.b
				}
			}
		}
		trigger = {
			trigger_if = {
				limit = { 4001_final_shot_trigger = yes }
				always = no
			}
			scope:task_contract.var:passage_topic ?= flag:stewardship_topic
			trigger_if = {
				limit = {
					NOT = { exists = scope:lifestyle_trait }
				}
				custom_tooltip = {
					text = laamp_base_learning_contract_events.4001.b.tt.used
					exists = scope:lifestyle_trait
				}
			}
			trigger_else = {
				custom_tooltip = {
					text = laamp_base_learning_contract_events.4001.b.tt.unavailable
					OR = {
						4001_trait_option_is_available_trigger = { TRAIT = architect }
						4001_trait_option_is_available_trigger = { TRAIT = administrator }
						4001_trait_option_is_available_trigger = { TRAIT = avaricious }
						4001_trait_option_is_available_trigger = { TRAIT = gardener }
					}
				}
			}
		}
		show_as_unavailable = { scope:task_contract.var:passage_topic ?= flag:stewardship_topic }
		flavor = {
			triggered_desc = {
				trigger = { learning <= average_skill_rating }
				desc = laamp_base_learning_contract_events.4001.b.flavor.unlearned
			}
		}
		reason = has_stewardship_trait
		if = {
			limit = { exists = scope:lifestyle_trait }
			switch = {
				trigger = scope:lifestyle_trait
				flag:architect = {
					scope:task_contract = { 
						set_variable = {
							name = used_architect_trait_var
							value = flag:yes
						}
					}
				}
				flag:administrator = {
					scope:task_contract = { 
						set_variable = {
							name = used_administrator_trait_var
							value = flag:yes
						}
					}
				}
				flag:avaricious = {
					scope:task_contract = { 
						set_variable = {
							name = used_avaricious_trait_var
							value = flag:yes
						}
					}
				}
				flag:gardener = {
					scope:task_contract = { 
						set_variable = {
							name = used_gardener_trait_var
							value = flag:yes
						}
					}
				}
			}
		}
		#Ye be dim, aight?	
		if = {
			limit = { learning <= average_skill_rating }
			4001_duel_generic_effect = {
				SKILL = learning
				DIFF = average_skill_rating
				MIN_WIN = 50
				MIN_LOSE = 5
				EMBELLISHMENT = no
				VAL = learning_task_contract_medium_score_value
			}
		}
		else = {
			4001_success_effect = { VAL = learning_task_contract_medium_score_value }
		}
		#Some flavor
		add_prestige = miniscule_gold_laamps_value

		ai_chance = {
			base = 1
			modifier = {
				exists = scope:lifestyle_trait
				NOT = { scope:lifestyle_trait = flag:none }
				factor = 2
			}
		}
	}
	#Triggered: Draw from a Intrigue Lifestyle trait
	option = {
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = {
							NOT = { exists = scope:lifestyle_trait }
						}
						desc = laamp_base_learning_contract_events.4001.b.unavailable
					}
					desc = laamp_base_learning_contract_events.4001.b
				}
			}
		}
		trigger = {
			trigger_if = {
				limit = { 4001_final_shot_trigger = yes }
				always = no
			}
			scope:task_contract.var:passage_topic ?= flag:intrigue_topic
			trigger_if = {
				limit = {
					NOT = { exists = scope:lifestyle_trait }
				}
				custom_tooltip = {
					text = laamp_base_learning_contract_events.4001.b.tt.used
					exists = scope:lifestyle_trait
				}
			}
			trigger_else = {
				custom_tooltip = {
					text = laamp_base_learning_contract_events.4001.b.tt.unavailable
					OR = {
						4001_trait_option_is_available_trigger = { TRAIT = schemer }
						4001_trait_option_is_available_trigger = { TRAIT = seducer }
						4001_trait_option_is_available_trigger = { TRAIT = torturer }
					}
				}
			}	
		}
		show_as_unavailable = { scope:task_contract.var:passage_topic ?= flag:intrigue_topic }
		flavor = {
			triggered_desc = {
				trigger = { learning <= average_skill_rating }
				desc = laamp_base_learning_contract_events.4001.b.flavor.unlearned
			}
		}
		reason = has_intrigue_trait
		if = {
			limit = { exists = scope:lifestyle_trait }
			switch = {
				trigger = scope:lifestyle_trait
				flag:schemer = {
					scope:task_contract = { 
						set_variable = {
							name = used_schemer_trait_var
							value = flag:yes
						}
					}
				}
				flag:seducer = {
					scope:task_contract = { 
						set_variable = {
							name = used_seducer_trait_var
							value = flag:yes
						}
					}
				}
				flag:torturer = {
					scope:task_contract = { 
						set_variable = {
							name = used_torturer_trait_var
							value = flag:yes
						}
					}
				}
			}
		}
		#Ye be dim, aight?	
		if = {
			limit = { learning <= average_skill_rating }
			4001_duel_generic_effect = {
				SKILL = learning
				DIFF = average_skill_rating
				MIN_WIN = 50
				MIN_LOSE = 5
				EMBELLISHMENT = no
				VAL = learning_task_contract_medium_score_value
			}
		}
		else = {
			4001_success_effect = { VAL = learning_task_contract_medium_score_value }
		}
		#Some flavor
		domicile ?= { change_provisions = miniscule_provisions_gain }

		ai_chance = {
			base = 1
			modifier = {
				exists = scope:lifestyle_trait
				NOT = { scope:lifestyle_trait = flag:none }
				factor = 2
			}
		}
	}
	#Triggered: Draw from a Learning Lifestyle trait
	option = {
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = {
							NOT = { exists = scope:lifestyle_trait }
						}
						desc = laamp_base_learning_contract_events.4001.b.unavailable
					}
					desc = laamp_base_learning_contract_events.4001.b
				}
			}
		}
		trigger = {
			trigger_if = {
				limit = { 4001_final_shot_trigger = yes }
				always = no
			}
			trigger_else = {
				scope:task_contract.var:passage_topic ?= flag:learning_topic
				custom_tooltip = {
					text = laamp_base_learning_contract_events.4001.b.tt.used
					exists = scope:lifestyle_trait
				}
				custom_tooltip = {
					text = laamp_base_learning_contract_events.4001.b.tt.unavailable
					OR = {
						AND = {
							scope:lifestyle_trait = flag:whole_of_body
							NOT = {
								scope:task_contract = { has_variable = used_whole_of_body_trait_var }
							}
						}
						AND = {
							scope:lifestyle_trait = flag:scholar
							NOT = {
								scope:task_contract = { has_variable = used_scholar_trait_var }
							}
						}
						AND = {
							scope:lifestyle_trait = flag:theologian
							NOT = {
								scope:task_contract = { has_variable = used_theologian_trait_var }
							}
						}
						AND = {
							scope:lifestyle_trait = flag:physician
							NOT = {
								scope:task_contract = { has_variable = used_physician_trait_var }
							}
						}
						AND = {
							scope:lifestyle_trait = flag:mystic
							NOT = {
								scope:task_contract = { has_variable = used_mystic_trait_var }
							}
						}
						AND = {
							scope:lifestyle_trait = flag:herbalist
							NOT = {
								scope:task_contract = { has_variable = used_herbalist_trait_var }
							}
						}
					}
				}
			}
			
		}
		show_as_unavailable = { scope:task_contract.var:passage_topic ?= flag:learning_topic }
		flavor = {
			triggered_desc = {
				trigger = { learning <= average_skill_rating }
				desc = laamp_base_learning_contract_events.4001.b.flavor.unlearned
			}
		}
		reason = has_learning_trait
		if = {
			limit = { exists = scope:lifestyle_trait }
			switch = {
				trigger = scope:lifestyle_trait
				flag:whole_of_body = {
					scope:task_contract = { 
						set_variable = {
							name = used_whole_of_body_trait_var
							value = flag:yes
						}
					}
				}
				flag:scholar = {
					scope:task_contract = { 
						set_variable = {
							name = used_scholar_trait_var
							value = flag:yes
						}
					}
				}
				flag:theologian = {
					scope:task_contract = { 
						set_variable = {
							name = used_theologian_trait_var
							value = flag:yes
						}
					}
				}
				flag:physician = {
					scope:task_contract = { 
						set_variable = {
							name = used_physician_trait_var
							value = flag:yes
						}
					}
				}
				flag:mystic = {
					scope:task_contract = { 
						set_variable = {
							name = used_mystic_trait_var
							value = flag:yes
						}
					}
				}
				flag:herbalist = {
					scope:task_contract = { 
						set_variable = {
							name = used_herbalist_trait_var
							value = flag:yes
						}
					}
				}
			}
		}
		#Ye be dim, aight?	
		if = {
			limit = { learning <= average_skill_rating }
			4001_duel_generic_effect = {
				SKILL = learning
				DIFF = average_skill_rating
				MIN_WIN = 50
				MIN_LOSE = 5
				EMBELLISHMENT = no
				VAL = learning_task_contract_medium_score_value
			}
		}
		else = {
			4001_success_effect = { VAL = learning_task_contract_medium_score_value }
		}
		#Some flavor
		add_prestige = minor_piety_gain

		ai_chance = {
			base = 1
			modifier = {
				exists = scope:lifestyle_trait
				NOT = { scope:lifestyle_trait = flag:none }
				factor = 2
			}
		}
	}
	#Triggered: You know more than 1 language
	option = {
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = {
							NOT = { exists = scope:additional_language_culture }
						}
						desc = laamp_base_learning_contract_events.4001.c.unavailable
					}
					desc = laamp_base_learning_contract_events.4001.c
				}
			}
		}
		trigger = {
			trigger_if = {
				limit = { 4001_final_shot_trigger = yes }
				always = no
			}
			trigger_if = {
				limit = {
					scope:task_contract = { has_variable = used_additional_language_var }
				}
				custom_tooltip = {
					text = laamp_base_learning_contract_events.4001.c.tt.used
					4001_option_is_available_trigger = { TRAIT = no LANGUAGE = yes }
				}	
			}
			trigger_else_if = {
				limit = {
					num_of_known_languages <= 1
				}
				custom_tooltip = {
					text = laamp_base_learning_contract_events.4001.c.tt.unavailable
					always = no
				}
			}
			trigger_else = {
				always = yes
			}
		}
		show_as_unavailable = { 4001_final_shot_trigger = no }
		flavor = {
			triggered_desc = {
				trigger = { learning <= average_skill_rating }
				desc = laamp_base_learning_contract_events.4001.b.flavor.unlearned
			}
		}
		reason = language
		scope:task_contract = { 
			set_variable = {
				name = used_additional_language_var
				value = flag:yes
			}
		}
		#Ye be dim.
		if = {
			limit = { learning <= average_skill_rating }
			4001_duel_generic_effect = {
				SKILL = learning
				DIFF = average_skill_rating
				MIN_WIN = 5
				MIN_LOSE = 5
				EMBELLISHMENT = no
				VAL = learning_task_contract_medium_score_value
			}
		}
		else = {
			4001_success_effect = { VAL = learning_task_contract_medium_score_value }
		}
		# No stress here.
		ai_chance = {
			base = 1
			modifier = {
				exists = scope:additional_language_culture
				factor = 2
			}
		}
	}
	#No, let's just copy the text
	option = {
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = { 4001_secret_is_active_trigger = yes }
						desc = laamp_base_learning_contract_events.4001.d.secret
					}
					desc = laamp_base_learning_contract_events.4001.d
				}
			}
		}
		flavor = {
			first_valid = {
				#We don't have a secret, but we do have better options so let's sweeten the deal
				triggered_desc = {
					trigger = {
						4001_secret_is_active_trigger = no
						learning > average_skill_rating
						4001_better_option_is_available_trigger = yes
					}
					desc = laamp_base_learning_contract_events.4001.d.flavor.unwind
				}
				#We're just a bit... dim
				triggered_desc = {
					trigger = { learning <= average_skill_rating }
					desc = laamp_base_learning_contract_events.4001.d.flavor.unlearned
				}
			}
		}
		trigger = { 4001_final_shot_trigger = no }
		#Still dim.
		if = {
			limit = { learning <= average_skill_rating }
			4001_duel_generic_effect = {
				SKILL = learning
				DIFF = average_skill_rating
				MIN_WIN = 5
				MIN_LOSE = 5
				EMBELLISHMENT = no
				VAL = learning_task_contract_qualified_score_value
			}
		}
		else = {
			4001_success_effect = { VAL = learning_task_contract_qualified_score_value }
		}
		#Stress relief to sweeten the deal if any of the +2 options are available
		if = {
			limit = {
				learning > average_skill_rating
				4001_better_option_is_available_trigger = yes 
			}
			stress_impact = { base = medium_stress_impact_loss }
		}
		#Let's learn that secret
		if = {
			limit = { 4001_secret_is_active_trigger = yes }
			custom_tooltip = {
				text = laamp_base_learning_contract_events.4001.d.secret.tt
				hidden_effect = {
					scope:potential_secret = { reveal_to = root }
				}
			}
		}
		ai_chance = { base = 1 }
	}
	#Final Shot: Bruteforce - triggered if you have 1 shot left and less than 2 score (3 is qualified success)
	option = {
		name = laamp_base_learning_contract_events.4001.e
		trigger = { 
			OR = {
				4001_final_shot_trigger = yes
				4001_shoddy_situation_trigger = yes
			}
		}
		#A lot, but not a flat out 100
		add_stress = {
			value = {
				add = massive_stress_impact_gain
				multiply = 0.8
			}
		}
		4001_success_effect = { VAL = learning_task_contract_major_score_value }
		ai_chance = {
			base = 0
		}
	}
	#Final Shot: How about I just die then
	option = {
		name = laamp_base_learning_contract_events.4001.f
		trigger = { 4001_final_shot_trigger = yes }
		custom_tooltip = laamp_base_learning_contract_events.4001.f.tt
		ai_chance = {
			base = 0
		}
	}
	after = {
		#Adjust the passages left
		scope:task_contract = {
			increment_variable_effect = {
				VAR = text_passages_left
				VAL = -1
			}
		}
		if = {
			limit = { scope:task_contract.var:text_passages_left > 0 }
			#Reset the trait scope
			save_scope_value_as = {
				name = lifestyle_trait
				value = flag:none
			}
			#Reset the secret scope; if it's ROOT, it's inactive
			save_scope_as = secret_check
			#Reset the topic
			scope:task_contract = {
				set_variable = {
					name = used_additional_language_var
					value = flag:none
				}
			}
			#Once more into the fray
			trigger_event = {
				id = laamp_base_learning_contract_events.4001
				days = { 2 5 }
			}
		}
		else = {
			#Conclusion
			trigger_event = {
				id = laamp_base_learning_contract_events.4005
				days = 1
			}
		}
	}
}

#Conclusion
laamp_base_learning_contract_events.4005 = {
	type = character_event
	title = laamp_base_learning_contract_events.4005.t
	window = big_event_window
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					OR = {
						exists = scope:success_critical
						exists = scope:success_standard
					}
				}
				desc = laamp_base_learning_contract_events.4005.desc.success
			}
			triggered_desc = {
				trigger = { exists = scope:success_qualified }
				desc = laamp_base_learning_contract_events.4005.desc.success.qualified
			}
			desc = laamp_base_learning_contract_events.4005.desc.failure
		}
	}
	theme = learning
	left_portrait = {
		character = scope:attendee
		triggered_animation = {
			trigger = { exists = scope:success_critical }
			animation = disbelief
		}
		triggered_animation = {
			trigger = {
				NOT = { exists = scope:failure_standard }
			}
			animation = thinking
		}
		animation = disapproval
	}
	center_portrait = {
		character = root
		triggered_animation = {
			trigger = { exists = scope:success_critical }
			animation = personality_zealous
		}
		triggered_animation = {
			trigger = { exists = scope:success_standard }
			animation = happiness
		}
		triggered_animation = {
			trigger = { exists = scope:success_qualified }
			animation = stress
		}
		animation = shame
	}
	right_portrait = {
		character = scope:employer
		triggered_animation = {
			trigger = {
				OR = {
					exists = scope:success_critical
					exists = scope:success_standard
				}
			}
			animation = reading
		}
		triggered_animation = {
			trigger = { exists = scope:success_qualified }
			animation = personality_rational
		}
		animation = disapproval
	}
	override_background = { reference = relaxing_room }
	trigger = {
		# Standard triggers.
		scope:task_contract = {
			valid_laamp_basic_trigger = {
				EMPLOYER = scope:employer
				LAAMP = root
			}
		}
	}
	on_trigger_fail = {
		send_interface_message = {
			title = contract_invalidated_title
			type = diplo_contract_scheme_invalidated_message
			right_icon = scope:task_contract.task_contract_employer
			scope:task_contract = { invalidate_contract = yes }
		}
	}
	immediate = {
		if = {
			limit = { scope:task_contract.var:score_tally >= scope:task_contract.var:win_t3_threshold }
			save_scope_as = success_critical
		}
		else_if = {
			limit = { scope:task_contract.var:score_tally >= scope:task_contract.var:win_t2_threshold }
			save_scope_as = success_standard
		}
		else_if = {
			limit = { scope:task_contract.var:score_tally >= scope:task_contract.var:win_t1_threshold }
			save_scope_as = success_qualified
		}
		else = { save_scope_as = failure_standard }
		# Plus, stop us whilst we're here.
		hidden_effect = {
			current_travel_plan ?= { pause_travel_plan = yes }
		}
		# Finally, tell us where our total is at.
		4001_show_score_effect = yes
	}
	#Yup, yup...
	option = {
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = { exists = scope:success_critical }
						desc = laamp_base_learning_contract_events.4005.a.success_critical
					}
					triggered_desc = {
						trigger = { exists = scope:success_standard }
						desc = laamp_base_learning_contract_events.4005.a.success_standard
					}
					triggered_desc = {
						trigger = { exists = scope:success_qualified }
						desc = laamp_base_learning_contract_events.4005.a.success_qualified
					}
					desc = laamp_base_learning_contract_events.4005.a.failure_standard
				}
			}
		}
		scope:task_contract = {
			if = {
				limit = { exists = scope:success_critical }
				complete_task_contract = success_critical
			}
			else_if = {
				limit = { exists = scope:success_standard }
				complete_task_contract = success_standard
			}
			else_if = {
				limit = { exists = scope:success_qualified }
				complete_task_contract = success_qualified
			}
			else = { complete_task_contract = failure_standard }
		}
		#*shrug*
		ai_chance = {
			base = 100
		}
	}
	after = { 
		remove_character_flag ?= is_in_task_contract_event_chain 
		hidden_effect = { current_travel_plan ?= { resume_travel_plan = yes } }
	}
}



##################################################
# Help settle theological arguments
# 4011 - 4017
############################################

#Travel setup
laamp_base_learning_contract_events.4011 = {
	type = character_event
	title = laamp_base_learning_contract_events.4011.t
	desc = laamp_base_learning_contract_events.4011.desc
	theme = learning
	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		trigger = { exists = scope:follower }
		character = scope:follower
		animation = thinking
	}
	lower_center_portrait = {
		character = scope:employer
	}
	override_background = { reference = terrain_travel }
	immediate = {
		random_courtier = {
			limit = {
				NOT = { 
					has_any_bad_relationship_with_character_trigger = { CHARACTER = root }
				}
				is_available_allow_travelling = yes
				age >= 10
			}
			save_scope_as = follower
		}
	}
	# Travel without domicile.
	option = {
		name = laamp_base_learning_contract_events.4011.a
		custom_tooltip = laamp_base_learning_contract_events.4011.a.tt
		switch = {
			trigger = exists
			scope:destination_5 = { custom_tooltip = laamp_base_learning_contract_events.4011.tt.destination_list.5_destinations }
			scope:destination_4 = { custom_tooltip = laamp_base_learning_contract_events.4011.tt.destination_list.4_destinations }
			fallback = { custom_tooltip = laamp_base_learning_contract_events.4011.tt.destination_list.3_destinations }
		}
		custom_tooltip = laamp_base_learning_contract_events.4011.tt.explanation
		switch = {
			trigger = exists
			scope:destination_5 = {
				root = {
					start_travel_plan = {
						destination = scope:employer_location_destination
						destination = scope:destination_1.title_province
						destination = scope:destination_2.title_province
						destination = scope:destination_3.title_province
						destination = scope:destination_4.title_province
						destination = scope:destination_5.title_province
						destination = scope:employer_location_destination
						on_arrival_on_action = laamp_base_4015_contract_arrival_events
						on_travel_planner_cancel_event = laamp_base_learning_contract_events.4012
					}
				}
			}
			scope:destination_4 = {
				root = {
					start_travel_plan = {
						destination = scope:employer_location_destination
						destination = scope:destination_1.title_province
						destination = scope:destination_2.title_province
						destination = scope:destination_3.title_province
						destination = scope:destination_4.title_province
						destination = scope:employer_location_destination
						on_arrival_on_action = laamp_base_4015_contract_arrival_events
						on_travel_planner_cancel_event = laamp_base_learning_contract_events.4012
					}
				}
			}
			fallback = {
				root = {
					start_travel_plan = {
						destination = scope:employer_location_destination
						destination = scope:destination_1.title_province
						destination = scope:destination_2.title_province
						destination = scope:destination_3.title_province
						destination = scope:employer_location_destination
						on_arrival_on_action = laamp_base_4015_contract_arrival_events
						on_travel_planner_cancel_event = laamp_base_learning_contract_events.4012
					}
				}
			}
		}
		ai_chance = { base = 100 }
	}
	#You don't get to choose to travel _with_ domicile because that breaks the Conclusion. :colbert:
}

#	Travel invalidation event.
laamp_base_learning_contract_events.4012 = {
	hidden = yes

	trigger = { is_alive = yes }

	immediate = {
		scope:employer = { remove_character_flag = is_in_task_contract_event_chain }
		send_interface_message = {
			title = contract_invalidated_title
			type = diplo_contract_scheme_invalidated_message
			right_icon = scope:task_contract.task_contract_employer
			scope:task_contract = { invalidate_contract = yes }
		}
	}
}

scripted_effect 4014_show_score_effect = {
	if = {
		limit = { scope:task_contract.var:wins_tally < scope:task_contract.var:win_t1_threshold }
		custom_tooltip = laamp_base_learning_contract_events.4015.tt.current_total.sub_t1
	}
	else_if = {
		limit = { scope:task_contract.var:wins_tally < scope:task_contract.var:win_t2_threshold }
		custom_tooltip = laamp_base_learning_contract_events.4015.tt.current_total.sub_t2
	}
	else_if = {
		limit = { scope:task_contract.var:wins_tally < scope:task_contract.var:win_t3_threshold }
		custom_tooltip = laamp_base_learning_contract_events.4015.tt.current_total.sub_t3
	}
}

#Kick off featuring your Employer
laamp_base_learning_contract_events.4014 = { 
	type = character_event
	title = laamp_base_learning_contract_events.4014.t
	window = big_event_window
	desc = laamp_base_learning_contract_events.4014.desc
	theme = learning
	center_portrait = {
		character = root
		animation = personality_compassionate
	}
	right_portrait = {
		character = scope:employer
		camera = camera_event_scheme_far_right
		triggered_animation = {
			trigger = {
				OR = {
					has_trait = calm
					has_trait = callous
				}
			}
			animation = stress
		}
		triggered_animation = {
			trigger = {
				OR = {
					has_trait = wrathful
					has_trait = irritable
				}
			}
			animation = rage
		}
		animation = anger
	}
	override_background = { reference = throne_room }
	trigger = {
		NOT = {
			scope:task_contract = { has_variable = had_intro_event_var }
		}
	}
	immediate = {
		#For background
		scope:employer = { save_scope_as = bg_override_char }
		#For loc
		random_dummy_gender_effect = yes
		#For the contract
		scope:task_contract = { set_variable = had_intro_event_var }
		# Plus, stop us whilst we're here.
		hidden_effect = {
			current_travel_plan ?= { pause_travel_plan = yes }
		}
		# Finally, tell us where our total is at.
		4014_show_score_effect = yes
	}
	#Yup, yup...
	option = {
		name = laamp_base_learning_contract_events.4014.a
		custom_tooltip = laamp_base_learning_contract_events.4014.a.tt
		#Nothing to see here
		ai_chance = {
			base = 100
		}
	}
	after = {
		hidden_effect = {
			current_travel_plan = { resume_travel_plan = yes }
		}
	}
}

scripted_trigger 4015_not_worship_indoors_trigger = {
	OR = {
		culture ?= { has_graphical_steppe_culture_group_trigger = yes }
		faith.religion = { is_in_family = rf_pagan }
	}
}

scripted_effect 4015_success_effect = {
	scope:task_contract = {
		increment_variable_effect = {
			VAR = wins_tally
			VAL = 1
		}
	}
	custom_tooltip = laamp_base_learning_contract_events.4100.tt.progress_towards_success
	#Up the count / lower the count
	scope:task_contract = {
		increment_variable_effect = {
			VAR = encounter_tally
			VAL = 1
		}
		increment_variable_effect = {
			VAR = opportunities_left_tally
			VAL = -1
		}
	}
}

scripted_effect 4015_mayor_success_effect = {
	scope:local_holder ?= {
		if = {
			limit = { this = root }
			reverse_add_opinion = {
				modifier = respect_opinion
				target = root
				opinion = 25
			}
			if = {
				limit = {
					NOT = { is_contact_of = root }
				}
				add_contact = scope:local_holder
			}
			
		}
	}	
}

scripted_effect 4015_failure_effect = {
	custom_tooltip = laamp_base_learning_contract_events.4015.tt.no_progress
	#Up the count
	scope:task_contract = {
		increment_variable_effect = {
			VAR = encounter_tally
			VAL = 1
		}
		increment_variable_effect = {
			VAR = opportunities_left_tally
			VAL = -1
		}
	}
}

# Help settle theological arguments
laamp_base_learning_contract_events.4015 = {
	type = character_event
	title = laamp_base_learning_contract_events.4015.t
	window = big_event_window
	desc = {
		# Surroundings.
		first_valid = {
			triggered_desc = {
				trigger = { scope:task_contract.var:background ?= flag:alley }
				desc = laamp_base_learning_contract_events.4015.desc.surroundings.alley
			}
			triggered_desc = {
				trigger = { scope:task_contract.var:background ?= flag:market }
				desc = laamp_base_learning_contract_events.4015.desc.surroundings.market
			}
			triggered_desc = {
				trigger = { 
					scope:task_contract.var:background ?= flag:temple
					location = { 4015_not_worship_indoors_trigger = yes }
				}
				desc = laamp_base_learning_contract_events.4015.desc.surroundings.outdoors_temple
			}
			triggered_desc = {
				trigger = { scope:task_contract.var:background ?= flag:temple }
				desc = laamp_base_learning_contract_events.4015.desc.surroundings.temple
			}
			triggered_desc = {
				trigger = { scope:task_contract.var:background ?= flag:study }
				desc = laamp_base_learning_contract_events.4015.desc.surroundings.study
			}
			triggered_desc = {
				trigger = { scope:task_contract.var:background ?= flag:physician }
				desc = laamp_base_learning_contract_events.4015.desc.surroundings.physician
			}
			triggered_desc = {
				trigger = { scope:task_contract.var:background ?= flag:council_chamber }
				desc = laamp_base_learning_contract_events.4015.desc.surroundings.council_chamber
			}
			triggered_desc = {
				trigger = { scope:task_contract.var:background ?= flag:corridor }
				desc = laamp_base_learning_contract_events.4015.desc.surroundings.corridor
			}
			triggered_desc = {
				trigger = { scope:task_contract.var:background ?= flag:relaxing_room }
				desc = laamp_base_learning_contract_events.4015.desc.surroundings.relaxing_room
			}
		}
		desc = boilerplate.paragraph
		# Local mood.
		first_valid = {
			triggered_desc = {
				trigger = { scope:local_mood = flag:disapproval }
				desc = laamp_base_learning_contract_events.4015.desc.local_mood.disapproval
			}
			triggered_desc = {
				trigger = { scope:local_mood = flag:anger }
				desc = laamp_base_learning_contract_events.4015.desc.local_mood.anger
			}
			triggered_desc = {
				trigger = { scope:local_mood = flag:admiration }
				desc = laamp_base_learning_contract_events.4015.desc.local_mood.admiration
			}
			random_valid = {
				triggered_desc = {
					trigger = { scope:local_mood = flag:indifferent }
					desc = laamp_base_learning_contract_events.4015.desc.local_mood.indifferent
				}
				triggered_desc = {
					trigger = { scope:local_mood = flag:indifferent }
					desc = laamp_base_learning_contract_events.4015.desc.local_mood.indifferent.02
				}
			}
			triggered_desc = {
				trigger = { scope:local_mood = flag:thinking }
				desc = laamp_base_learning_contract_events.4015.desc.local_mood.thinking
			}
		}
		desc = boilerplate.paragraph
		first_valid = {
			triggered_desc = {
				trigger = { 
					exists = scope:camp_priest
					scope:task_contract = { 
						has_variable = used_priest_count_var
						var:used_priest_count_var >= scope:task_contract.var:win_t2_threshold
					}
				}
				desc = laamp_base_learning_contract_events.4015.desc.outro_priest.exhausted
			}
			triggered_desc = {
				trigger = { 
					exists = scope:camp_priest
					scope:task_contract = { 
						has_variable = used_priest_count_var
						var:used_priest_count_var >= scope:task_contract.var:win_t1_threshold
					}
				}
				desc = laamp_base_learning_contract_events.4015.desc.outro_priest.wary
			}
			triggered_desc = {
				trigger = { exists = scope:camp_priest }
				desc = laamp_base_learning_contract_events.4015.desc.outro_priest
			}
			desc = laamp_base_learning_contract_events.4015.desc.outro
		}	
	}
	theme = stewardship
	left_portrait = {
		trigger = { exists = scope:camp_priest }
		character = scope:camp_priest
		triggered_animation = {
			trigger = { 
				exists = scope:camp_priest
				scope:task_contract = { 
					has_variable = used_priest_count_var
					var:used_priest_count_var >= scope:task_contract.var:win_t2_threshold
				}
			}
			animation = stress
		}
		triggered_animation = {
			trigger = { 
				exists = scope:camp_priest
				scope:task_contract = { 
					has_variable = used_priest_count_var
					var:used_priest_count_var >= scope:task_contract.var:win_t1_threshold
				}
			}
			animation = stressed_teacher
		}
		animation = happy_teacher
	}
	center_portrait = {
		character = root
		animation = storyteller
	}
	right_portrait = {
		character = scope:challenge_character	
		camera = camera_event_scheme_far_right
		triggered_animation = {
			trigger = { scope:local_mood = flag:disapproval }
			animation = disapproval
		}
		triggered_animation = {
			trigger = { scope:local_mood = flag:anger }
			animation = anger
		}
		triggered_animation = {
			trigger = { scope:local_mood = flag:admiration }
			animation = admiration
		}
		triggered_animation = {
			trigger = { scope:local_mood = flag:indifferent }
			animation = personality_honorable
		}
		triggered_animation = {
			trigger = { scope:local_mood = flag:thinking }
			animation = thinking
		}
		animation = disapproval
	}
	# Backgrounds indented +1 for easier folding.
		override_background = {
			trigger = { scope:task_contract.var:background ?= flag:alley }
			reference = alley_day
		}
		override_background = {
			trigger = { scope:task_contract.var:background ?= flag:market }
			reference = market
		}
		#We're probs not indoors
		override_background = {
			trigger = { 
				scope:task_contract.var:background ?= flag:temple
				location = { 4015_not_worship_indoors_trigger = yes }
			}
			reference = holy_site_generic
		}
		override_background = {
			trigger = { scope:task_contract.var:background ?= flag:temple }
			reference = temple
		}
		override_background = {
			trigger = { scope:task_contract.var:background ?= flag:study }
			reference = study
		}
		override_background = {
			trigger = { scope:task_contract.var:background ?= flag:physician }
			reference = physicians_study
		}
		override_background = {
			trigger = { scope:task_contract.var:background ?= flag:docks }
			reference = docks
		}
		override_background = {
			trigger = { scope:task_contract.var:background ?= flag:council_chamber }
			reference = council_chamber
		}
		override_background = {
			trigger = { scope:task_contract.var:background ?= flag:corridor }
			reference = corridor_day
		}
		override_background = {
			trigger = { scope:task_contract.var:background ?= flag:relaxing_room }
			reference = relaxing_room
		}
		
	trigger = { scope:task_contract.var:opportunities_left_tally > 0 }
	immediate = {
		#Find a Baron to use
		if = {
			limit = {
				location.barony.holder ?= { 
					highest_held_title_tier = tier_barony
					is_available_ai_adult = yes
				}
			}
			location.barony.holder = {
				save_scope_as = local_holder
				save_scope_as = challenge_character
			}
		}
		else = {
			#Or a local clergy, I guess
			random_pool_character = {
				province = location
				limit = {
					is_available_adult = yes
					has_trait = devoted
					NOT = { has_character_flag = used_in_theological_dispute }
				}
				save_scope_as = local_clergy
				save_scope_as = challenge_character
				if = {
					limit = {
						NOT = { has_character_flag = need_priest_outfit }
					}
					add_character_flag = {
						flag = need_priest_outfit
						days = 10
					}
				}
			}
			if = {
				limit = {
					NOT = { exists = scope:local_clergy }
				}
				#Or generate a local to use.
				create_character = {
					template = monk_character_template
					location = root.location
					culture = root.location.culture
					faith = root.location.faith
					trait = devoted
					save_scope_as = local_clergy
					save_scope_as = challenge_character
				}
			}
			scope:local_clergy ?= {
				add_character_flag = {
					flag = used_in_theological_dispute
					months = 2
				}
			}
		}	
		#For background
		scope:challenge_character = {
			if = {
				limit = {
					is_ruler = no
					exists = court_owner
				}
				court_owner = { save_scope_as = bg_override_char }
			}
			else = {
				save_scope_as = bg_override_char
			}
		}
		scope:task_contract = {
			add_to_variable_list = {
				name = visited_disputers
				target = scope:challenge_character
			}
		}
		#Does the Holder exist and do they have an opinion of Employer?
		if = {
			limit = { exists = scope:local_holder }
			scope:local_holder ?= {
				if = {
					limit = {
						has_any_good_relationship_with_character_trigger = { CHARACTER = scope:employer }
					}
					save_scope_value_as = {
						name = local_mood
						value = flag:admiration
					}
				}
				else_if = {
					limit = {
						likes_character_trigger = { CHARACTER = scope:employer }
					}
					save_scope_value_as = {
						name = local_mood
						value = flag:thinking
					}
				}
				else_if = {
					limit = {
						has_any_mild_bad_relationship_with_character_trigger = { CHARACTER = scope:employer }
					}
					save_scope_value_as = {
						name = local_mood
						value = flag:disapproval
					}
				}	
				else_if = {
					limit = {
						has_any_bad_relationship_with_character_trigger = { CHARACTER = scope:employer }
					}
					save_scope_value_as = {
						name = local_mood
						value = flag:anger
					}
				}
				else = {
					save_scope_value_as = {
						name = local_mood
						value = flag:indifferent
					}
				}
			}
		}
		#Otherwise local mood tombola
		else = {
			random_list = {
				100 = {
					trigger = {
						trigger_if = {
							limit = {
								scope:task_contract = { has_variable = local_mood }
							}
							NOT = { scope:task_contract.var:local_mood ?= flag:disapproval }
						}
						trigger_else = { always = yes }
					}
					#No repeat moods, pls
					scope:task_contract = {
						set_variable = {
							name = local_mood
							value = flag:disapproval
						}
					}
					save_scope_value_as = {
						name = local_mood
						value = flag:disapproval
					}
				}
				100 = {
					trigger = {
						trigger_if = {
							limit = {
								scope:task_contract = { has_variable = local_mood }
							}
							NOT = { scope:task_contract.var:local_mood ?= flag:anger }
						}
						trigger_else = { always = yes }
					}
					scope:task_contract = {
						set_variable = {
							name = local_mood
							value = flag:anger
						}
					}
					save_scope_value_as = {
						name = local_mood
						value = flag:anger
					}
				}
				100 = {
					trigger = {
						trigger_if = {
							limit = {
								scope:task_contract = { has_variable = local_mood }
							}
							NOT = { scope:task_contract.var:local_mood ?= flag:admiration }
						}
						trigger_else = { always = yes }
					}
					scope:task_contract = {
						set_variable = {
							name = local_mood
							value = flag:admiration
						}
					}
					save_scope_value_as = {
						name = local_mood
						value = flag:admiration
					}
				}
				100 = {	
					trigger = {
						trigger_if = {
							limit = {
								scope:task_contract = { has_variable = local_mood }
							}
							NOT = { scope:task_contract.var:local_mood ?= flag:indifferent }
						}
						trigger_else = { always = yes }
					}
					scope:task_contract = {
						set_variable = {
							name = local_mood
							value = flag:indifferent
						}
					}
					save_scope_value_as = {
						name = local_mood
						value = flag:indifferent
					}
				}
				100 = {
					trigger = {
						trigger_if = {
							limit = {
								scope:task_contract = { has_variable = local_mood }
							}
							NOT = { scope:task_contract.var:local_mood ?= flag:thinking }
						}
						trigger_else = { always = yes }
					}
					scope:task_contract = {
						set_variable = {
							name = local_mood
							value = flag:thinking
						}
					}
					save_scope_value_as = {
						name = local_mood
						value = flag:thinking
					}
				}
			}
		}
		# Roll our background tombola.
		random_list = {
			100 = {
				trigger = {
					NOT = { exists = scope:local_holder }
					trigger_if = {
						limit = { 
							scope:task_contract = { has_variable = background }	
						}
						NOT = { scope:task_contract.var:background ?= flag:alley }
					}	
				}
				#No repeat backgrounds, pls
				scope:task_contract = {
					set_variable = {
						name = background
						value = flag:alley
					}
				}
			}
			100 = {
				trigger = {
					NOT = { exists = scope:local_holder }
					trigger_if = {
						limit = { 
							scope:task_contract = { has_variable = background }	
						}
						NOT = { scope:task_contract.var:background = flag:market }
					}
				}
				scope:task_contract = {
					set_variable = {
						name = background
						value = flag:market
					}
				}
			}
			100 = {
				trigger = {
					trigger_if = {
						limit = { 
							scope:task_contract = { has_variable = background }	
						}
						NOT = { scope:task_contract.var:background = flag:temple }
					}
				}
				scope:task_contract = {
					set_variable = {
						name = background
						value = flag:temple
					}
				}
			}
			100 = {
				trigger = {
					trigger_if = {
						limit = { 
							scope:task_contract = { has_variable = background }	
						}
						NOT = { scope:task_contract.var:background = flag:study }
					}
				}
				scope:task_contract = {
					set_variable = {
						name = background
						value = flag:study
					}
				}
			}
			100 = {
				trigger = {
					trigger_if = {
						limit = { 
							scope:task_contract = { has_variable = background }	
						}
						NOT = { scope:task_contract.var:background = flag:physician }
					}
				}
				scope:task_contract = {
					set_variable = {
						name = background
						value = flag:physician
					}
				}
			}
			100 = {
				trigger = {
					location = { is_coastal = yes }
					trigger_if = {
						limit = { 
							scope:task_contract = { has_variable = background }	
						}
						NOT = { scope:task_contract.var:background = flag:docks }
					}
				}
				scope:task_contract = {
					set_variable = {
						name = background
						value = flag:docks
					}
				}
			}
			100 = {
				trigger = {
					exists = scope:local_holder
					trigger_if = {
						limit = { 
							scope:task_contract = { has_variable = background }	
						}
						NOT = { scope:task_contract.var:background = flag:council_chamber }
					}
				}
				scope:task_contract = {
					set_variable = {
						name = background
						value = flag:council_chamber
					}
				}
			}
			100 = {
				trigger = {
					exists = scope:local_holder
					trigger_if = {
						limit = { 
							scope:task_contract = { has_variable = background }	
						}
						NOT = { scope:task_contract.var:background = flag:corridor }
					}
				}
				scope:task_contract = {
					set_variable = {
						name = background
						value = flag:corridor
					}
				}
			}
			100 = {
				trigger = {
					exists = scope:local_holder
					trigger_if = {
						limit = { 
							scope:task_contract = { has_variable = background }	
						}
						NOT = { scope:task_contract.var:background = flag:relaxing_room }
					}
				}
				scope:task_contract = {
					set_variable = {
						name = background
						value = flag:relaxing_room
					}
				}
			}
		}
		#Got a supportive priest?
		court_position:camp_priest_camp_officer ?= {
			if = {
				limit = {
					is_available_allow_travelling = yes
					location = root.location
				}
				if = {
					limit = {
						NOT = { has_character_flag = need_priest_outfit }
					}
					add_character_flag = {
						flag = need_priest_outfit
						days = 10
					}
				}
				save_scope_as = camp_priest
			}
		}
		#Check for religious traits that the holder doesn't have and that we haven't used them previously
		random_list = {
			25 = {
				trigger = { 
					has_trait = crusader_king
					NOR = {
						scope:task_contract = { has_variable = used_crusader_king_trait_var }
						scope:challenge_character ?= { has_trait = crusader_king }
					}
				}
				save_scope_value_as = {
					name = religious_trait
					value = flag:crusader_king
				}
			}
			10 = {
				trigger = { 
					has_trait = pilgrim
					has_trait_xp = {
						trait = pilgrim
						value >= 50 #Second tier
					}
					NOR = {
						scope:task_contract = { has_variable = used_pilgrim_trait_var }
						scope:challenge_character ?= { 
							has_trait = pilgrim
							has_trait_xp = {
								trait = pilgrim
								value >= 100 #Max tier
							}
						}
					}
				}
				save_scope_value_as = {
					name = religious_trait
					value = flag:pilgrim
				}
			}
			10 = {
				trigger = { 
					has_trait = faith_warrior
					NOR = {
						scope:task_contract = { has_variable = used_faith_warrior_trait_var }
						scope:challenge_character ?= { has_trait = faith_warrior }
					}
				}
				save_scope_value_as = {
					name = religious_trait
					value = flag:faith_warrior
				}
			}
			10 = {
				trigger = { 
					has_trait = chakravarti
					NOR = {
						scope:task_contract = { has_variable = used_chakravarti_trait_var }
						scope:challenge_character ?= { has_trait = chakravarti }
					}
				}
				save_scope_value_as = {
					name = religious_trait
					value = flag:chakravarti
				}
			}
			25 = {
				trigger = { 
					has_trait = saint
					NOR = {
						scope:task_contract = { has_variable = used_saint_trait_var }
						scope:challenge_character ?= { has_trait = saint }
					}
				}
				save_scope_value_as = {
					name = religious_trait
					value = flag:saint
				}
			}
			25 = {
				trigger = { 
					has_trait = savior
					NOR = {
						scope:task_contract = { has_variable = used_savior_trait_var }
						scope:challenge_character ?= { has_trait = savior }
					}
				}
				save_scope_value_as = {
					name = religious_trait
					value = flag:savior
				}
			}
			10 = {
				trigger = { 
					has_trait = sayyid
					NOR = {
						scope:task_contract = { has_variable = used_sayyid_trait_var }
						scope:challenge_character ?= { has_trait = sayyid }
					}
				}
				save_scope_value_as = {
					name = religious_trait
					value = flag:sayyid
				}
			}
			10 = {
				trigger = { 
					has_trait = saoshyant
					NOR = {
						scope:task_contract = { has_variable = used_saoshyant_trait_var }
						scope:challenge_character ?= { has_trait = saoshyant }
					}
				}
				save_scope_value_as = {
					name = religious_trait
					value = flag:saoshyant
				}
			}
			10 = {
				trigger = { 
					has_trait = paragon
					NOR = {
						scope:task_contract = { has_variable = used_paragon_trait_var }
						scope:challenge_character ?= { has_trait = paragon }
					}
				}
				save_scope_value_as = {
					name = religious_trait
					value = flag:paragon
				}
			}
		}
		#Calculate the piety cost
		if = {
			limit = {
				NOT = { exists = scope:task_contract.var:used_piety_count_var }
			}
			save_scope_value_as = {
				name = piety_cost
				value = medium_piety_gain
			}
		}
		else = {
			save_scope_value_as = {
				name = piety_cost
				value = {
					add = medium_piety_gain
					multiply = {
						value = scope:task_contract.var:used_piety_count_var
						add = 1
					}
				}
			}
		}
		# Plus, stop us whilst we're here.
		hidden_effect = {
			current_travel_plan ?= { pause_travel_plan = yes }
		}
		# Finally, tell us where our total is at.
		4014_show_score_effect = yes
		custom_tooltip = laamp_base_learning_contract_events.4015.tt.disputes_left
	}
	#Ye olde learning duel
	option = {
		name = laamp_base_learning_contract_events.4015.a
		skill = learning
		duel = {
			skill = learning
			target = scope:challenge_character
			# Victory!
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				min = 5
				desc = laamp_base_learning_contract_events.4015.a.success.tt
				send_interface_toast = {
					title = laamp_base_learning_contract_events.4015.a.success.t
					left_icon = root
					right_icon = scope:challenge_character
					4015_success_effect = yes
					4015_mayor_success_effect = yes
					add_piety = {
						value = {
							add = minor_piety_gain
							if = {
								limit = { 
									scope:task_contract = { has_variable = used_learning_count_var }
								}
								multiply = {
									value = scope:task_contract.var:used_learning_count_var
									add = 1
								}
							}		
							min = minor_piety_gain
						}
					}
				}
			}
			# Defeat!
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				min = 5
				desc = laamp_base_learning_contract_events.4015.a.failure.tt
				send_interface_toast = {
					title = laamp_base_learning_contract_events.4015.a.failure.t
					left_icon = root
					right_icon = scope:challenge_character
					4015_failure_effect = yes
				}
			}
		}
		#Diminishing returns
		scope:task_contract = {
			increment_variable_effect = {
				VAR = used_learning_count_var
				VAL = 1
			}
		}
		# The AI always plays it risky.
		ai_chance = { base = 50 }
	}	
	#Dynamic: Got Devotion Level to invoke? 100% / 25/75% / 50/50%
	option = {
		name = laamp_base_learning_contract_events.4015.b
		reason = piety_level
		random_list = {
			0 = {
				desc = laamp_base_learning_contract_events.4015.b.success.tt
				modifier = {
					add = 10
					piety_level <= 0
				}
				modifier = {
					add = 20
					piety_level = 1
				}
				modifier = {
					add = 40
					piety_level = 2
				}
				modifier = {
					add = 60
					piety_level = 3
				}
				modifier = {
					add = 80
					piety_level = 4
				}
				modifier = {
					add = 100
					piety_level >= 5
				}
				send_interface_toast = {
					title = laamp_base_learning_contract_events.4015.b.success.t
					left_icon = root
					right_icon = scope:challenge_character
					4015_success_effect = yes
					4015_mayor_success_effect = yes
					scope:challenge_character.faith = {
						change_fervor = {
							value = 1
							desc = fervor_gain_built_temple_holding
						}
					}
				}
			}
			0 = {
				desc = laamp_base_learning_contract_events.4015.b.failure.tt
				modifier = {
					add = 90
					piety_level <= 0
				}
				modifier = {
					add = 80
					piety_level = 1
				}
				modifier = {
					add = 60
					piety_level = 2
				}
				modifier = {
					add = 40
					piety_level = 3
				}
				modifier = {
					add = 20
					piety_level = 4
				}
				modifier = {
					add = 0
					piety_level >= 5
				}
				modifier = {
					add = {
						value = 10
						multiply = scope:task_contract.var:used_devotion_count_var
					}
					exists = scope:task_contract.var:used_devotion_count_var
				}
				send_interface_toast = {
					title = laamp_base_learning_contract_events.4015.b.failure.t
					left_icon = root
					right_icon = scope:challenge_character
					4015_failure_effect = yes
				}
			}
		}
		#Diminishing returns
		scope:task_contract = {
			increment_variable_effect = {
				VAR = used_devotion_count_var
				VAL = 1
			}
		}
		# The AI always plays it risky.
		ai_chance = { base = 0 }
	}
	#Triggered: Got a religious trait to use?
	option = {
		name = laamp_base_learning_contract_events.4015.c
		trigger = { exists = scope:religious_trait }
		reason = has_religious_trait
		4015_success_effect = yes
		#Got traits to stack?
		add_prestige = {
			value = {
				add = miniscule_prestige_gain
				if = {
					limit = { 
						scope:task_contract = { has_variable = used_trait_count_var }
					}
					multiply = {
						value = scope:task_contract.var:used_trait_count_var
						add = 1
					}
				}		
				min = miniscule_prestige_gain
			}
		}
		switch = {
			trigger = scope:religious_trait
			flag:crusader_king = {
				scope:task_contract = { set_variable = used_crusader_king_trait_var }
			}
			flag:pilgrim = {
				scope:task_contract = { set_variable = used_pilgrim_trait_var }
			}
			flag:faith_warrior = {
				scope:task_contract = { set_variable = used_faith_warrior_trait_var }
			}
			flag:chakravarti = {
				scope:task_contract = { set_variable = used_chakravarti_trait_var }
			}
			flag:saint = {
				scope:task_contract = { set_variable = used_saint_trait_var }
			}
			flag:savior = {
				scope:task_contract = { set_variable = used_savior_trait_var }
			}
			flag:sayyid = {
				scope:task_contract = { set_variable = used_sayyid_trait_var }
			}
			flag:saoshyant = {
				scope:task_contract = { set_variable = used_saoshyant_trait_var }
			}
			flag:paragon = {
				scope:task_contract = { set_variable = used_paragon_trait_var }
			}
		}
		scope:task_contract = {
			increment_variable_effect = {
				VAR = used_trait_count_var
				VAL = 1
			}
		}
		# The AI always plays it risky.
		ai_chance = { base = 0 }
	}
	#Triggered: Camp Priest
	option = {
		name = laamp_base_learning_contract_events.4015.d
		trigger = { exists = scope:camp_priest }
		reason = have_camp_priest
		random_list = {
			0 = {
				desc = laamp_base_learning_contract_events.4015.d.success.tt
				# Raw aptitude.
				modifier = {
					add = {
						scope:camp_priest ?= { add = "aptitude(camp_priest_camp_officer)" }
						multiply = 20
						min = 5
						max = 95
					}
					always = yes
				}
				send_interface_toast = {
					title = laamp_base_learning_contract_events.4015.d.success.t
					left_icon = scope:camp_priest
					right_icon = scope:challenge_character
					4015_success_effect = yes
					if = {
						limit = { has_lifestyle = learning_lifestyle }
						add_stewardship_lifestyle_xp = medium_lifestyle_xp
					}
					else = {
						add_piety = {
							value = miniscule_piety_gain
							if = {
								limit = {
									scope:task_contract = { has_variable = used_priest_count_var }
								}
								multiply = {
									value = scope:task_contract.var:used_priest_count_var
									add = 1
								}
								divide = 2
							}
							min = miniscule_piety_gain
						}
					}
					scope:camp_priest = {
						if = {
							limit = { has_lifestyle = learning_lifestyle }
							add_stewardship_lifestyle_xp = medium_lifestyle_xp
						}
						else = {
							add_piety = {
								value = miniscule_piety_gain
								if = {
									limit = {
										scope:task_contract = { has_variable = used_priest_count_var }
									}
									multiply = {
										value = scope:task_contract.var:used_priest_count_var
										add = 1
									}
									divide = 2
								}
								min = miniscule_piety_gain
							}
						}
					}
				}	
			}
			0 = {
				desc = laamp_base_learning_contract_events.4015.d.failure.tt
				modifier = {
					add = {
						value = 20
						multiply = scope:task_contract.var:used_priest_count_var
						min = 5
					}
					exists = scope:task_contract.var:used_priest_count_var
				}
				send_interface_toast = {
					title = laamp_base_learning_contract_events.4015.d.failure.t
					left_icon = scope:camp_priest
					right_icon = scope:challenge_character
					4015_failure_effect = yes
				}
			}
		}
		#Diminishing returns
		scope:task_contract = {
			increment_variable_effect = {
				VAR = used_priest_count_var
				VAL = 1
			}
		}
		# The AI always plays it risky.
		ai_chance = { base = 0 }
	}
	# Pay Piety?
	option = {
		name = laamp_base_learning_contract_events.4015.e
		trigger = { piety >= scope:piety_cost }
		flavor = laamp_base_learning_contract_events.4015.e.flavor
		reason = piety
		add_piety = {
			value = { subtract = scope:piety_cost }
		}
		4015_success_effect = yes
		#Diminishing returns
		scope:task_contract = {
			increment_variable_effect = {
				VAR = used_piety_count_var
				VAL = 1
			}
		}
		# The AI always plays it risky.
		ai_chance = { base = 0 }
	}
	# Or take Stress?
	option = {
		name = laamp_base_learning_contract_events.4015.e
		trigger = { piety < scope:piety_cost }
		flavor = laamp_base_learning_contract_events.4015.e.flavor
		stress_impact = {
			base = medium_stress_impact_gain
		}
		4015_success_effect = yes
		# The AI always plays it risky.
		ai_chance = { base = 0 }
	}
	#After
	after = {
		#Carry on
		hidden_effect = {
			current_travel_plan = { resume_travel_plan = yes }
		}
	}
}

#Conclusion
laamp_base_learning_contract_events.4017 = {
	type = character_event
	title = laamp_base_learning_contract_events.4017.t
	window = big_event_window
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:success_qualified }
				desc = laamp_base_learning_contract_events.4017.desc.success.qualified
			}
			triggered_desc = {
				trigger = { exists = scope:success_standard }
				desc = laamp_base_learning_contract_events.4017.desc.success.standard
			}
			triggered_desc = {
				trigger = { exists = scope:success_critical }
				desc = laamp_base_learning_contract_events.4017.desc.success.critical
			}
			desc = laamp_base_learning_contract_events.4017.desc.failure
		}
	}
	theme = learning
	center_portrait = {
		character = root
		triggered_animation = {
			trigger = { exists = scope:success_qualified }
			animation = thinking
		}
		triggered_animation = {
			trigger = { exists = scope:success_standard }
			animation = personality_compassionate
		}
		triggered_animation = {
			trigger = { exists = scope:success_critical }
			animation = personality_zealous
		}
		animation = shame
	}
	right_portrait = {
		character = scope:employer
		camera = camera_event_scheme_far_right
		triggered_animation = {
			trigger = { exists = scope:success_qualified }
			animation = personality_callous
		}
		triggered_animation = {
			trigger = { exists = scope:success_standard }
			animation = admiration
		}
		triggered_animation = {
			trigger = { exists = scope:success_critical }
			animation = ecstasy
		}
		animation = disapproval
	}
	override_background = { reference = throne_room }
	#Time's up
	trigger = { scope:task_contract.var:opportunities_left_tally = 0 }
	immediate = {
		scope:task_contract = {
			ordered_in_list = {
				variable = visited_disputers
				order_by = {
					value = "opinion(scope:employer)"
					multiply = -1
					if = {
						limit = { highest_held_title_tier >= tier_barony }
						add = 100
					}
				}
				save_scope_as = mentioned_disputee
			}
		}
		#For background
		scope:employer = { save_scope_as = bg_override_char }
		if = {
			limit = { scope:task_contract.var:wins_tally >= scope:task_contract.var:win_t3_threshold }
			save_scope_as = success_critical
		}
		else_if = {
			limit = { scope:task_contract.var:wins_tally >= scope:task_contract.var:win_t2_threshold }
			save_scope_as = success_standard
		}
		else_if = {
			limit = { scope:task_contract.var:wins_tally >= scope:task_contract.var:win_t1_threshold }
			save_scope_as = success_qualified
		}
		else = { save_scope_as = failure_standard }
		# Plus, stop us whilst we're here.
		hidden_effect = {
			current_travel_plan ?= { pause_travel_plan = yes }
		}
		# Finally, tell us where our total is at.
		4014_show_score_effect = yes
	}
	#Triggered option: You have less than Success Qualified - Start debating to get a qualified success
	option = {
		name = laamp_base_learning_contract_events.4017.a
		trigger = { scope:task_contract.var:wins_tally < scope:task_contract.var:win_t1_threshold }
		duel = {
			skills = { learning intrigue }
			target = scope:employer
			# Victory!
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				min = 5
				desc = laamp_base_learning_contract_events.4017.a.success.tt
				scope:task_contract = { complete_task_contract = success_qualified }
			}
			# Defeat!
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				min = 5
				desc = laamp_base_learning_contract_events.4017.a.failure.tt
				scope:task_contract = { complete_task_contract = failure_standard }
				#If we have literally 0
				if = {
					limit = {
						OR = {
							AND = {
								scope:task_contract.var:win_t1_threshold = 2
								scope:task_contract.var:wins_tally = 0
							}
							AND = {
								scope:task_contract.var:win_t1_threshold = 1
								scope:task_contract.var:wins_tally = 0
							}
						}
					}
					add_stress = {
						value = {
							add = massive_stress_impact_gain
							multiply = 0.8
						}
					}
				}
				#Else we should have 1 out of 2 for a Qualified Success
				else = { add_stress = medium_stress_impact_gain }	
			}
		}
		#*shrug*
		ai_chance = {
			base = 100
		}
	}
	#Yup, yup...
	option = {
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = { exists = scope:success_qualified }
						desc = laamp_base_learning_contract_events.4017.b.success_qualified
					}
					triggered_desc = {
						trigger = { exists = scope:success_standard }
						desc = laamp_base_learning_contract_events.4017.b.success_standard
					}
					triggered_desc = {
						trigger = { exists = scope:success_critical }
						desc = laamp_base_learning_contract_events.4017.b.success_critical
					}
					desc = laamp_base_learning_contract_events.4017.b.failure_standard
				}
			}
		}
		scope:task_contract = {
			if = {
				limit = { exists = scope:success_qualified }
				complete_task_contract = success_qualified
			}
			else_if = {
				limit = { exists = scope:success_standard }
				complete_task_contract = success_standard
			}
			else_if = {
				limit = { exists = scope:success_critical }
				complete_task_contract = success_critical
			}
			else = { complete_task_contract = failure_standard }
		}
		#*shrug*
		ai_chance = {
			base = 100
		}
	}
	after = { 
		remove_character_flag ?= is_in_task_contract_event_chain
		#Carry on
		hidden_effect = { current_travel_plan ?= { resume_travel_plan = yes } }
	}
}



##################################################
# Create a work of learning
# 4021 - 4027
############################################

scripted_trigger 4025_has_multiple_talents_trigger = {
	calc_true_if = {
		amount >= 2
		4025_is_skilled_in_diplomacy_trigger = yes
		4025_is_skilled_in_martial_trigger = yes
		4025_is_skilled_in_stewardship_trigger = yes
		4025_is_skilled_in_intrigue_trigger = yes
		4025_is_skilled_traveler_trigger = yes
		4025_is_skilled_pilgrim_trigger = yes
		4025_has_max_poi_trigger = yes
	}
}

scripted_effect 4021_variable_setup_effect = {
	scope:task_contract = {
		increment_variable_effect = {
			VAR = wins_tally
			VAL = 0
		}
		increment_variable_effect = {
			VAR = chapters_left
			VAL = $TIER_3$
		}
		increment_variable_effect = {
			VAR = chapters_attempted
			VAL = 0
		}
		### Victory tiers.
		increment_variable_effect = {
			VAR = win_t1_threshold
			VAL = $TIER_1$
		}
		increment_variable_effect = {
			VAR = win_t2_threshold
			VAL = $TIER_2$
		}
		increment_variable_effect = {
			VAR = win_t3_threshold
			VAL = $TIER_3$
		}
	}
}

scripted_effect 4021_roll_for_prefered_topic_effect = {
	random_list = {
		10 = {
			trigger = { 
				root = { 4025_is_skilled_in_diplomacy_trigger = yes }
				#Don't roll the same topic again
				trigger_if = {
					limit = { has_variable = temp_old_prefered_topic }
					NOT = { var:temp_old_prefered_topic = flag:diplomacy }
				}
				trigger_else = { always = yes }
			}
			set_variable = {
				name = prefered_topic
				value = flag:diplomacy
			}
		}
		10 = {
			trigger = { 
				root = { 4025_is_skilled_in_martial_trigger = yes }
				trigger_if = {
					limit = { has_variable = temp_old_prefered_topic }
					NOT = { var:temp_old_prefered_topic = flag:martial }
				}
				trigger_else = { always = yes }
			}
			set_variable = {
				name = prefered_topic
				value = flag:martial
			}
		}
		10 = {
			trigger = { 
				root = { 4025_is_skilled_in_stewardship_trigger = yes }
				trigger_if = {
					limit = { has_variable = temp_old_prefered_topic }
					NOT = { var:temp_old_prefered_topic = flag:stewardship }
				}
				trigger_else = { always = yes }
			}
			set_variable = {
				name = prefered_topic
				value = flag:stewardship
			}
		}
		10 = {
			trigger = { 
				root = { 4025_is_skilled_in_intrigue_trigger = yes }
				trigger_if = {
					limit = { has_variable = temp_old_prefered_topic }
					NOT = { var:temp_old_prefered_topic = flag:intrigue }
				}
				trigger_else = { always = yes }
			}
			set_variable = {
				name = prefered_topic
				value = flag:intrigue
			}
		}
		5 = {
			trigger = {
				trigger_if = {
					limit = { has_variable = temp_old_prefered_topic }
					NOT = { var:temp_old_prefered_topic = flag:learning }
				}
				trigger_else = { always = yes }
			}
			set_variable = {
				name = prefered_topic
				value = flag:learning
			}
		}
		10 = {
			trigger = { 
				root = { 4025_is_skilled_traveler_trigger = yes }
				trigger_if = {
					limit = { has_variable = temp_old_prefered_topic }
					NOT = { var:temp_old_prefered_topic = flag:travel }
				}
				trigger_else = { always = yes }
			}
			set_variable = {
				name = prefered_topic
				value = flag:travel
			}
		}
		10 = {
			trigger = { 
				root = { 4025_is_skilled_pilgrim_trigger = yes }
				trigger_if = {
					limit = { has_variable = temp_old_prefered_topic }
					NOT = { var:temp_old_prefered_topic = flag:pilgrimage }
				}
				trigger_else = { always = yes }
			}
			set_variable = {
				name = prefered_topic
				value = flag:pilgrimage
			}
		}
		15 = {
			trigger = { 
				root = { 4025_has_max_poi_trigger = yes }
				#No getting inspired about POI
				NOT = { has_variable = temp_old_prefered_topic }
			}
			set_variable = {
				name = prefered_topic
				value = flag:poi
			}
		}
	}
}

#How many Chapters?
laamp_base_learning_contract_events.4021 = { 
	type = character_event
	title = laamp_base_learning_contract_events.4021.t
	window = big_event_window
	desc = laamp_base_learning_contract_events.4021.desc
	theme = learning
	center_portrait = {
		character = root
		animation = page_flipping
	}
	override_background = { reference = study }
	immediate = {
		#For background
		scope:employer = { save_scope_as = bg_override_char }
		#Tombola to determine what our Employer would like
		if = {
			limit = {
				scope:task_contract = {
					NOT = { has_variable = prefered_topic }
				}
				#Only if we have something else we would excel in
				4025_has_multiple_talents_trigger = yes
			}
			scope:task_contract = { 4021_roll_for_prefered_topic_effect = yes }
		}
		# Plus, stop us whilst we're here.
		hidden_effect = {
			current_travel_plan ?= { pause_travel_plan = yes }
		}
		custom_tooltip = laamp_base_learning_contract_events.4021.tt.chapter_explanation
		custom_tooltip = laamp_base_learning_contract_events.4021.tt.explanation
	}
	#3 Chapters, please
	option = {
		name = laamp_base_learning_contract_events.4021.a
		custom_tooltip = laamp_base_learning_contract_events.4021.a.tt
		4021_variable_setup_effect = {
			TIER_1 = 1
			TIER_2 = 2
			TIER_3 = 3
		}
		#Nothing to see here
		ai_chance = {
			base = 100
		}
	}
	#5 Chapters!
	option = {
		name = laamp_base_learning_contract_events.4021.b
		custom_tooltip = laamp_base_learning_contract_events.4021.b.tt
		4021_variable_setup_effect = {
			TIER_1 = 2
			TIER_2 = 4
			TIER_3 = 5
		}
		#Nothing to see here
		ai_chance = {
			base = 100
		}
	}
	after = {
		trigger_event = {
			id = laamp_base_learning_contract_events.4025
			days = 1
		}
	}
}

scripted_trigger 4025_is_skilled_in_diplomacy_trigger = {
	OR = {
		diplomacy >= medium_skill_rating
		has_trait = diplomat
		has_trait = family_first
		has_trait = august
	}
}

scripted_trigger 4025_is_skilled_in_martial_trigger = {
	OR = {
		martial >= medium_skill_rating
		has_trait = strategist
		has_trait = overseer
		has_trait = gallant
	}
}

scripted_trigger 4025_is_skilled_in_stewardship_trigger = {
	OR = {
		stewardship >= medium_skill_rating
		has_trait = architect
		has_trait = administrator
		has_trait = avaricious
	}
}

scripted_trigger 4025_is_skilled_in_intrigue_trigger = {
	OR = {
		intrigue >= medium_skill_rating
		has_trait = schemer
		has_trait = seducer
		has_trait = torturer
	}
}

scripted_trigger 4025_is_skilled_traveler_trigger = {
	AND = {
		has_trait = lifestyle_traveler
		has_trait_xp = {
			trait = lifestyle_traveler
			track = travel
			value >= 60
		}
	}
}

scripted_trigger 4025_is_skilled_pilgrim_trigger = {
	AND = {
		has_trait = pilgrim
		has_trait_xp = {
			trait = pilgrim
			value >= 60
		}
	}
}

scripted_trigger 4025_has_max_poi_trigger = {
	trigger_if = {
		limit = { has_variable = poi_visited }
		var:poi_visited >= 50
	}
	trigger_else = { always = no }
}

scripted_trigger 4025_prefered_topic_trigger = {
	scope:task_contract = { 
		has_variable = prefered_topic
		var:prefered_topic = $TOPIC$
	}
}

scripted_trigger 4025_has_traveler_trait_xp_trigger = {
	has_trait = lifestyle_traveler
	has_trait_xp = {
		trait = lifestyle_traveler
		track = travel
		value >= $VALUE$
	}
}

scripted_trigger 4025_has_pilgrim_trait_xp_trigger = {
	has_trait = pilgrim
	has_trait_xp = {
		trait = pilgrim
		value >= $VALUE$
	}
}

scripted_trigger 4025_is_final_shot_trigger = {
	scope:task_contract = {
		var:win_t3_threshold ?= 5
		var:chapters_attempted ?= 4
		var:wins_tally ?= 0
	}
}

scripted_trigger 4025_has_applicable_skills_for_additional_event_options_trigger = {
	OR = {
		AND = {
			root = { 4025_is_skilled_in_diplomacy_trigger = yes }
			NOT = {
				is_target_in_variable_list = {
					name = event_option_list
					target = flag:has_diplomacy_option
				}	
			}
		}
		AND = {
			root = { 4025_is_skilled_in_martial_trigger = yes }
			NOT = {
				is_target_in_variable_list = {
					name = event_option_list
					target = flag:has_martial_option
				}	
			}
		}
		AND = {
			root = { 4025_is_skilled_in_stewardship_trigger = yes }
			NOT = {
				is_target_in_variable_list = {
					name = event_option_list
					target = flag:has_stewardship_option
				}	
			}
		}
		AND = {
			root = { 4025_is_skilled_in_intrigue_trigger = yes }
			NOT = {
				is_target_in_variable_list = {
					name = event_option_list
					target = flag:has_intrigue_option
				}	
			}
		}
		AND = {
			root = { 4025_is_skilled_traveler_trigger = yes }
			NOT = {
				is_target_in_variable_list = {
					name = event_option_list
					target = flag:has_traveler_option
				}	
			}
		}
		AND = {
			root = { 4025_is_skilled_pilgrim_trigger = yes }
			NOT = {
				is_target_in_variable_list = {
					name = event_option_list
					target = flag:has_pilgrimage_option
				}	
			}
		}
		AND = {
			root = { 4025_has_max_poi_trigger = yes }
			NOT = {
				is_target_in_variable_list = {
					name = event_option_list
					target = flag:has_poi_option
				}	
			}
		}
	}
}

scripted_effect 4025_show_score_effect = {
	if = {
		limit = { scope:task_contract.var:wins_tally < scope:task_contract.var:win_t1_threshold }
		custom_tooltip = laamp_base_learning_contract_events.4025.tt.current_total.sub_t1
	}
	else_if = {
		limit = { scope:task_contract.var:wins_tally < scope:task_contract.var:win_t2_threshold }
		custom_tooltip = laamp_base_learning_contract_events.4025.tt.current_total.sub_t2
	}
	else_if = {
		limit = { scope:task_contract.var:wins_tally < scope:task_contract.var:win_t3_threshold }
		custom_tooltip = laamp_base_learning_contract_events.4025.tt.current_total.sub_t3
	}
}

scripted_effect 4025_success_effect = {
	scope:task_contract = {
		increment_variable_effect = {
			VAR = wins_tally
			VAL = 1
		}
	}
	custom_tooltip = laamp_base_learning_contract_events.4025.tt.progress_towards_success
	if = {
		limit = { 
			$REWARD$ = yes 
			scope:task_contract.var:chapters_attempted = 4
		}
		random = {
			chance = 5
			modifier = {
				factor = {
					value = scope:task_contract.var:wins_tally
					add = 1
				}
				always = yes
			}
			random_list = {
				10 = {
					trigger = { scope:task_contract.var:skill_to_learn_var ?= flag:diplomacy }
					show_chance = no
					add_diplomacy_skill = 1			
				}
				10 = {
					trigger = { scope:task_contract.var:skill_to_learn_var ?= flag:martial }
					show_chance = no
					add_martial_skill = 1		
				}
				10 = {
					trigger = { scope:task_contract.var:skill_to_learn_var ?= flag:stewardship }
					show_chance = no
					add_stewardship_skill = 1			
				}
				10 = {
					trigger = { scope:task_contract.var:skill_to_learn_var ?= flag:intrigue }
					show_chance = no
					add_intrigue_skill = 1
											
				}
				10 = {
					trigger = { scope:task_contract.var:skill_to_learn_var ?= flag:learning }
					show_chance = no
					add_learning_skill = 1			
				}
			}
		}
	}
}

scripted_effect 4025_failure_effect = { custom_tooltip = laamp_base_learning_contract_events.4025.tt.no_progress }

scripted_effect 4025_find_applicable_event_options_effect = {
	random_list = {
		10 = {
			trigger = { 
				root = { 4025_is_skilled_in_diplomacy_trigger = yes }
				NOT = {
					is_target_in_variable_list = {
						name = event_option_list
						target = flag:has_diplomacy_option
					}	
				}
			}
			modifier = {
				add = scope:employer.diplomacy
				always = yes
			}
			add_to_variable_list = {
				name = event_option_list
				target = flag:has_diplomacy_option
			}
		}
		10 = {
			trigger = { 
				root = { 4025_is_skilled_in_martial_trigger = yes }
				NOT = {
					is_target_in_variable_list = {
						name = event_option_list
						target = flag:has_martial_option
					}	
				}
			}
			modifier = {
				add = scope:employer.martial
				always = yes
			}
			add_to_variable_list = {
				name = event_option_list
				target = flag:has_martial_option
			}
		}
		10 = {
			trigger = { 
				root = { 4025_is_skilled_in_stewardship_trigger = yes }
				NOT = {
					is_target_in_variable_list = {
						name = event_option_list
						target = flag:has_stewardship_option
					}	
				}
			}
			modifier = {
				add = scope:employer.stewardship
				always = yes
			}
			add_to_variable_list = {
				name = event_option_list
				target = flag:has_stewardship_option
			}
		}
		10 = {
			trigger = { 
				root = { 4025_is_skilled_in_intrigue_trigger = yes }
				NOT = {
					is_target_in_variable_list = {
						name = event_option_list
						target = flag:has_intrigue_option
					}	
				}
			}
			modifier = {
				add = scope:employer.intrigue
				always = yes
			}
			add_to_variable_list = {
				name = event_option_list
				target = flag:has_intrigue_option
			}
		}
		10 = {
			trigger = { 
				root = { 4025_is_skilled_traveler_trigger = yes }
				NOT = {
					is_target_in_variable_list = {
						name = event_option_list
						target = flag:has_traveler_option
					}	
				}
			}
			modifier = {
				add = 20
				scope:employer = { has_trait = lifestyle_traveler }
			}
			add_to_variable_list = {
				name = event_option_list
				target = flag:has_traveler_option
			}
		}
		10 = {
			trigger = { 
				root = { 4025_is_skilled_pilgrim_trigger = yes }
				NOT = {
					is_target_in_variable_list = {
						name = event_option_list
						target = flag:has_pilgrimage_option
					}	
				}
			}
			modifier = {
				add = 20
				scope:employer = { has_trait = pilgrim }
			}
			add_to_variable_list = {
				name = event_option_list
				target = flag:has_pilgrimage_option
			}
		}
		10 = {
			trigger = { 
				root = { 4025_has_max_poi_trigger = yes }
				NOT = {
					is_target_in_variable_list = {
						name = event_option_list
						target = flag:has_poi_option
					}	
				}
			}
			modifier = {
				add = 20
				scope:employer = { has_variable = poi_visited }
			}
			add_to_variable_list = {
				name = event_option_list
				target = flag:has_poi_option
			}
		}
	}
}

scripted_effect 4025_roll_for_event_options_effect = {
	#Make sure we always have the prefered topic option
	if = {
		limit = { has_variable = prefered_topic }
		switch = {
			trigger = var:prefered_topic
			flag:diplomacy = {
				add_to_variable_list = {
					name = event_option_list
					target = flag:has_diplomacy_option
				}
			}
			flag:martial = {
				add_to_variable_list = {
					name = event_option_list
					target = flag:has_martial_option
				}
			}
			flag:stewardship = {
				add_to_variable_list = {
					name = event_option_list
					target = flag:has_stewardship_option
				}
			}
			flag:intrigue = {
				add_to_variable_list = {
					name = event_option_list
					target = flag:has_intrigue_option
				}
			}
			flag:travel = {
				add_to_variable_list = {
					name = event_option_list
					target = flag:has_traveler_option
				}
			}
			flag:pilgrimage = {
				add_to_variable_list = {
					name = event_option_list
					target = flag:has_pilgrimage_option
				}
			}
			flag:poi = {
				add_to_variable_list = {
					name = event_option_list
					target = flag:has_poi_option
				}
			}
		}
	}
	#And fill up the rest so that we have up to 5 options
	while = {
		limit = { 
			4025_has_applicable_skills_for_additional_event_options_trigger = yes
			variable_list_size = {
				name = event_option_list
				value <= 4
			}
		}
		4025_find_applicable_event_options_effect = yes
	}
}

scripted_effect 4025_add_prestige_reward_effect = {
	add_prestige = {
		value = {
			value = $VALUE$
			divide = 2
			multiply = {
				value = scope:task_contract.var:chapters_attempted
				add = 1
			}
			if = {
				limit = { 
					4025_prefered_topic_trigger = { TOPIC = flag:$TOPIC$ }
				}
				multiply = 1.5
			}
		}
	}
}

scripted_effect 4025_add_gold_reward_effect = {
	add_gold = {
		value = {
			value = $VALUE$
			divide = 2
			multiply = {
				value = scope:task_contract.var:chapters_attempted
				add = 1
			}
			if = {
				limit = { 
					4025_prefered_topic_trigger = { TOPIC = flag:$TOPIC$ }
				}
				multiply = 1.5
			}
			min = 5
		}
	}
}

scripted_effect 4025_add_provisions_reward_effect = {
	domicile = {
		change_provisions = {
			value = {
				value = $VALUE$
				multiply = {
					value = scope:task_contract.var:chapters_attempted
					add = 1
				}
				if = {
					limit = { 
						4025_prefered_topic_trigger = { TOPIC = flag:$TOPIC$ }
					}
					multiply = 1.5
				}
				min = 25
			}
		}
	}
}

scripted_effect 4025_add_piety_reward_effect = {
	add_piety = {
		value = {
			value = $VALUE$
			divide = 2
			multiply = {
				value = scope:task_contract.var:chapters_attempted
				add = 1
			}
			if = {
				limit = { 
					4025_prefered_topic_trigger = { TOPIC = flag:$TOPIC$ }
				}
				multiply = 1.5
			}
		}
	}
}

scripted_effect 4025_generic_skill_duel_effect = {
	if = {
		limit = { $SKILL$ = learning }
		duel = {
			skill = $SKILL$
			value = medium_skill_rating
			# Victory!
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				min = 5
				desc = laamp_base_learning_contract_events.4025.success.tt
				send_interface_toast = {
					title = laamp_base_learning_contract_events.4025.success.t
					left_icon = root
					4025_success_effect = { REWARD = yes }
					4025_add_piety_reward_effect = {
						TOPIC = $SKILL$
						VALUE = minor_piety_gain
					}
				}
			}
			# Defeat!
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				modifier = {
					add = {
						value = 10
						multiply = scope:task_contract.var:chapters_attempted
					}
					always = yes
				}
				min = 5
				desc = laamp_base_learning_contract_events.4025.failure.tt
				send_interface_toast = {
					title = laamp_base_learning_contract_events.4025.failure.t
					left_icon = root
					4025_failure_effect = yes
				}
			}
		}
	}
	else = {
		duel = {
			skills = { learning $SKILL$ }
			value = medium_skill_rating
			# Victory!
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				min = 5
				desc = laamp_base_learning_contract_events.4025.success.tt
				send_interface_toast = {
					title = laamp_base_learning_contract_events.4025.success.t
					left_icon = root
					if = {
						limit = { $SKILL$ = diplomacy }
						4025_success_effect = { REWARD = yes }
						4025_add_prestige_reward_effect = { 
							TOPIC = $SKILL$ 
							VALUE = miniscule_prestige_gain 
						}
						4025_add_gold_reward_effect = { 
							TOPIC = $SKILL$ 
							VALUE = miniscule_gold_laamps_value 
						}
					}
					if = {
						limit = { $SKILL$ = martial }
						4025_success_effect = { REWARD = yes }
						4025_add_prestige_reward_effect = { 
							TOPIC = $SKILL$ 
							VALUE = minor_prestige_gain 
						}
					}
					if = {
						limit = { $SKILL$ = stewardship }
						4025_success_effect = { REWARD = yes }
						4025_add_gold_reward_effect = { 
							TOPIC = $SKILL$ 
							VALUE = tiny_gold_laamps_value 
						}
					}
					if = {
						limit = { $SKILL$ = intrigue }
						4025_success_effect = { REWARD = yes }
						4025_add_gold_reward_effect = { 
							TOPIC = $SKILL$ 
							VALUE = miniscule_gold_laamps_value 
						}
						if = {
							limit = {
								domicile ?= { provisions < max_provisions }
							}
							4025_add_provisions_reward_effect = { 
								TOPIC = $SKILL$ 
								VALUE = task_contract_failure_provisions_gain_minor_value
							}
						}
					}
				}
			}
			# Defeat!
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				modifier = {
					add = {
						value = 10
						multiply = scope:task_contract.var:chapters_attempted
					}
					always = yes
				}
				min = 5
				desc = laamp_base_learning_contract_events.4025.failure.tt
				send_interface_toast = {
					title = laamp_base_learning_contract_events.4025.failure.t
					left_icon = root
					4025_failure_effect = yes
				}
			}
		}
	}
}

#Create a work of learning
laamp_base_learning_contract_events.4025 = { 
	type = character_event
	title = {
		first_valid = {
			#First
			triggered_desc = {
				trigger = { scope:task_contract.var:chapters_attempted = 0 }
				desc = laamp_base_learning_contract_events.4025.t.first
			}
			#Second to last
			triggered_desc = {
				trigger = { scope:task_contract.var:chapters_attempted = scope:task_contract.var:win_t2_threshold }
				desc = laamp_base_learning_contract_events.4025.t.last
			}
			desc = laamp_base_learning_contract_events.4025.t
		}
	}
	window = big_event_window
	desc = {
		#Intro
		first_valid = {
			#First
			triggered_desc = {
				trigger = { scope:task_contract.var:chapters_attempted = 0 }
				desc = laamp_base_learning_contract_events.4025.desc.intro.first
			}
			#Final shot
			triggered_desc = {
				trigger = { 4025_is_final_shot_trigger = yes }
				desc = laamp_base_learning_contract_events.4025.desc.intro.final_shot
			}
			#Second to last
			triggered_desc = {
				trigger = { scope:task_contract.var:chapters_attempted = scope:task_contract.var:win_t2_threshold }
				desc = laamp_base_learning_contract_events.4025.desc.intro.last
			}
			#A thought suddenly strikes me
			triggered_desc = {
				trigger = {
					scope:task_contract = {
						NOR = {
							var:chapters_attempted ?= 0
							var:chapters_attempted ?= scope:task_contract.var:win_t2_threshold
						}
						has_variable = temp_old_prefered_topic
					} 
				}
				desc = laamp_base_learning_contract_events.4025.desc.intro.inspiration
			}
			random_valid = {
				triggered_desc = {
					trigger = {
						OR = {
							scope:task_contract.var:loc_variation = 1
							scope:task_contract.var:loc_variation = 2
						}
					}
					desc = laamp_base_learning_contract_events.4025.desc.intro.01
				}
				triggered_desc = {
					trigger = {
						OR = {
							scope:task_contract.var:loc_variation = 2
							scope:task_contract.var:loc_variation = 3
						}
					}
					desc = laamp_base_learning_contract_events.4025.desc.intro.02
				}
				triggered_desc = {
					trigger = {
						OR = {
							scope:task_contract.var:loc_variation = 3
							scope:task_contract.var:loc_variation = 1
						}
					}
					desc = laamp_base_learning_contract_events.4025.desc.intro.03
				}
			}
		}
		desc = boilerplate.paragraph
		#Mid
		first_valid = {
			#First
			triggered_desc = {
				trigger = { scope:task_contract.var:chapters_attempted = 0 }
				desc = laamp_base_learning_contract_events.4025.desc.first
			}
			#Final shot
			triggered_desc = {
				trigger = { 4025_is_final_shot_trigger = yes }
				desc = laamp_base_learning_contract_events.4025.desc.final_shot
			}
			#Second to last
			triggered_desc = {
				trigger = { scope:task_contract.var:chapters_attempted = scope:task_contract.var:win_t2_threshold }
				desc = laamp_base_learning_contract_events.4025.desc.last
			}
			random_valid = {
				desc = laamp_base_learning_contract_events.4025.desc.01
				desc = laamp_base_learning_contract_events.4025.desc.02
				desc = laamp_base_learning_contract_events.4025.desc.03
			}
		}
		desc = boilerplate.paragraph
		#Outro
		first_valid = {
			#First, prefered topic
			triggered_desc = {
				trigger = { 
					scope:task_contract.var:chapters_attempted = 0
					scope:task_contract = { has_variable = prefered_topic } 
				}
				desc = laamp_base_learning_contract_events.4025.desc.outro.first.has_topic
			}
			#First, no topic
			triggered_desc = {
				trigger = { scope:task_contract.var:chapters_attempted = 0 }
				desc = laamp_base_learning_contract_events.4025.desc.outro.first.no_topic
			}
			#Final shot
			triggered_desc = {
				trigger = { 4025_is_final_shot_trigger = yes }
				desc = laamp_base_learning_contract_events.4025.desc.outro.final_shot
			}
			random_valid = {
				desc = laamp_base_learning_contract_events.4025.desc.outro.01
				desc = laamp_base_learning_contract_events.4025.desc.outro.02
				desc = laamp_base_learning_contract_events.4025.desc.outro.03
			}	
		}
	}
	theme = learning
	center_portrait = {
		character = root
		triggered_animation = {
			trigger = { 4025_is_final_shot_trigger = yes }
			animation = worry
		}
		triggered_animation = {
			trigger = { scope:task_contract.var:chapters_attempted = 0 }
			animation = thinking
		}
		triggered_animation = {
			trigger = { scope:task_contract.var:animation_var ?= flag:writing }
			animation = writing
		}
		triggered_animation = {
			trigger = { scope:task_contract.var:animation_var ?= flag:stressed_teacher }
			animation = stressed_teacher
		}
		triggered_animation = {
			trigger = { scope:task_contract.var:animation_var ?= flag:page_flipping }
			animation = page_flipping
		}
		triggered_animation = {
			trigger = { scope:task_contract.var:animation_var ?= flag:happy_teacher }
			animation = happy_teacher
		}
		triggered_animation = {
			trigger = { scope:task_contract.var:animation_var ?= flag:steward }
			animation = steward
		}
		triggered_animation = {
			trigger = { scope:task_contract.var:animation_var ?= flag:chess_cocky }
			animation = chess_cocky
		}
		triggered_animation = {
			trigger = { scope:task_contract.var:animation_var ?= flag:spymaster }
			animation = spymaster
		}
		animation = reading
	}
	override_background = { reference = study }
	immediate = {
		#For background
		scope:employer = { save_scope_as = bg_override_char }
		scope:task_contract = {
			#Randomize the skill gain for if we get a perfect run
			if = {
				limit = { 
					var:win_t3_threshold ?= 5
					NOT = { has_variable = skill_to_learn_var }
				}
				random_list = {
					10 = {
						set_variable = {
							name = skill_to_learn_var
							value = flag:diplomacy
						}			
					}
					10 = {
						set_variable = {
							name = skill_to_learn_var
							value = flag:martial
						}			
					}
					10 = {
						set_variable = {
							name = skill_to_learn_var
							value = flag:stewardship
						}			
					}
					10 = {
						set_variable = {
							name = skill_to_learn_var
							value = flag:intrigue
						}			
					}
					10 = {
						set_variable = {
							name = skill_to_learn_var
							value = flag:learning
						}			
					}
				}
			}
			#Vary the animations
			random_list = {
				10 = {
					trigger = {
						trigger_if = {
							limit = { has_variable = animation_var }
							NOT = { var:animation_var ?= flag:writing }
						}
						trigger_else = { always = yes }
					}
					set_variable = {
						name = animation_var
						value = flag:writing
					}
				}
				10 = {
					trigger = {
						trigger_if = {
							limit = { has_variable = animation_var }
							NOT = { var:animation_var ?= flag:stressed_teacher }
						}
						trigger_else = { always = yes }
					}
					set_variable = {
						name = animation_var
						value = flag:stressed_teacher
					}
				}
				10 = {
					trigger = {
						trigger_if = {
							limit = { has_variable = animation_var }
							NOT = { var:animation_var ?= flag:page_flipping }
						}
						trigger_else = { always = yes }
					}
					set_variable = {
						name = animation_var
						value = flag:page_flipping
					}
				}
				10 = {
					trigger = {
						trigger_if = {
							limit = { has_variable = animation_var }
							NOT = { var:animation_var ?= flag:happy_teacher }
						}
						trigger_else = { always = yes }
						AND = {
							has_variable = wins_tally
							NOT = { var:wins_tally < var:win_t1_threshold }
						}
					}
					set_variable = {
						name = animation_var
						value = flag:happy_teacher
					}
				}
				10 = {
					trigger = {
						trigger_if = {
							limit = { has_variable = animation_var }
							NOT = { var:animation_var ?= flag:steward }
						}
						trigger_else = { always = yes }
						root = { highest_skill = stewardship }
					}
					set_variable = {
						name = animation_var
						value = flag:steward
					}
				}
				20 = {
					trigger = {
						trigger_if = {
							limit = { has_variable = animation_var }
							NOT = { var:animation_var ?= flag:chess_cocky }
						}
						trigger_else = { always = yes }
						root = { highest_skill = martial }
					}
					set_variable = {
						name = animation_var
						value = flag:chess_cocky
					}
				}
				20 = {
					trigger = {
						trigger_if = {
							limit = { has_variable = animation_var }
							NOT = { var:animation_var ?= flag:spymaster }
						}
						trigger_else = { always = yes }
						root = { highest_skill = intrigue }
					}
					set_variable = {
						name = animation_var
						value = flag:spymaster
					}
				}			
			}
			#Vary the loc :rolleyes:
			set_variable = {
				name = loc_variation
				value = {
					integer_range = {
						min = 1
						max = 3
					}
				}
			}
			#Clear old options
			clear_variable_list ?= event_option_list
			#Exists check are more fickle than... a suitable metaphor... so doing this instead :catstare:
			add_to_variable_list = {
				name = event_option_list
				target = flag:dummy
			}
			#Error suppression :scree:
			if = {
				limit = {
					is_target_in_variable_list = {
						name = event_option_list
						target = flag:dummy
					}
				}
			}
			#What event options do we have this time?
			4025_roll_for_event_options_effect = yes
		}
		# Finally, tell us where our total is at.
		4014_show_score_effect = yes
		custom_tooltip = laamp_base_learning_contract_events.4025.tt.chapters_left
		if = {
			limit = { 
				exists = scope:task_contract.var:prefered_topic
				4025_is_final_shot_trigger = no
			}
			custom_tooltip = laamp_base_learning_contract_events.4025.tt.prefered_topic
		}	
	}
	#Learning duel
	option = {
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = { scope:task_contract.var:latest_topic ?= flag:learning }
						desc = laamp_base_learning_contract_events.4025.a.second
					}
					desc = laamp_base_learning_contract_events.4025.a
				}
			}
		}
		skill = learning
		trigger = { 4025_is_final_shot_trigger = no }
		4025_generic_skill_duel_effect = { SKILL = learning }
		scope:task_contract = {
			set_variable = {
				name = latest_topic
				value = flag:learning
			}
		}
		#Nothing to see here
		ai_chance = {
			base = 100
		}
	}
	#TRIGGERED: Diplomacy + Learning
	option = {
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = { scope:task_contract.var:latest_topic ?= flag:diplomacy }
						desc = laamp_base_learning_contract_events.4025.b.second
					}
					desc = laamp_base_learning_contract_events.4025.b
				}
			}
		}
		trigger = {
			scope:task_contract = {
				is_target_in_variable_list = {
					name = event_option_list
					target = flag:has_diplomacy_option
				}
			}
			4025_is_final_shot_trigger = no
		}
		skill = diplomacy
		4025_generic_skill_duel_effect = { SKILL = diplomacy }
		scope:task_contract = {
			set_variable = {
				name = latest_topic
				value = flag:diplomacy
			}
		}
		#Nothing to see here
		ai_chance = {
			base = 100
		}
	}
	#TRIGGERED: Martial + Learning
	option = {
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = { scope:task_contract.var:latest_topic ?= flag:martial }
						desc = laamp_base_learning_contract_events.4025.c.second
					}
					desc = laamp_base_learning_contract_events.4025.c
				}
			}
		}
		trigger = {
			scope:task_contract = {
				is_target_in_variable_list = {
					name = event_option_list
					target = flag:has_martial_option
				}
			}
			4025_is_final_shot_trigger = no
		}
		skill = martial
		4025_generic_skill_duel_effect = { SKILL = martial }
		scope:task_contract = {
			set_variable = {
				name = latest_topic
				value = flag:martial
			}
		}
		#Nothing to see here
		ai_chance = {
			base = 100
		}
	}
	#TRIGGERED: Stewardship + Learning
	option = {
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = { scope:task_contract.var:latest_topic ?= flag:stewardship }
						desc = laamp_base_learning_contract_events.4025.d.second
					}
					desc = laamp_base_learning_contract_events.4025.d
				}
			}
		}
		trigger = {
			scope:task_contract = {
				is_target_in_variable_list = {
					name = event_option_list
					target = flag:has_stewardship_option
				}
			}
			4025_is_final_shot_trigger = no
		}
		skill = stewardship
		4025_generic_skill_duel_effect = { SKILL = stewardship }
		scope:task_contract = {
			set_variable = {
				name = latest_topic
				value = flag:stewardship
			}
		}
		#Nothing to see here
		ai_chance = {
			base = 100
		}
	}
	#TRIGGERED: Intrigue + Learning
	option = {
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = { scope:task_contract.var:latest_topic ?= flag:intrigue }
						desc = laamp_base_learning_contract_events.4025.e.second
					}
					desc = laamp_base_learning_contract_events.4025.e
				}
			}
		}
		trigger = {
			scope:task_contract = {
				is_target_in_variable_list = {
					name = event_option_list
					target = flag:has_intrigue_option
				}
			}
			4025_is_final_shot_trigger = no
		}
		skill = intrigue
		4025_generic_skill_duel_effect = { SKILL = intrigue }
		scope:task_contract = {
			set_variable = {
				name = latest_topic
				value = flag:intrigue
			}
		}
		#Nothing to see here
		ai_chance = {
			base = 100
		}
	}
	#TRIGGERED: Traveler
	option = {
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = { scope:task_contract.var:latest_topic ?= flag:travel }
						desc = laamp_base_learning_contract_events.4025.f.second
					}
					desc = laamp_base_learning_contract_events.4025.f
				}
			}
		}
		trigger = {
			scope:task_contract = {
				is_target_in_variable_list = {
					name = event_option_list
					target = flag:has_traveler_option
				}
			}
			4025_is_final_shot_trigger = no
		}
		trait = lifestyle_traveler
		random_list = {
			0 = {
				desc = laamp_base_learning_contract_events.4025.success.tt
				#Indented for easier folding
					modifier = {
						4025_has_traveler_trait_xp_trigger = { VALUE = 10 }
						add = 10
						always = yes
					}
					modifier = {
						4025_has_traveler_trait_xp_trigger = { VALUE = 20 }
						add = 10
						always = yes
					}
					modifier = {
						4025_has_traveler_trait_xp_trigger = { VALUE = 30 }
						add = 10
						always = yes
					}
					modifier = {
						4025_has_traveler_trait_xp_trigger = { VALUE = 40 }
						add = 10
						always = yes
					}
					modifier = {
						4025_has_traveler_trait_xp_trigger = { VALUE = 50 }
						add = 10
						always = yes
					}
					modifier = {
						4025_has_traveler_trait_xp_trigger = { VALUE = 60 }
						add = 10
						always = yes
					}
					modifier = {
						4025_has_traveler_trait_xp_trigger = { VALUE = 70 }
						add = 10
						always = yes
					}
					modifier = {
						4025_has_traveler_trait_xp_trigger = { VALUE = 80 }
						add = 10
						always = yes
					}
					modifier = {
						4025_has_traveler_trait_xp_trigger = { VALUE = 90 }
						add = 10
						always = yes
					}
					modifier = {
						4025_has_traveler_trait_xp_trigger = { VALUE = 100 }
						add = 10
						always = yes
					}
				send_interface_toast = {
					title = laamp_base_learning_contract_events.4025.success.t
					left_icon = root
					4025_success_effect = { REWARD = yes }
					if = {
						limit = {
							domicile ?= { provisions < max_provisions }
						}
						4025_add_provisions_reward_effect = {
							TOPIC = travel
							VALUE = task_contract_failure_provisions_gain_minor_value
						}
					}
				}
			}
			0 = {
				desc = laamp_base_learning_contract_events.4025.failure.tt
				modifier = {
					add = {
						value = 20
						multiply = scope:task_contract.var:chapters_attempted
						min = 5
					}
					always = yes
				}
				send_interface_toast = {
					title = laamp_base_learning_contract_events.4025.failure.t
					left_icon = root
					4025_failure_effect = yes
				}
			}
		}
		scope:task_contract = {
			set_variable = {
				name = latest_topic
				value = flag:travel
			}
		}
		#Nothing to see here
		ai_chance = {
			base = 100
		}
	}
	#TRIGGERED: Pilgrim
	option = {
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = {
							scope:task_contract = {
								OR = {
									AND = {
										has_variable = temp_old_prefered_topic
										var:prefered_topic ?= flag:pilgrimage
									}
									var:latest_topic ?= flag:pilgrimage
								}
							}
						}
						desc = laamp_base_learning_contract_events.4025.g.second
					}
					desc = laamp_base_learning_contract_events.4025.g
				}
			}
		}
		trigger = {
			scope:task_contract = {
				is_target_in_variable_list = {
					name = event_option_list
					target = flag:has_pilgrimage_option
				}
			}
			4025_is_final_shot_trigger = no
		}
		trait = pilgrim
		random_list = {
			0 = {
				desc = laamp_base_learning_contract_events.4025.success.tt
				#Indented for easier folding
					modifier = {
						4025_has_pilgrim_trait_xp_trigger = { VALUE = 10 }
						add = 10
						always = yes
					}
					modifier = {
						4025_has_pilgrim_trait_xp_trigger = { VALUE = 20 }
						add = 10
						always = yes
					}
					modifier = {
						4025_has_pilgrim_trait_xp_trigger = { VALUE = 30 }
						add = 10
						always = yes
					}
					modifier = {
						4025_has_pilgrim_trait_xp_trigger = { VALUE = 40 }
						add = 10
						always = yes
					}
					modifier = {
						4025_has_pilgrim_trait_xp_trigger = { VALUE = 50 }
						add = 10
						always = yes
					}
					modifier = {
						4025_has_pilgrim_trait_xp_trigger = { VALUE = 60 }
						add = 10
						always = yes
					}
					modifier = {
						4025_has_pilgrim_trait_xp_trigger = { VALUE = 70 }
						add = 10
						always = yes
					}
					modifier = {
						4025_has_pilgrim_trait_xp_trigger = { VALUE = 80 }
						add = 10
						always = yes
					}
					modifier = {
						4025_has_pilgrim_trait_xp_trigger = { VALUE = 90 }
						add = 10
						always = yes
					}
					modifier = {
						4025_has_pilgrim_trait_xp_trigger = { VALUE = 100 }
						add = 10
						always = yes
					}
				send_interface_toast = {
					title = laamp_base_learning_contract_events.4025.success.t
					left_icon = root
					4025_success_effect = { REWARD = yes }
					4025_add_gold_reward_effect = {
						TOPIC = pilgrimage
						VALUE = miniscule_gold_laamps_value
					}
					4025_add_piety_reward_effect = {
						TOPIC = pilgrimage
						VALUE = miniscule_piety_value
					}
				}
			}
			0 = {
				desc = laamp_base_learning_contract_events.4025.failure.tt
				modifier = {
					add = {
						value = 20
						multiply = scope:task_contract.var:chapters_attempted
						min = 5
					}
					always = yes
				}
				send_interface_toast = {
					title = laamp_base_learning_contract_events.4025.failure.t
					left_icon = root
					4025_failure_effect = yes
				}
			}
		}
		scope:task_contract = {
			set_variable = {
				name = latest_topic
				value = flag:pilgrimage
			}
		}
		#Nothing to see here
		ai_chance = {
			base = 100
		}
	}
	#TRIGGERED: Points of Interests visited
	option = {
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = { scope:task_contract.var:latest_topic ?= flag:poi }
						desc = laamp_base_learning_contract_events.4025.h.second
					}
					desc = laamp_base_learning_contract_events.4025.h
				}
			}
		}
		trigger = {
			scope:task_contract = {
				is_target_in_variable_list = {
					name = event_option_list
					target = flag:has_poi_option
				}
			}
			trigger_if = {
				limit = { has_variable = poi_visited }
				trigger_if = {
					limit = { scope:task_contract.var:chapters_attempted = 5 }
					var:poi_visited >= 50
				}
				trigger_else_if = {
					limit = { scope:task_contract.var:chapters_attempted = 4 }
					var:poi_visited >= 40 
				}
				trigger_else_if = {
					limit = { scope:task_contract.var:chapters_attempted = 3 }
					var:poi_visited >= 30 
				}
				trigger_else_if = {
					limit = { scope:task_contract.var:chapters_attempted = 2 }
					var:poi_visited >= 20 
				}
				trigger_else = { var:poi_visited >= 10 }
			}
			trigger_else = { always = no }
			4025_is_final_shot_trigger = no
		}
		reason = poi_amount
		4025_success_effect = { REWARD = yes }
		scope:task_contract = {
			set_variable = {
				name = latest_topic
				value = flag:poi
			}
		}
		#Nothing to see here
		ai_chance = {
			base = 100
		}
	}
	#TRIGGERED: Umm... guess you're not particularly skilled at _anything?_
	option = {
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = { scope:task_contract.var:latest_topic ?= flag:generic }
						desc = laamp_base_learning_contract_events.4025.i.second
					}
					desc = laamp_base_learning_contract_events.4025.i
				}
			}
		}
		trigger = {
			learning <= high_skill_rating
			4025_has_multiple_talents_trigger = no
			4025_is_final_shot_trigger = no
		}
		flavor = laamp_base_learning_contract_events.4025.i.flavor
		show_unlock_reason = no
		#*brows*
		add_stress = {
			value = {
				value = medium_stress_impact_gain
				multiply = scope:task_contract.var:chapters_attempted
			}
		}
		4025_success_effect = { REWARD = no }
		scope:task_contract = {
			set_variable = {
				name = latest_topic
				value = flag:generic
			}
		}
		#Nothing to see here
		ai_chance = {
			base = 100
		}
	}
	#Bruteforce: Massive stress
	option = {
		name = laamp_base_learning_contract_events.4025.j
		trigger = { 4025_is_final_shot_trigger = yes }
		#The OMEGA stress
		add_stress = {
			value = {
				add = massive_stress_impact_gain
				multiply = 0.8
			}
		}
		#Success! Yaay...
		scope:task_contract = {
			increment_variable_effect = {
				VAR = wins_tally
				VAL = 2
			}
		}
		custom_tooltip = laamp_base_learning_contract_events.4025.tt.guaranteed_success
		#Let's not
		ai_chance = {
			base = 0
		}
	}
	#Non
	option = {
		name = laamp_base_learning_contract_events.4025.k
		trigger = { 4025_is_final_shot_trigger = yes }
		#Ye've been warned
		custom_tooltip = laamp_base_learning_contract_events.4110.c.tt
		#Eh, probably
		ai_chance = { base = 50 }
	}
	after = {
		#Up the count / lower the count
		scope:task_contract = {
			increment_variable_effect = {
				VAR = chapters_attempted
				VAL = 1
			}
			increment_variable_effect = {
				VAR = chapters_left
				VAL = -1
			}
			#Re-save the old topic to the prefered topic
			if = {
				limit = { has_variable = temp_old_prefered_topic }
				set_variable = {
					name = prefered_topic
					value = var:temp_old_prefered_topic
				}
				remove_variable ?= temp_old_prefered_topic		
			}
			#Did we get any ingenial ideas?
			hidden_effect = {
				random_list = {
					20 = {
						trigger = { 
							has_variable = prefered_topic
							NOR = { 
								has_variable = had_inspiration_topic
								#Don't do this for the final chapter
								AND = {
									var:win_t3_threshold ?= 5
									var:chapters_attempted ?= 4
								}
								AND = {
									var:win_t3_threshold ?= 3
									var:chapters_attempted ?= 2
								}
							}
						}
						set_variable = {
							name = temp_old_prefered_topic
							value = var:prefered_topic
						}
						set_variable = had_inspiration_topic
						4021_roll_for_prefered_topic_effect = yes
					}
					80 = {
						#Probably not
					}
				}
			}	
		}
		#We done yet?
		if = {
			limit = { scope:task_contract.var:chapters_left > 0 }
			#Reset the Support Person
			save_scope_as = support_person
			#Once more into the fray
			trigger_event = {
				id = laamp_base_learning_contract_events.4025
				days = { 2 5 }
			}
		}
		else = {
			#Conclusion
			trigger_event = {
				id = laamp_base_learning_contract_events.4027
				days = 1
			}
		}
	}
}

#Conclusion
laamp_base_learning_contract_events.4027 = {
	type = character_event
	title = laamp_base_learning_contract_events.4027.t
	window = big_event_window
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:success_qualified }
				desc = laamp_base_learning_contract_events.4027.desc.failure
			}
			triggered_desc = {
				trigger = { exists = scope:success_standard }
				desc = laamp_base_learning_contract_events.4027.desc.success.standard
			}
			triggered_desc = {
				trigger = { exists = scope:success_critical }
				desc = laamp_base_learning_contract_events.4027.desc.success.critical
			}
			desc = laamp_base_learning_contract_events.4027.desc.failure
		}
	}
	theme = learning
	center_portrait = {
		character = root
		triggered_animation = {
			trigger = { exists = scope:success_qualified }
			animation = thinking
		}
		triggered_animation = {
			trigger = { exists = scope:success_standard }
			animation = personality_compassionate
		}
		triggered_animation = {
			trigger = { exists = scope:success_critical }
			animation = personality_zealous
		}
		animation = shame
	}
	right_portrait = {
		character = scope:employer
		camera = camera_event_scheme_far_right
		triggered_animation = {
			trigger = { exists = scope:success_qualified }
			animation = personality_callous
		}
		triggered_animation = {
			trigger = { exists = scope:success_standard }
			animation = admiration
		}
		triggered_animation = {
			trigger = { exists = scope:success_critical }
			animation = ecstasy
		}
		animation = disapproval
	}
	override_background = { reference = throne_room }
	immediate = {
		scope:employer = { save_scope_as = bg_override_char }
		if = {
			limit = { scope:task_contract.var:wins_tally >= scope:task_contract.var:win_t3_threshold }
			save_scope_as = success_critical
		}
		else_if = {
			limit = { scope:task_contract.var:wins_tally >= scope:task_contract.var:win_t2_threshold }
			save_scope_as = success_standard
		}
		else_if = {
			limit = { scope:task_contract.var:wins_tally >= scope:task_contract.var:win_t1_threshold }
			save_scope_as = success_qualified
		}
		else = { save_scope_as = failure_standard }
		# Finally, tell us where our total is at.
		4014_show_score_effect = yes
	}
	#Triggered option: You have less than Success Qualified - Start debating to get a qualified success
	option = {
		name = laamp_base_learning_contract_events.4027.a
		trigger = { scope:task_contract.var:wins_tally < scope:task_contract.var:win_t1_threshold }
		duel = {
			skills = { learning intrigue }
			target = scope:employer
			# Victory!
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				min = 5
				desc = laamp_base_learning_contract_events.4027.a.success.tt
				scope:task_contract = { complete_task_contract = success_qualified }
			}
			# Defeat!
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				min = 5
				desc = laamp_base_learning_contract_events.4027.a.failure.tt
				scope:task_contract = { complete_task_contract = failure_standard }
				#If we have literally 0
				if = {
					limit = {
						OR = {
							AND = {
								scope:task_contract.var:win_t1_threshold = 2
								scope:task_contract.var:wins_tally = 0
							}
							AND = {
								scope:task_contract.var:win_t1_threshold = 1
								scope:task_contract.var:wins_tally = 0
							}
						}
					}
					add_stress = {
						value = {
							add = massive_stress_impact_gain
							multiply = 0.8
						}
					}
				}
				#Else we should have 1 out of 2 for a Qualified Success
				else = { add_stress = medium_stress_impact_gain }	
			}
		}
		#*shrug*
		ai_chance = {
			base = 100
		}
	}
	#Yup, yup...
	option = {
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = { exists = scope:success_qualified }
						desc = laamp_base_learning_contract_events.4027.b.success_qualified
					}
					triggered_desc = {
						trigger = { exists = scope:success_standard }
						desc = laamp_base_learning_contract_events.4027.b.success_standard
					}
					triggered_desc = {
						trigger = { exists = scope:success_critical }
						desc = laamp_base_learning_contract_events.4027.b.success_critical
					}
					desc = laamp_base_learning_contract_events.4027.b.failure_standard
				}
			}
		}
		scope:task_contract = {
			if = {
				limit = { exists = scope:success_qualified }
				complete_task_contract = success_qualified
			}
			else_if = {
				limit = { exists = scope:success_standard }
				complete_task_contract = success_standard
			}
			else_if = {
				limit = { exists = scope:success_critical }
				complete_task_contract = success_critical
			}
			else = { complete_task_contract = failure_standard }
		}
		#*shrug*
		ai_chance = {
			base = 100
		}
	}
	after = { 
		#Carry on
		hidden_effect = {
			current_travel_plan ?= { resume_travel_plan = yes }
		}
	}
}



##################################################
# Act as a tutor for ruler's child
# 4100 - 4120
############################################

scripted_trigger 4100_terrain_with_background_trigger = {
	OR = {
		agot_is_farmlands_terrain = yes
		agot_is_plains_terrain = yes
		agot_is_steppe_terrain = yes
		agot_is_forest_terrain = yes
		agot_is_desert_terrain = yes
		agot_is_drylands_terrain = yes
		agot_is_oasis_terrain = yes
		agot_is_hills_terrain = yes
		agot_is_mountains_terrain = yes
		agot_is_wetlands_terrain = yes
	}
}

scripted_trigger 4100_person_is_apt_in_trigger = {
	$SKILL$ > root.$SKILL$
	$SKILL$ >= high_skill_rating
}

scripted_effect 4100_show_score_effect = {
	if = {
		limit = { scope:task_contract.var:wins_tally < scope:task_contract.var:win_t1_threshold }
		custom_tooltip = laamp_base_learning_contract_events.4100.tt.current_total.sub_t1
	}
	else_if= {
		limit = { scope:task_contract.var:wins_tally < scope:task_contract.var:win_t2_threshold }
		custom_tooltip = laamp_base_learning_contract_events.4100.tt.current_total.sub_t2
	}
}

scripted_effect 4100_adjust_difficulty_effect = {
	custom_tooltip = laamp_base_learning_contract_events.4100.tt.boost_difficulty.$DIFF_SPIKE$
	# Don't buff the difficulty for the AI, or they'll really have problems making solid judgements.
	if = {
		limit = { is_ai = no }
		scope:task_contract = {
			increment_variable_effect = {
				VAR = learning_diff
				VAL = $LEARNING$
			}
			increment_variable_effect = {
				VAR = topic_diff
				VAL = $TOPIC$
			}
			increment_variable_effect = {
				VAR = support_person_diff
				VAL = $SUPPORT_PERSON$
			}
			increment_variable_effect = {
				VAR = stress_charge
				VAL = $STRESS$
			}
		}
	}
}

scripted_effect 4100_increment_wins_tally_effect = {
	scope:task_contract = {
		increment_variable_effect = {
			VAR = wins_tally
			VAL = 1
		}
	}
}

scripted_effect 4100_reduce_teaching_moments_left_effect = {
	scope:task_contract = {
		increment_variable_effect = {
			VAR = educational_moments_left
			VAL = -1
		}
	}
}

scripted_effect 4100_partial_success_effect = {
	4100_increment_wins_tally_effect = yes
	custom_tooltip = laamp_base_learning_contract_events.4100.tt.progress_towards_success
	scope:child_to_educate = {
		random_list = {
			50 = {
				trigger = { scope:lesson_topic = flag:diplomacy_topic }
				show_chance = no
				desc = laamp_base_learning_contract_events.4100.child.fleeting_knowledge.desc
				add_character_modifier = {
					modifier = fleeting_diplomacy_knowledge_modifier
					years = 10
				}
			}
			50 = {
				trigger = { scope:lesson_topic = flag:martial_topic }
				show_chance = no
				desc = laamp_base_learning_contract_events.4100.child.fleeting_knowledge.desc
				add_character_modifier = {
					modifier = fleeting_martial_knowledge_modifier
					years = 10
				}
			}
			50 = {
				trigger = { scope:lesson_topic = flag:stewardship_topic }
				show_chance = no
				desc = laamp_base_learning_contract_events.4100.child.fleeting_knowledge.desc
				add_character_modifier = {
					modifier = fleeting_stewardship_knowledge_modifier
					years = 10
				}
			}
			50 = {
				trigger = { scope:lesson_topic = flag:intrigue_topic }
				show_chance = no
				desc = laamp_base_learning_contract_events.4100.child.fleeting_knowledge.desc
				add_character_modifier = {
					modifier = fleeting_intrigue_knowledge_modifier
					years = 10
				}
			}
			50 = {
				trigger = { scope:lesson_topic = flag:learning_topic }
				show_chance = no
				desc = laamp_base_learning_contract_events.4100.child.fleeting_knowledge.desc
				add_character_modifier = {
					modifier = fleeting_learning_knowledge_modifier
					years = 10
				}
			}
			50 = {
				trigger = { scope:lesson_topic = flag:prowess_topic }
				show_chance = no
				desc = laamp_base_learning_contract_events.4100.child.fleeting_knowledge.desc
				add_character_modifier = {
					modifier = fleeting_prowess_knowledge_modifier
					years = 10
				}
			}
			50 = {
				show_chance = no
				desc = laamp_base_learning_contract_events.4100.child.nothing_gleaned.desc
				#Nothing
			}
		}
	}
	4100_reduce_teaching_moments_left_effect = yes
}

scripted_effect 4100_educated_while_educating_effect = {
	random = {
		chance = chance_to_be_educated_while_educating_value
		add_$SKILL$_skill = 1
	}
}

scripted_effect 4100_actual_success_effect = {
	4100_educated_while_educating_effect = { SKILL = $SKILL$ }
	scope:child_to_educate = {
		if = {
			limit = { has_focus = education_$SKILL$ }
			custom_tooltip = laamp_base_learning_contract_events.4100.child_$SKILL$.tt
			education_point_acquisition_additional_points_effect = { LEVEL = low }
		}
		else = {
			random_list = {
				50 = {
					show_chance = no
					desc = laamp_base_learning_contract_events.4100.child.fleeting_knowledge.desc
					add_character_modifier = {
						modifier = fleeting_$SKILL$_knowledge_modifier
						years = 10
					}
				}
				25 = {
					show_chance = no
					desc = laamp_base_learning_contract_events.4100.child.solid_knowledge.desc
					modifier = {
						always = yes
						add = root.learning
					}
					add_$SKILL$_skill = 1
				}
			}
		}	
	}
}

scripted_effect 4100_success_effect = {
	4100_increment_wins_tally_effect = yes
	custom_tooltip = laamp_base_learning_contract_events.4100.tt.progress_towards_success
	#Diplomacy
	switch = {
		trigger = scope:lesson_topic
		flag:diplomacy_topic = {
			4100_actual_success_effect = { SKILL = diplomacy }
		}
		flag:martial_topic = {
			4100_actual_success_effect = { SKILL = martial }
		}
		flag:stewardship_topic = {
			4100_actual_success_effect = { SKILL = stewardship }
		}
		flag:intrigue_topic = {
			4100_actual_success_effect = { SKILL = intrigue }
		}
		flag:learning_topic = {
			4100_actual_success_effect = { SKILL = learning }
		}
		flag:prowess_topic = {
			4100_educated_while_educating_effect = { SKILL = prowess }
			scope:child_to_educate = {
				#No Prowess lifestyle, right?
				random_list = {
					50 = {
						add_character_modifier = {
							modifier = fleeting_prowess_knowledge_modifier
							years = 10
						}
					}
					25 = {
						modifier = {
							always = yes
							add = root.learning
						}
						add_prowess_skill = 1
					}
				}	
			}
		}
	}
	4100_reduce_teaching_moments_left_effect = yes
}

scripted_effect 4100_failure_effect = {
	custom_tooltip = laamp_base_learning_contract_events.4100.tt.education_failed
	4100_reduce_teaching_moments_left_effect = yes
}

scripted_effect 4100_duel_generic_effect = {
	duel = {
		skill = $SKILL$
		value = $DIFF$
		# Victory!
		50 = {
			compare_modifier = {
				value = scope:duel_value
				multiplier = 3.5
				min = -49
			}
			modifier = {
				knows_language_of_culture = scope:child_to_educate.culture
				add = 20
			}
			min = 5
			desc = laamp_base_learning_contract_events.4100.$SKILL$.tt.success
			send_interface_toast = {
				title = laamp_base_learning_contract_events.4100.success.t
				right_icon = scope:child_to_educate
				4100_success_effect = yes
			}
		}
		# Defeat!
		50 = {
			compare_modifier = {
				value = scope:duel_value
				multiplier = -3.5
				min = -49
			}
			min = 5
			desc = laamp_base_learning_contract_events.4100.$SKILL$.tt.failure
			send_interface_toast = {
				title = laamp_base_learning_contract_events.4100.failure.t
				right_icon = scope:child_to_educate
				4100_failure_effect = yes
			}
		}
	}
}

#What's the topic?
scripted_effect 4100_decide_topic_effect = {
	random_list = {
		#Diplomacy
		10 = {
			trigger = {
				NOT = { 
					scope:task_contract = { has_variable = used_diplomacy_topic_var }
				}
			}
			modifier = {
				highest_skill_including_prowess = diplomacy
				add = 5
			}
			save_scope_value_as = {
				name = lesson_topic
				value = flag:diplomacy_topic
			}
			scope:task_contract = { set_variable = used_diplomacy_topic_var }
		}
		#Martial
		10 = {
			trigger = {
				NOT = { 
					scope:task_contract = { has_variable = used_martial_topic_var }
				}
			}
			modifier = {
				highest_skill_including_prowess = martial
				add = 5
			}
			save_scope_value_as = {
				name = lesson_topic
				value = flag:martial_topic
			}
			scope:task_contract = { set_variable = used_martial_topic_var }
		}
		#Stewardship
		10 = {
			trigger = {
				NOT = { 
					scope:task_contract = { has_variable = used_stewardship_topic_var }
				}
			}
			modifier = {
				highest_skill_including_prowess = stewardship
				add = 5
			}
			save_scope_value_as = {
				name = lesson_topic
				value = flag:stewardship_topic
			}
			scope:task_contract = { set_variable = used_stewardship_topic_var }
		}
		#Intrigue
		10 = {
			trigger = {
				NOT = { 
					scope:task_contract = { has_variable = used_intrigue_topic_var }
				}
			}
			modifier = {
				highest_skill_including_prowess = intrigue
				add = 5
			}
			save_scope_value_as = {
				name = lesson_topic
				value = flag:intrigue_topic
			}
			scope:task_contract = { set_variable = used_intrigue_topic_var }
		}
		#Learning
		10 = {
			trigger = {
				NOT = { 
					scope:task_contract = { has_variable = used_learning_topic_var }
				}
			}
			save_scope_value_as = {
				name = lesson_topic
				value = flag:learning_topic
			}
			scope:task_contract = { set_variable = used_learning_topic_var }
		}
		#Prowess
		10 = {
			trigger = {
				NOT = { 
					scope:task_contract = { has_variable = used_prowess_topic_var }
				}
			}
			modifier = {
				highest_skill_including_prowess = prowess
				add = 5
			}
			save_scope_value_as = {
				name = lesson_topic
				value = flag:prowess_topic
			}
			scope:task_contract = { set_variable = used_prowess_topic_var }
		}
	}
}

scripted_effect 4100_actual_save_background_effect = {
	save_scope_value_as = {
		name = background
		value = flag:$FLAG$
	}
}

scripted_effect 4100_save_background_effect = {
	if = {
		limit = { agot_is_farmlands_terrain = yes }
		4100_actual_save_background_effect = { FLAG = farmlands }
	}
	if = {
		limit = { agot_is_plains_terrain = yes }
		4100_actual_save_background_effect = { FLAG = plains }
	}
	if = {
		limit = { agot_is_steppe_terrain = yes }
		4100_actual_save_background_effect = { FLAG = steppe }
	}
	if = {
		limit = { agot_is_desert_terrain = yes }
		4100_actual_save_background_effect = { FLAG = desert }
	}
	if = {
		limit = { agot_is_drylands_terrain = yes }
		4100_actual_save_background_effect = { FLAG = drylands }
	}
	if = {
		limit = { agot_is_oasis_terrain = yes }
		4100_actual_save_background_effect = { FLAG = oasis }
	}
	if = {
		limit = { agot_is_hills_terrain = yes }
		4100_actual_save_background_effect = { FLAG = hills }
	}
	if = {
		limit = { agot_is_mountains_terrain = yes }
		4100_actual_save_background_effect = { FLAG = mountains }
	}
	if = {
		limit = { agot_is_wetlands_terrain = yes }
		4100_actual_save_background_effect = { FLAG = wetlands }
	}
	#Plenty of different forest backgrounds
	if = {
		limit = { agot_is_forest_terrain = yes }
		random_list = {
			1 = {
				trigger = { current_season_spring = yes }
				4100_actual_save_background_effect = { FLAG = foggy_forest }
			}
			1 = {
				trigger = { current_season_autumn = yes }
				4100_actual_save_background_effect = { FLAG = managed_forest }
			}
			1 = {
				trigger = { graphical_wilderness_forest_pine_trigger = yes }
				4100_actual_save_background_effect = { FLAG = pine_forest }
			}
			1 = {
				trigger = { graphical_wilderness_forest_trigger = yes }
				4100_actual_save_background_effect = { FLAG = forest }
			}
			1 = {
				trigger = { 
					root = { middle_of_year_season_trigger = yes }
				}
				4100_actual_save_background_effect = { FLAG = forest_cave }
			}
			1 = {
				trigger = { location_has_winter_trigger = yes }
				4100_actual_save_background_effect = { FLAG = snowy_forest }
			}
		}
	}
}

# Roll our background tombola.
scripted_effect 4100_background_tombola_effect = {
	random_list = {
		#Alley
		100 = {
			trigger = {
				NOT = {
					scope:task_contract = { has_variable = used_alley_day_var }
				}
			}
			4100_actual_save_background_effect = { FLAG = alley_day }
			scope:task_contract = { set_variable = used_alley_day_var }
		}
		#Gallows
		100 = {
			trigger = {
				NOT = {
					scope:task_contract = { has_variable = used_gallows_var }
				}
				location = { geographical_region = world_europe }
			}
			4100_actual_save_background_effect = { FLAG = gallows }
			scope:task_contract = { set_variable = used_gallows_var }
		}
		#Market
		100 = {
			trigger = {
				NOT = {
					scope:task_contract = { has_variable = used_market_var }
				}
			}
			4100_actual_save_background_effect = { FLAG = market }
			scope:task_contract = { set_variable = used_market_var }
		}
		#Docks
		100 = {
			trigger = {
				NOT = {
					scope:task_contract = { has_variable = used_docks_var }
				}
				location = { is_coastal = yes }
			}
			4100_actual_save_background_effect = { FLAG = docks }
			scope:task_contract = { set_variable = used_docks_var }
		}
		#Garden
		100 = {
			trigger = {
				NOT = {
					scope:task_contract = { has_variable = used_garden_var }
				}
			}
			4100_actual_save_background_effect = { FLAG = garden }
			scope:task_contract = { set_variable = used_garden_var }
		}
		#Tavern
		100 = {
			trigger = {
				NOT = {
					scope:task_contract = { has_variable = used_tavern_var }
				}
			}
			4100_actual_save_background_effect = { FLAG = tavern }
			scope:task_contract = { set_variable = used_tavern_var }
		}
		#Temple
		100 = {
			trigger = {
				NOT = {
					scope:task_contract = { has_variable = used_temple_var }
				}
			}
			4100_actual_save_background_effect = { FLAG = temple }
			scope:task_contract = { set_variable = used_temple_var }
		}
		#Throneroom
		100 = {
			trigger = {
				NOT = {
					scope:task_contract = { has_variable = used_throneroom_var }
				}
			}
			4100_actual_save_background_effect = { FLAG = throneroom }
			scope:task_contract = { set_variable = used_throneroom_var }
		}
		#Armory
		100 = {
			trigger = {
				NOT = {
					scope:task_contract = { has_variable = used_armory_var }
				}
			}
			4100_actual_save_background_effect = { FLAG = armory }
			save_scope_value_as = {
				name = background
				value = flag:armory
			}
			scope:task_contract = { set_variable = used_armory_var }
		}
		#Field trip!
		100 = {
			trigger = {
				NOT = {
					scope:task_contract = { has_variable = used_terrain_var }
				}
				#Any nearby place we can go for a field study?
				OR = {
					location = { 4100_terrain_with_background_trigger = yes }
					location = {
						any_neighboring_province = { 4100_terrain_with_background_trigger = yes }
					}
				}
			}
			#Grab our location terrain
			location = { 4100_save_background_effect = yes }
			#Or grab a random nearby province terrain
			if = {
				limit = {
					NOT = { exists = scope:background }
				}
				location = {
					random_neighboring_province = { 4100_save_background_effect = yes }
				}
			}
			scope:task_contract = { set_variable = used_terrain_var }
		}
	}
}
		
scripted_effect 4100_topic_option_effect_wrapper_effect = {
	#Tally difficulty
	4100_adjust_difficulty_effect = {
		DIFF_SPIKE = topic
		LEARNING = 2
		TOPIC = 3
		SUPPORT_PERSON = 5
		STRESS = 5
	}
	#Record most recent approach
	scope:task_contract = {
		set_variable = {
			name = education_approach_var
			value = flag:topic
		}
	}
}

#Act as a tutor for ruler's child
laamp_base_learning_contract_events.4100 = {
	type = character_event
	title = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:lesson_topic = flag:diplomacy_topic }
				desc = laamp_base_learning_contract_events.4100.t.diplomacy
			}
			triggered_desc = {
				trigger = { scope:lesson_topic = flag:martial_topic }
				desc = laamp_base_learning_contract_events.4100.t.martial
			}
			triggered_desc = {
				trigger = { scope:lesson_topic = flag:stewardship_topic }
				desc = laamp_base_learning_contract_events.4100.t.stewardship
			}
			triggered_desc = {
				trigger = { scope:lesson_topic = flag:intrigue_topic }
				desc = laamp_base_learning_contract_events.4100.t.intrigue
			}
			triggered_desc = {
				trigger = { scope:lesson_topic = flag:learning_topic }
				desc = laamp_base_learning_contract_events.4100.t.learning
			}
			triggered_desc = {
				trigger = { scope:lesson_topic = flag:prowess_topic }
				desc = laamp_base_learning_contract_events.4100.t.prowess
			}
		}
	}	
	window = big_event_window
	desc = {
		#Intro
		first_valid = {
			#First time
			triggered_desc = {
				trigger = { 
					NOT = { 
						scope:task_contract = { has_variable = education_approach_var }
					}
				}
				desc = laamp_base_learning_contract_events.4100.desc.intro.first_time
			}
			#Is there an intro from last time?
			triggered_desc = {
				trigger = { scope:task_contract.var:education_approach_var = flag:stress }
				desc = laamp_base_learning_contract_events.4100.desc.intro.stress
			}
			triggered_desc = {
				trigger = {
					scope:support_person = root
					scope:task_contract.var:education_approach_var = flag:support 
				}
				desc = laamp_base_learning_contract_events.4100.desc.intro.support_no_support
			}
			triggered_desc = {
				trigger = { 
					scope:task_contract.var:education_approach_var = flag:support 
				}
				desc = laamp_base_learning_contract_events.4100.desc.intro.support
			}
			triggered_desc = {
				trigger = { 
					scope:task_contract.var:education_approach_var = flag:learning 
				}
				desc = laamp_base_learning_contract_events.4100.desc.intro.learning
			}
			triggered_desc = {
				trigger = { 
					scope:task_contract.var:education_approach_var = flag:topic 
				}
				desc = laamp_base_learning_contract_events.4100.desc.intro.topic
			}
		}
		# Surroundings.
		first_valid = {
			triggered_desc = {
				trigger = { scope:background = flag:alley_day }
				desc = laamp_base_learning_contract_events.4100.desc.surroundings.alley_day
			}
			triggered_desc = {
				trigger = { scope:background = flag:gallows }
				desc = laamp_base_learning_contract_events.4100.desc.surroundings.gallows
			}
			triggered_desc = {
				trigger = { scope:background = flag:market }
				desc = laamp_base_learning_contract_events.4100.desc.surroundings.market
			}
			triggered_desc = {
				trigger = { scope:background = flag:docks }
				desc = laamp_base_learning_contract_events.4100.desc.surroundings.docks
			}
			triggered_desc = {
				trigger = { scope:background = flag:armory }
				desc = laamp_base_learning_contract_events.4100.desc.surroundings.armory
			}
			triggered_desc = {
				trigger = { scope:background = flag:garden }
				desc = laamp_base_learning_contract_events.4100.desc.surroundings.garden
			}
			triggered_desc = {
				trigger = { scope:background = flag:tavern }
				desc = laamp_base_learning_contract_events.4100.desc.surroundings.tavern
			}
			triggered_desc = {
				trigger = { scope:background = flag:temple }
				desc = laamp_base_learning_contract_events.4100.desc.surroundings.temple
			}
			triggered_desc = {
				trigger = { scope:background = flag:throneroom }
				desc = laamp_base_learning_contract_events.4100.desc.surroundings.throneroom
			}
			triggered_desc = {
				trigger = { scope:background = flag:armory }
				desc = laamp_base_learning_contract_events.4100.desc.surroundings.armory
			}
			#Nature
			triggered_desc = {
				trigger = { scope:background = flag:farmlands }
				desc = laamp_base_learning_contract_events.4100.desc.surroundings.farmlands
			}
			triggered_desc = {
				trigger = { scope:background = flag:plains }
				desc = laamp_base_learning_contract_events.4100.desc.surroundings.plains
			}
			triggered_desc = {
				trigger = { scope:background = flag:steppe }
				desc = laamp_base_learning_contract_events.4100.desc.surroundings.steppe
			}
			triggered_desc = {
				trigger = { scope:background = flag:desert }
				desc = laamp_base_learning_contract_events.4100.desc.surroundings.desert
			}
			triggered_desc = {
				trigger = { scope:background = flag:drylands }
				desc = laamp_base_learning_contract_events.4100.desc.surroundings.drylands
			}
			triggered_desc = {
				trigger = { scope:background = flag:oasis }
				desc = laamp_base_learning_contract_events.4100.desc.surroundings.oasis
			}
			triggered_desc = {
				trigger = { scope:background = flag:hills }
				desc = laamp_base_learning_contract_events.4100.desc.surroundings.hills
			}
			triggered_desc = {
				trigger = { scope:background = flag:mountains }
				desc = laamp_base_learning_contract_events.4100.desc.surroundings.mountains
			}
			triggered_desc = {
				trigger = { scope:background = flag:wetlands }
				desc = laamp_base_learning_contract_events.4100.desc.surroundings.wetlands
			}
			triggered_desc = {
				trigger = { scope:background = flag:foggy_forest }
				desc = laamp_base_learning_contract_events.4100.desc.surroundings.foggy_forest
			}
			#Forest
			triggered_desc = {
				trigger = { scope:background = flag:managed_forest }
				desc = laamp_base_learning_contract_events.4100.desc.surroundings.managed_forest
			}
			triggered_desc = {
				trigger = { scope:background = flag:pine_forest }
				desc = laamp_base_learning_contract_events.4100.desc.surroundings.pine_forest
			}
			triggered_desc = {
				trigger = { scope:background = flag:forest }
				desc = laamp_base_learning_contract_events.4100.desc.surroundings.forest
			}
			triggered_desc = {
				trigger = { scope:background = flag:forest_cave }
				desc = laamp_base_learning_contract_events.4100.desc.surroundings.forest_cave
			}
			triggered_desc = {
				trigger = { scope:background = flag:snowy_forest }
				desc = laamp_base_learning_contract_events.4100.desc.surroundings.snowy_forest
			}
		}
		#Topic
		first_valid = {
			triggered_desc = {
				trigger = { scope:lesson_topic = flag:diplomacy_topic }
				desc = laamp_base_learning_contract_events.4100.desc.topic.diplomacy
			}
			triggered_desc = {
				trigger = { scope:lesson_topic = flag:martial_topic }
				desc = laamp_base_learning_contract_events.4100.desc.topic.martial
			}
			triggered_desc = {
				trigger = { scope:lesson_topic = flag:stewardship_topic }
				desc = laamp_base_learning_contract_events.4100.desc.topic.stewardship
			}
			triggered_desc = {
				trigger = { scope:lesson_topic = flag:intrigue_topic }
				desc = laamp_base_learning_contract_events.4100.desc.topic.intrigue
			}
			triggered_desc = {
				trigger = { scope:lesson_topic = flag:learning_topic }
				desc = laamp_base_learning_contract_events.4100.desc.topic.learning
			}
			triggered_desc = {
				trigger = { scope:lesson_topic = flag:prowess_topic }
				desc = laamp_base_learning_contract_events.4100.desc.topic.prowess
			}
		}
		#Kid distraction
		first_valid = {
			triggered_desc = {
				trigger = { scope:current_child_distraction = flag:stress }
				desc = laamp_base_learning_contract_events.4100.desc.distraction.stress
			}
			triggered_desc = {
				trigger = { scope:current_child_distraction = flag:hobbyhorse }
				desc = laamp_base_learning_contract_events.4100.desc.distraction.hobbyhorse
			}
			triggered_desc = {
				trigger = { scope:current_child_distraction = flag:attention }
				desc = laamp_base_learning_contract_events.4100.desc.distraction.attention
			}
			triggered_desc = {
				trigger = { scope:current_child_distraction = flag:dog }
				desc = laamp_base_learning_contract_events.4100.desc.distraction.dog
			}
			triggered_desc = {
				trigger = { scope:current_child_distraction = flag:running }
				desc = laamp_base_learning_contract_events.4100.desc.distraction.running
			}
			triggered_desc = {
				trigger = { scope:current_child_distraction = flag:crushing }
				desc = laamp_base_learning_contract_events.4100.desc.distraction.crushing
			}
			triggered_desc = {
				trigger = { scope:current_child_distraction = flag:other_kids }
				desc = laamp_base_learning_contract_events.4100.desc.distraction.other_kids
			}
			triggered_desc = {
				trigger = { scope:current_child_distraction = flag:friends }
				desc = laamp_base_learning_contract_events.4100.desc.distraction.friends
			}
			triggered_desc = {
				trigger = { scope:current_child_distraction = flag:hiding }
				desc = laamp_base_learning_contract_events.4100.desc.distraction.hiding
			}
			triggered_desc = {
				trigger = { scope:current_child_distraction = flag:unimpressed }
				desc = laamp_base_learning_contract_events.4100.desc.distraction.unimpressed
			}
		}
		#Do we have a support person?
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:task_contract = { var:education_approach_var ?= flag:support }
					NOT = { scope:support_person = root }
				}
				desc = laamp_base_learning_contract_events.4100.desc.outro_other
			}
			triggered_desc = {
				trigger = { 
					NOT = { scope:support_person = root }
				}
				desc = laamp_base_learning_contract_events.4100.desc.outro
			}
		}	
	}
	theme = learning
	left_portrait = {
		trigger = { 
			NOT = { scope:support_person = root }
		}
		character = scope:support_person
		triggered_animation = {
			trigger = { scope:lesson_topic = flag:diplomacy_topic }
			animation = happiness
		}
		triggered_animation = {
			trigger = { scope:lesson_topic = flag:martial_topic }
			animation = marshal_shield
		}
		triggered_animation = {
			trigger = { scope:lesson_topic = flag:stewardship_topic }
			animation = steward
		}
		triggered_animation = {
			trigger = { scope:lesson_topic = flag:intrigue_topic }
			animation = spymaster
		}	
		animation = thinking
	}
	center_portrait = {
		character = root
		triggered_animation = {
			trigger = {
				NOT = { scope:support_person = root }
			}
			animation = happy_teacher
		}
		animation = stressed_teacher
	}
	right_portrait = {
		character = scope:child_to_educate
		camera = camera_event_scheme_vs_extra_right_look_right
		triggered_animation = {
			trigger = {
				scope:task_contract = { var:education_approach_var ?= flag:stress }
			}
			animation = disapproval
		}
		#Age up to 11
		triggered_animation = {
			trigger = { scope:current_child_distraction = flag:hobbyhorse }
			animation = child_hobby_horse
		}
		triggered_animation = {
			trigger = { scope:current_child_distraction = flag:attention }
			animation = eccentric
		}
		triggered_animation = {
			trigger = { scope:current_child_distraction = flag:dog }
			animation = happiness
		}
		triggered_animation = {
			trigger = { scope:current_child_distraction = flag:running }
			animation = manic
		}
		#Age 12-15
		triggered_animation = {
			trigger = { scope:current_child_distraction = flag:crushing }
			animation = shame
		}
		triggered_animation = {
			trigger = { scope:current_child_distraction = flag:other_kids }
			animation = interested
		}
		triggered_animation = {
			trigger = { scope:current_child_distraction = flag:friends }
			animation = laugh
		}
		triggered_animation = {
			trigger = { scope:current_child_distraction = flag:hiding }
			animation = happiness
		}
		triggered_animation = {
			trigger = { scope:current_child_distraction = flag:unimpressed }
			animation = boredom
		}
		animation = survey
	}
	# Backgrounds indented +1 for easier folding.
		override_background = {
			trigger = { scope:background = flag:alley_day }
			reference = alley_day
		}
		override_background = {
			trigger = { scope:background = flag:gallows }
			reference = gallows
		}
		override_background = {
			trigger = { scope:background = flag:market }
			reference = market
		}
		override_background = {
			trigger = { scope:background = flag:docks }
			reference = docks
		}
		override_background = {
			trigger = { scope:background = flag:garden }
			reference = garden
		}
		override_background = {
			trigger = { scope:background = flag:tavern }
			reference = tavern
		}
		override_background = {
			trigger = { scope:background = flag:temple }
			reference = holy_site_generic
		}
		override_background = {
			trigger = { scope:background = flag:throneroom }
			reference = throne_room
		}
		override_background = {
			trigger = { scope:background = flag:armory }
			reference = armory
		}
		#Nature
		override_background = {
			trigger = { scope:background = flag:farmlands }
			reference = ep2_travel_settlement_farm
		}
		override_background = {
			trigger = { scope:background = flag:plains }
			reference = ep2_travel_settlement_hills
		}
		override_background = {
			trigger = { scope:background = flag:steppe }
			reference = ep2_travel_settlement_steppe
		}
		override_background = {
			trigger = { scope:background = flag:desert }
			reference = ep2_travel_settlement_desert
		}
		override_background = {
			trigger = { scope:background = flag:drylands }
			reference = drylands
		}
		override_background = {
			trigger = { scope:background = flag:oasis }
			reference = ce1_legendary_oasis
		}
		override_background = {
			trigger = { scope:background = flag:hills }
			reference = hills
		}
		override_background = {
			trigger = { scope:background = flag:mountains }
			reference = ep2_travel_settlement_mountains
		}
		override_background = {
			trigger = { scope:background = flag:wetlands }
			reference = wilderness_wetlands
		}
		#Forest
		override_background = {
			trigger = { scope:background = flag:foggy_forest }
			reference = ep2_hunt_foggy_forest
		}
		override_background = {
			trigger = { scope:background = flag:managed_forest }
			reference = ep2_forest_managed
		}
		override_background = {
			trigger = { scope:background = flag:pine_forest }
			reference = wilderness_forest_pine
		}
		override_background = {
			trigger = { scope:background = flag:forest }
			reference = wilderness_forest
		}
		override_background = {
			trigger = { scope:background = flag:forest_cave }
			reference = ep2_hunt_forest_cave
		}
		override_background = {
			trigger = { scope:background = flag:snowy_forest }
			reference = ep2_hunt_snowy_forest
		}
	trigger = {
		exists = scope:task_contract
		scope:task_contract.var:task_contract_target = { age < 15 }
	}
	on_trigger_fail = {
		if = {
			limit = {
				exists = scope:task_contract
			}
		send_interface_message = {
			title = laamp_base_learning_contract_events_invalidated_message.old
			type = diplo_contract_scheme_invalidated_message
			right_icon = scope:task_contract.task_contract_employer
			scope:task_contract = { invalidate_contract = yes }
			}
		}
	}
	immediate = {
		#No distractions
		if = {
			limit = {
				NOT = { has_character_flag = is_in_task_contract_event_chain }
			}
			add_character_flag = is_in_task_contract_event_chain
		}
		#What's the topic?
		4100_decide_topic_effect = yes
		# Roll our background tombola.
		scope:child_to_educate = {
			if = {
				limit = {
					is_ruler = no
					exists = court_owner
				}
				court_owner = { save_scope_as = bg_override_char }
			}
			else = {
				save_scope_as = bg_override_char
			}
		}
		4100_background_tombola_effect = yes
		#What is the kid distracted by...
		random_list = {
			1 = {
				trigger = { 
					scope:task_contract = { var:education_approach_var ?= flag:stress }
				}
				save_scope_value_as = {
					name = current_child_distraction
					value = flag:stress
				}
			}
			#Age up to 11
			1 = {
				trigger = {
					scope:child_to_educate = { age < 12 }
					scope:task_contract = {
						NOT = { has_variable = had_hobbyhorse_var }
					}
				}
				scope:task_contract = { set_variable = had_hobbyhorse_var }
				save_scope_value_as = {
					name = current_child_distraction
					value = flag:hobbyhorse
				}
			}
			1 = {
				trigger = {
					scope:child_to_educate = { age < 12 }
					scope:task_contract = {
						NOT = { has_variable = had_attention_var }
					}
				}
				scope:task_contract = { set_variable = had_attention_var }
				save_scope_value_as = {
					name = current_child_distraction
					value = flag:attention
				}
			}
			1 = {
				trigger = {
					scope:child_to_educate = { age < 12 }
					scope:task_contract = {
						NOT = { has_variable = had_dog_var }
					}
				}
				scope:task_contract = { set_variable = had_dog_var }
				save_scope_value_as = {
					name = current_child_distraction
					value = flag:dog
				}
			}
			1 = {
				trigger = {
					scope:child_to_educate = { age < 12 }
					scope:task_contract = {
						NOT = { has_variable = had_running_var }
					}
				}
				scope:task_contract = { set_variable = had_running_var }
				save_scope_value_as = {
					name = current_child_distraction
					value = flag:running
				}
			}
			#Age 12-15
			1 = {
				trigger = {
					scope:child_to_educate = { age >= 12 }
					scope:task_contract = {
						NOT = { has_variable = had_crushing_var }
					}
				}
				scope:task_contract = { set_variable = had_crushing_var }
				save_scope_value_as = {
					name = current_child_distraction
					value = flag:crushing
				}
				random_dummy_gender_effect = yes
			}
			1 = {
				trigger = {
					scope:child_to_educate = { age >= 12 }
					scope:task_contract = {
						NOT = { has_variable = had_other_kids_var }
					}
				}
				scope:task_contract = { set_variable = had_other_kids_var }
				save_scope_value_as = {
					name = current_child_distraction
					value = flag:other_kids
				}
			}
			1 = {
				trigger = {
					scope:child_to_educate = { age >= 12 }
					scope:task_contract = {
						NOT = { has_variable = had_friends_var }
					}
				}
				scope:task_contract = { set_variable = had_friends_var }
				save_scope_value_as = {
					name = current_child_distraction
					value = flag:friends
				}
			}
			1 = {
				trigger = {
					scope:child_to_educate = { age >= 12 }
					scope:task_contract = {
						NOT = { has_variable = had_hiding_var }
					}
				}
				scope:task_contract = { set_variable = had_hiding_var }
				save_scope_value_as = {
					name = current_child_distraction
					value = flag:hiding
				}
			}
			1 = {
				trigger = {
					scope:child_to_educate = { age >= 12 }
					scope:task_contract = {
						NOT = { has_variable = had_unimpressed_var }
					}
				}
				scope:task_contract = { set_variable = had_unimpressed_var }
				save_scope_value_as = {
					name = current_child_distraction
					value = flag:unimpressed
				}
			}
		}
		#Find someone who knows the subject matter
		random_courtier_or_guest = {
			limit = {
				is_ai = yes
				is_adult = yes
				is_available_allow_travelling = yes
				trigger_if = {
					limit = { exists = scope:lesson_topic }
					trigger_if = {
						limit = { scope:lesson_topic = flag:diplomacy_topic }
						4100_person_is_apt_in_trigger = { SKILL = diplomacy }
					}
					trigger_if = {
						limit = { scope:lesson_topic = flag:martial_topic }
						4100_person_is_apt_in_trigger = { SKILL = martial }
					}
					trigger_if = {
						limit = { scope:lesson_topic = flag:stewardship_topic }
						4100_person_is_apt_in_trigger = { SKILL = stewardship }
					}
					trigger_if = {
						limit = { scope:lesson_topic = flag:intrigue_topic }
						4100_person_is_apt_in_trigger = { SKILL = intrigue }
					}
					trigger_if = {
						limit = { scope:lesson_topic = flag:learning_topic }
						4100_person_is_apt_in_trigger = { SKILL = learning }
					}
					trigger_if = {
						limit = { scope:lesson_topic = flag:prowess_topic }
						4100_person_is_apt_in_trigger = { SKILL = prowess }
					}
				}
				trigger_else = { always = no }
				
			}
			save_scope_as = support_person
		}
		#Guess you ain't got support this time
		if = {
			limit = {
				NOT = { exists = scope:support_person }
			}
			save_scope_as = support_person
		}
		# Plus, stop us whilst we're here.
		hidden_effect = {
			current_travel_plan ?= { pause_travel_plan = yes }
		}
		# Finally, tell us where our total is at.
		4100_show_score_effect = yes
		custom_tooltip = laamp_base_learning_contract_events.4100.tt.opportunities_left
	}
	#Learning: Ye olde learning duel
	option = {
		name = laamp_base_learning_contract_events.4100.a
		trigger = {
			trigger_if = {
				limit = { scope:lesson_topic = flag:learning_topic }
				NOT = { has_trait = scholar }
			}
			trigger_else = { always = yes }
		}
		skill = learning
		#One duel, comin' up
		4100_duel_generic_effect = {
			SKILL = learning
			DIFF = scope:task_contract.var:learning_diff
		}
		#Tally difficulty
		4100_adjust_difficulty_effect = {
			DIFF_SPIKE = learning
			LEARNING = 3
			TOPIC = 2
			SUPPORT_PERSON = 5
			STRESS = 5
		}
		#Record most recent approach
		scope:task_contract = {
			set_variable = {
				name = education_approach_var
				value = flag:learning
			}
		}
		# No stress here.
		ai_chance = {
			base = 1
			modifier = {
				add = learning
				always = yes
			}
		}
	}
	#TOPIC: Diplomacy
	option = {
		name = laamp_base_learning_contract_events.4100.b
		trigger = { scope:lesson_topic = flag:diplomacy_topic }
		skill = diplomacy #Literally the only reason TOPIC is split into 5 event options
		if = {
			limit = { scope:lesson_topic = flag:diplomacy_topic }
			4100_duel_generic_effect = {
				SKILL = diplomacy
				DIFF = scope:task_contract.var:topic_diff
			}
		}
		#Used in more than 3 places
		4100_topic_option_effect_wrapper_effect = yes
		# No stress here.
		ai_chance = {
			base = 1
			modifier = {
				add = diplomacy
				always = yes
			}
		}
	}
	#TOPIC: Martial
	option = {
		name = laamp_base_learning_contract_events.4100.b
		trigger = { scope:lesson_topic = flag:martial_topic }
		skill = martial #Literally the only reason TOPIC is split into 5 event options
		if = {
			limit = { scope:lesson_topic = flag:martial_topic }
			4100_duel_generic_effect = {
				SKILL = martial
				DIFF = scope:task_contract.var:topic_diff
			}
		}
		#Used in more than 3 places
		4100_topic_option_effect_wrapper_effect = yes
		# No stress here.
		ai_chance = {
			base = 1
			modifier = {
				add = martial
				always = yes
			}
		}
	}
	#TOPIC: Stewardship
	option = {
		name = laamp_base_learning_contract_events.4100.b
		trigger = { scope:lesson_topic = flag:stewardship_topic }
		skill = stewardship #Literally the only reason TOPIC is split into 5 event options
		if = {
			limit = { scope:lesson_topic = flag:stewardship_topic }
			4100_duel_generic_effect = {
				SKILL = stewardship
				DIFF = scope:task_contract.var:topic_diff
			}
		}
		#Used in more than 3 places
		4100_topic_option_effect_wrapper_effect = yes
		# No stress here.
		ai_chance = {
			base = 1
			modifier = {
				add = stewardship
				always = yes
			}
		}
	}
	#TOPIC: Intrigue
	option = {
		name = laamp_base_learning_contract_events.4100.b
		trigger = { scope:lesson_topic = flag:intrigue_topic }
		skill = intrigue #Literally the only reason TOPIC is split into 5 event options
		if = {
			limit = { scope:lesson_topic = flag:intrigue_topic }
			4100_duel_generic_effect = {
				SKILL = intrigue
				DIFF = scope:task_contract.var:topic_diff
			}
		}
		#Used in more than 3 places
		4100_topic_option_effect_wrapper_effect = yes
		# No stress here.
		ai_chance = {
			base = 1
			modifier = {
				add = intrigue
				always = yes
			}
		}
	}
	#TOPIC: Learning
	option = {
		name = laamp_base_learning_contract_events.4100.b.scholar
		trigger = { 
			scope:lesson_topic = flag:learning_topic
			has_trait = scholar
		}
		show_as_unavailable = { scope:lesson_topic = flag:learning_topic }
		reason = scholar
		send_interface_toast = {
			title = laamp_base_learning_contract_events.4100.success.t
			right_icon = scope:child_to_educate
			4100_success_effect = yes
		}
		# No stress here.
		ai_chance = {
			base = 1
			modifier = {
				add = learning
				always = yes
			}
		}
	}
	#TOPIC: Prowess
	option = {
		name = laamp_base_learning_contract_events.4100.b
		trigger = { scope:lesson_topic = flag:prowess_topic }
		skill = prowess #Literally the only reason TOPIC is split into 5 event options
		if = {
			limit = { scope:lesson_topic = flag:prowess_topic }
			4100_duel_generic_effect = {
				SKILL = prowess
				DIFF = scope:task_contract.var:topic_diff
			}
		}
		#Used in more than 3 places
		4100_topic_option_effect_wrapper_effect = yes
		# No stress here.
		ai_chance = {
			base = 1
			modifier = {
				add = diplomacy
				always = yes
			}
		}
	}
	#Triggered: Support Person! Attack!
	option = {
		name = {
			text = {
				first_valid = {
					#Diplomacy
					triggered_desc = {
						trigger = { 
							scope:support_person ?= root
							scope:lesson_topic = flag:diplomacy_topic
						}
						desc = laamp_base_learning_contract_events.4100.c.diplomacy.support_not_exists
					}
					#Martial
					triggered_desc = {
						trigger = { 
							scope:support_person ?= root
							scope:lesson_topic = flag:martial_topic
						}
						desc = laamp_base_learning_contract_events.4100.c.martial.support_not_exists
					}
					#Stewardship
					triggered_desc = {
						trigger = { 
							scope:support_person ?= root
							scope:lesson_topic = flag:stewardship_topic
						}
						desc = laamp_base_learning_contract_events.4100.c.stewardship.support_not_exists
					}
					#Intrigue
					triggered_desc = {
						trigger = { 
							scope:support_person ?= root
							scope:lesson_topic = flag:intrigue_topic
						}
						desc = laamp_base_learning_contract_events.4100.c.intrigue.support_not_exists
					}
					#Learning
					triggered_desc = {
						trigger = { 
							scope:support_person ?= root
							scope:lesson_topic = flag:learning_topic
						}
						desc = laamp_base_learning_contract_events.4100.c.learning.support_not_exists
					}
					#Prowess
					triggered_desc = {
						trigger = { 
							scope:support_person ?= root
							scope:lesson_topic = flag:prowess_topic
						}
						desc = laamp_base_learning_contract_events.4100.c.prowess.support_not_exists
					}
					desc = laamp_base_learning_contract_events.4100.c.support_exists
				}
			}
		}
		trigger = {
			#Diplomacy
			trigger_if = {
				limit = { scope:lesson_topic = flag:diplomacy_topic }
				custom_tooltip = {
					text = laamp_base_learning_contract_events.4100.c.diplomacy.support_not_exists.tt
					NOT = { scope:support_person ?= root }
				}
			}
			#Martial
			trigger_else_if = {
				limit = { scope:lesson_topic = flag:martial_topic }
				custom_tooltip = {
					text = laamp_base_learning_contract_events.4100.c.martial.support_not_exists.tt
					NOT = { scope:support_person ?= root }
				}
			}
			#Stewardship
			trigger_else_if = {
				limit = { scope:lesson_topic = flag:stewardship_topic }
				custom_tooltip = {
					text = laamp_base_learning_contract_events.4100.c.stewardship.support_not_exists.tt
					NOT = { scope:support_person ?= root }
				}
			}
			#Intrigue
			trigger_else_if = {
				limit = { scope:lesson_topic = flag:intrigue_topic }
				custom_tooltip = {
					text = laamp_base_learning_contract_events.4100.c.intrigue.support_not_exists.tt
					NOT = { scope:support_person ?= root }
				}
			}
			#Learning
			trigger_else_if = {
				limit = { scope:lesson_topic = flag:learning_topic }
				custom_tooltip = {
					text = laamp_base_learning_contract_events.4100.c.learning.support_not_exists.tt
					NOT = { scope:support_person ?= root }
				}
			}
			#Prowess
			trigger_else_if = {
				limit = { scope:lesson_topic = flag:prowess_topic }
				custom_tooltip = {
					text = laamp_base_learning_contract_events.4100.c.prowess.support_not_exists.tt
					NOT = { scope:support_person ?= root }
				}
			}
			trigger_else = { always = no }
		}
		show_as_unavailable = { exists = scope:lesson_topic }
		reason = skilled_follower
		#Pretty self-explanatory
		custom_tooltip = laamp_base_learning_contract_events.4100.tt.support_skill
		#"Duel"
		random_list = {
			0 = {
				desc = laamp_base_learning_contract_events.4100.tt.support_skill.success
				send_interface_toast = {
					title = laamp_base_learning_contract_events.4100.tt.support_skill.success
					left_icon = scope:support_person
					4100_success_effect = yes
				}
				#How trained are they in the subject matter?
				modifier = {
					scope:lesson_topic = flag:diplomacy_topic
					add = { 
						scope:support_person ?= { add = diplomacy }
						multiply = 20
						min = 5
						max = 95
					}
				}
				modifier = {
					scope:lesson_topic = flag:martial_topic
					add = { 
						scope:support_person ?= { add = martial }
						multiply = 20
						min = 5
						max = 95
					}
				}
				modifier = {
					scope:lesson_topic = flag:stewardship_topic
					add = { 
						scope:support_person ?= { add = stewardship }
						multiply = 20
						min = 5
						max = 95
					}
				}
				modifier = {
					scope:lesson_topic = flag:intrigue_topic
					add = { 
						scope:support_person ?= { add = intrigue }
						multiply = 20
						min = 5
						max = 95
					}
				}
				modifier = {
					scope:lesson_topic = flag:learning_topic
					add = { 
						scope:support_person ?= { add = learning }
						multiply = 20
						min = 5
						max = 95
					}
				}
				modifier = {
					scope:lesson_topic = flag:prowess_topic
					add = { 
						scope:support_person ?= { add = prowess }
						multiply = 20
						min = 5
						max = 95
					}
				}
				# Adjusted for difficulty.
				modifier = {
					add = {
						value = scope:task_contract.var:support_person_diff
						multiply = -1
					}
					always = yes
				}
			}
			0 = {
				desc = laamp_base_learning_contract_events.4100.tt.support_skill.failure
				send_interface_toast = {
					title = laamp_base_learning_contract_events.4100.tt.support_skill.failure
					left_icon = scope:support_person
					4100_failure_effect = yes
				}
				# Adjusted for difficulty.
				modifier = {
					add = scope:task_contract.var:support_person_diff
					always = yes
				}
			}
		}
		#Tally difficulty
		4100_adjust_difficulty_effect = {
			DIFF_SPIKE = support_person
			LEARNING = 2
			TOPIC = 2
			SUPPORT_PERSON = 5
			STRESS = 5
		}
		#Record most recent approach
		scope:task_contract = {
			set_variable = {
				name = education_approach_var
				value = flag:support
			}
		}
		# No stress here.
		ai_chance = {
			base = 1
			modifier = {
				factor = 2
				exists = scope:support_person
			}
		}
	}
	#Brute force: Stress
	option = {
		name = laamp_base_learning_contract_events.4100.d
		#The stress
		add_stress = scope:task_contract.var:stress_charge
		#'s all the reward you get'
		4100_partial_success_effect = yes
		#Tally difficulty
		4100_adjust_difficulty_effect = {
			DIFF_SPIKE = stress
			LEARNING = 2
			TOPIC = 2
			SUPPORT_PERSON = 5
			STRESS = 15 
		}
		#Record most recent approach
		scope:task_contract = {
			set_variable = {
				name = education_approach_var
				value = flag:stress
			}
		}
		# The AI always plays it risky.
		ai_chance = { base = 0 }
	}
	after = {
		#Ye're in a sticky situation, lad
		if = {
			limit = {
				AND = {
					scope:task_contract.var:educational_moments_left = 1
					scope:task_contract.var:wins_tally = 0
				} 
			}
			#Go big or go home-event
			trigger_event = laamp_base_learning_contract_events.4110
		}
		#We done yet?
		else_if = {
			limit = { scope:task_contract.var:educational_moments_left > 0 }
			#Reset the Support Person
			save_scope_as = support_person
			#Once more into the fray
			trigger_event = {
				id = laamp_base_learning_contract_events.4100
				days = { 20 50 }
			}
		}
		else = {
			#Conclusion
			trigger_event = {
				id = laamp_base_learning_contract_events.4120
				days = 1
			}
		}
	}
}


scripted_effect 4110_success_effect = {
	#Guaranteed success
	scope:task_contract = {
		increment_variable_effect = {
			VAR = wins_tally
			VAL = 2
		}
	}
	custom_tooltip = laamp_base_learning_contract_events.4100.tt.guaranteed_success
}

#Go big or go home
laamp_base_learning_contract_events.4110 = {
	type = character_event
	title = laamp_base_learning_contract_events.4110.t
	window = big_event_window
	desc = laamp_base_learning_contract_events.4110.desc
	theme = learning
	center_portrait = {
		character = root
		triggered_animation = {
			trigger = { exists = scope:alternative_language_culture }
			animation = thinking
		}
		animation = stress
	}
	right_portrait = {
		character = scope:child_to_educate
		camera = camera_event_scheme_vs_extra_right_look_right
		triggered_animation = {
			trigger = { 
				scope:child_to_educate = { age >= 12 }
			}
			animation = disapproval
		}
		animation = personality_irrational
	}
	# Backgrounds indented +1 for easier folding.
		override_background = {
			trigger = { scope:background = flag:alley_day }
			reference = alley_day
		}
		override_background = {
			trigger = { scope:background = flag:gallows }
			reference = gallows
		}
		override_background = {
			trigger = { scope:background = flag:market }
			reference = market
		}
		override_background = {
			trigger = { scope:background = flag:docks }
			reference = docks
		}
		override_background = {
			trigger = { scope:background = flag:garden }
			reference = garden
		}
		override_background = {
			trigger = { scope:background = flag:tavern }
			reference = tavern
		}
		override_background = {
			trigger = { scope:background = flag:temple }
			reference = holy_site_generic
		}
		override_background = {
			trigger = { scope:background = flag:throneroom }
			reference = throne_room
		}
		override_background = {
			trigger = { scope:background = flag:armory }
			reference = armory
		}
		#Nature
		override_background = {
			trigger = { scope:background = flag:farmlands }
			reference = ep2_travel_settlement_farm
		}
		override_background = {
			trigger = { scope:background = flag:plains }
			reference = ep2_travel_settlement_hills
		}
		override_background = {
			trigger = { scope:background = flag:steppe }
			reference = ep2_travel_settlement_steppe
		}
		override_background = {
			trigger = { scope:background = flag:desert }
			reference = ep2_travel_settlement_desert
		}
		override_background = {
			trigger = { scope:background = flag:drylands }
			reference = drylands
		}
		override_background = {
			trigger = { scope:background = flag:oasis }
			reference = ce1_legendary_oasis
		}
		override_background = {
			trigger = { scope:background = flag:hills }
			reference = hills
		}
		override_background = {
			trigger = { scope:background = flag:mountains }
			reference = ep2_travel_settlement_mountains
		}
		override_background = {
			trigger = { scope:background = flag:wetlands }
			reference = wilderness_wetlands
		}
		#Forest
		override_background = {
			trigger = { scope:background = flag:foggy_forest }
			reference = ep2_hunt_foggy_forest
		}
		override_background = {
			trigger = { scope:background = flag:managed_forest }
			reference = ep2_forest_managed
		}
		override_background = {
			trigger = { scope:background = flag:pine_forest }
			reference = wilderness_forest_pine
		}
		override_background = {
			trigger = { scope:background = flag:forest }
			reference = wilderness_forest
		}
		override_background = {
			trigger = { scope:background = flag:forest_cave }
			reference = ep2_hunt_forest_cave
		}
		override_background = {
			trigger = { scope:background = flag:snowy_forest }
			reference = ep2_hunt_snowy_forest
		}
	trigger = {
		exists = scope:task_contract
		scope:task_contract.var:task_contract_target = { age < 15 }
	}
	on_trigger_fail = {
		if = {
			limit = {
				exists = scope:task_contract
			}
		send_interface_message = {
			title = laamp_base_learning_contract_events_invalidated_message.old
			type = diplo_contract_scheme_invalidated_message
			right_icon = scope:task_contract.task_contract_employer
			scope:task_contract = { invalidate_contract = yes }
			}
		}
	}
	immediate = {
		#Do we have an alternative language to stir things up?
		if = {
			limit = {
				is_ai = no
				OR = {
					scope:child_to_educate = {
						NOT = { knows_language_of_culture = root.culture }
					}
					AND = {
						num_of_known_languages > 1
						scope:child_to_educate = { knows_language_of_culture = root.culture }
					}
				}
			}
			every_culture_global = {
				limit = { 
					root = { knows_language_of_culture = prev }
					scope:child_to_educate = {
						NOT = { knows_language_of_culture = prev }
					}
				}
				save_scope_as = alternative_language_culture
			}
		}
		# Plus, stop us whilst we're here.
		hidden_effect = {
			current_travel_plan ?= { pause_travel_plan = yes }
		}
		# Finally, tell us where our total is at.
		4100_show_score_effect = yes
		custom_tooltip = laamp_base_learning_contract_events.4100.tt.opportunities_left
	}
	#Bruteforce: Massive stress
	option = {
		name = laamp_base_learning_contract_events.4110.a
		#The OMEGA stress
		add_stress = {
			value = {
				add = scope:task_contract.var:stress_charge
				multiply = 2
			}
		}
		#Success! Yaay...
		4110_success_effect = yes
		#Let's not
		ai_chance = {
			base = 0
		}
	}
	#Triggered: Try a different language/approach
	option = {
		name = laamp_base_learning_contract_events.4110.b
		trigger = {
			custom_tooltip = {
				text = laamp_base_learning_contract_events.4110.b.tt
				exists = scope:alternative_language_culture 
			}	
		}
		show_as_unavailable = { always = yes }
		reason = language
		#Success! Yaay...
		4110_success_effect = yes
		#Always yes
		ai_chance = {
			base = 100
		}
	}
	#Non
	option = {
		name = laamp_base_learning_contract_events.4110.c
		#Ye've been warned
		custom_tooltip = laamp_base_learning_contract_events.4110.c.tt
		#Eh, probably
		ai_chance = { base = 50 }
	}
	after = {
		#Up the count
		scope:task_contract = {
			increment_variable_effect = {
				VAR = educational_moments_left
				VAL = -1
			}
		}
		#Conclusion
		trigger_event = {
			id = laamp_base_learning_contract_events.4120
			days = 1
		}
	}
}

#Conclusion event
laamp_base_learning_contract_events.4120 = {
	type = character_event
	title = laamp_base_learning_contract_events.4120.t
	window = big_event_window
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:success_standard }
				desc = laamp_base_learning_contract_events.4120.desc.success
			}
			triggered_desc = {
				trigger = { exists = scope:success_critical }
				desc = laamp_base_learning_contract_events.4120.desc.success_critical
			}
			desc = laamp_base_learning_contract_events.4120.desc.failure
		}
	}
	theme = learning
	left_portrait = {
		character = scope:child_to_educate
		triggered_animation = {
			trigger = {
				NOT = { exists = scope:failure_standard }
			}
			animation = thinking
		}
		animation = personality_irrational
	}
	center_portrait = {
		character = root
		triggered_animation = {
			trigger = { exists = scope:success_standard }
			animation = personality_compassionate
		}
		triggered_animation = {
			trigger = { exists = scope:success_critical }
			animation = personality_zealous
		}
		animation = shame
	}
	right_portrait = {
		character = scope:employer
		triggered_animation = {
			trigger = { exists = scope:success_standard }
			animation = admiration
		}
		triggered_animation = {
			trigger = { exists = scope:success_critical }
			animation = ecstasy
		}
		animation = disapproval
	}
	override_background = { reference = throne_room }
	trigger = {
		exists = scope:task_contract
		scope:task_contract.var:task_contract_target = { age < 15 }
	}
	on_trigger_fail = {
		if = {
			limit = {
				exists = scope:task_contract
			}
		send_interface_message = {
			title = laamp_base_learning_contract_events_invalidated_message.old
			type = diplo_contract_scheme_invalidated_message
			right_icon = scope:task_contract.task_contract_employer
			scope:task_contract = { invalidate_contract = yes }
			}
		}
	}
	immediate = {
		if = {
			limit = { scope:task_contract.var:wins_tally = scope:task_contract.var:win_t2_threshold }
			save_scope_as = success_critical
		}
		else_if = {
			limit = { scope:task_contract.var:wins_tally = scope:task_contract.var:win_t1_threshold }
			save_scope_as = success_standard
		}
		else = { save_scope_as = failure_standard }
		# Plus, stop us whilst we're here.
		hidden_effect = {
			current_travel_plan ?= { pause_travel_plan = yes }
		}
		# Finally, tell us where our total is at.
		4100_show_score_effect = yes
	}
	#Yup, yup...
	option = {
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = { exists = scope:success_standard }
						desc = laamp_base_learning_contract_events.4120.a.success_standard
					}
					triggered_desc = {
						trigger = { exists = scope:success_critical }
						desc = laamp_base_learning_contract_events.4120.a.success_critical
					}
					desc = laamp_base_learning_contract_events.4120.a.failure_standard
				}
			}
		}
		scope:task_contract = {
			if = {
				limit = { exists = scope:success_standard }
				complete_task_contract = success_standard
			}
			else_if = {
				limit = { exists = scope:success_critical }
				complete_task_contract = success_critical
			}
			else = { complete_task_contract = failure_standard }
		}
		#*shrug*
		ai_chance = {
			base = 100
		}
	}
	after = { 
		remove_character_flag ?= is_in_task_contract_event_chain 
		hidden_effect = { current_travel_plan ?= { resume_travel_plan = yes } }
	}
}
