﻿namespace = tour_grounds_events

############################
## Tour Mini-Activity: Tour Grounds
############################
## Liege Events
## 6000-6999
## by Chad Uhl
############################
# tour_grounds_events.6000 - Liege: Orgy with vassal
# tour_grounds_events.6100 - Liege: Visit a Cathedral/Mosque (special building)
# tour_grounds_events.6200 - Liege: Visit some farmlands (buildings)
# tour_grounds_events.6201-4 - Bilateral: Child thief steals your gold in vassal's tradeport (buildings)
# tour_grounds_events.6300 - Liege: Gloryhound Vassal challenges you to a sparring match
#####################################################################################

######################
## Liege Events
## 6000-6999
## by Chad Uhl
######################

scripted_trigger has_multiple_consorts_trigger = {
	any_consort = {
		count > 2
		is_available_ai_adult = yes 
	}
}

scripted_effect tour_grounds_events_6000_sex_effect = {
	if = {
		limit = { sex_opposite_of = scope:stop_host_scope }
		# Set up the error blocker for cheating sex, because the vassal couple might be monogamous but are consenting to the experiment here.
		save_scope_as = ignore_cheating_error_check
		had_sex_with_effect = {
			CHARACTER = scope:stop_host_scope
			PREGNANCY_CHANCE = seduce_pregnancy_chance
		}
	}
	if = {
		limit = { sex_opposite_of = scope:orgy_consort_1 }
		# Set up the error blocker for cheating sex, because the vassal couple might be monogamous but are consenting to the experiment here.
		## Aaaand we set it up again because it gets cleaned up in the effect.
		save_scope_as = ignore_cheating_error_check
		had_sex_with_effect = {
			CHARACTER = scope:orgy_consort_1
			PREGNANCY_CHANCE = seduce_pregnancy_chance
		}
	}
	if = {
		limit = {
			exists = scope:orgy_consort_2
		}
		if = {
			limit = { sex_opposite_of = scope:orgy_consort_2 }
			# Set up the error blocker for cheating sex, because the vassal couple might be monogamous but are consenting to the experiment here.
			## Aaaand we set it up again because it gets cleaned up in the effect x2.
			save_scope_as = ignore_cheating_error_check
			had_sex_with_effect = {
				CHARACTER = scope:orgy_consort_2
				PREGNANCY_CHANCE = seduce_pregnancy_chance
			}
		}
	}
	if = {
		limit = {
			exists = scope:orgy_consort_3
		}
		if = {
			limit = { sex_opposite_of = scope:orgy_consort_3 }
			# Set up the error blocker for cheating sex, because the vassal couple might be monogamous but are consenting to the experiment here.
			## Aaaand we set it up again because it gets cleaned up in the effect x2.
			save_scope_as = ignore_cheating_error_check
			had_sex_with_effect = {
				CHARACTER = scope:orgy_consort_3
				PREGNANCY_CHANCE = seduce_pregnancy_chance
			}
		}
	}

	# Progress towards lover 
	if = {
		limit = {
			is_attracted_to_gender_of = scope:stop_host_scope
			scope:stop_host_scope = { is_attracted_to_gender_of = root }
		}
		progress_towards_lover_effect = {
			CHARACTER = scope:stop_host_scope
			REASON = lover_tour_grounds_orgy
			OPINION = default_lover_opinion
		} 
	}
	if = {
		limit = {
			is_attracted_to_gender_of = scope:orgy_consort_1
			scope:orgy_consort_1 = { is_attracted_to_gender_of = root }
		}
		progress_towards_lover_effect = {
			CHARACTER = scope:orgy_consort_1
			REASON = lover_tour_grounds_orgy
			OPINION = default_lover_opinion
		}
	}
	if = {
		limit = {
			exists = scope:orgy_consort_2
			is_attracted_to_gender_of = scope:orgy_consort_2
			scope:orgy_consort_2 = { is_attracted_to_gender_of = root }
		}
		progress_towards_lover_effect = {
			CHARACTER = scope:orgy_consort_2
			REASON = lover_tour_grounds_orgy
			OPINION = default_lover_opinion
		}
	}
	if = {
		limit = {
			exists = scope:orgy_consort_3
			is_attracted_to_gender_of = scope:orgy_consort_3
			scope:orgy_consort_3 = { is_attracted_to_gender_of = root }
		}
		progress_towards_lover_effect = {
			CHARACTER = scope:orgy_consort_3
			REASON = lover_tour_grounds_orgy
			OPINION = default_lover_opinion
		}
	}
}

# You happen upon your vassal and their partner(s) getting steamy and they invite you to join
tour_grounds_events.6000 = {
	type = activity_event
	title = tour_grounds_events.6000.t
	desc = {
		desc = tour_grounds_events.6000.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:orgy_consort_2
					exists = scope:orgy_consort_3
				}
				desc = tour_grounds_events.6000.desc.three_consorts
			}
			desc = tour_grounds_events.6000.desc.one_consort
		}
		desc = tour_grounds_events.6000.desc.outro
	}
	theme = tour_grounds

	override_background = { reference = bedchamber }
	left_portrait = {
		character = root
		animation = stunned
	}
	center_portrait = {
		character = scope:stop_host_scope
		animation = wedding_groom_right
	}
	right_portrait = {
		character = scope:orgy_consort_1
		animation = happiness
		camera = camera_event_very_right
	}
	lower_center_portrait = {
		trigger = { exists = scope:orgy_consort_3 }
		character = scope:orgy_consort_3
	}
	lower_right_portrait = {
		trigger = { exists = scope:orgy_consort_2 }
		character = scope:orgy_consort_2
	}
	
	trigger = {
		is_adult = yes
		exists = scope:stop_host_scope
		scope:stop_host_scope = {
			is_ai = yes 
			is_adult = yes 
			# Vassal or their primary consort is attracted to liege
			OR = {
				is_attracted_to_gender_of = root
				any_consort = {
					is_attracted_to_gender_of = root
				}
			}
			# Vassal has a partner/concubine(s)
			any_consort = {
				is_available_ai_adult = yes
			}
		}
		# No close family members allowed in sexy time, unless you're already incestuous
		trigger_if = {
			limit = {
				NOT = { is_incestuous_trigger = yes }
				trait_is_criminal_in_faith_trigger = { TRAIT = incestuous FAITH = root.faith GENDER_CHARACTER = root }
			}
			NOT = { is_close_or_extended_family_of = scope:stop_host_scope }
		}
		NOT = { has_sexuality = asexual }
	}

	cooldown = { years = 5 }

	weight_multiplier = {
		base = 1
		# weight up if either are deviants
		modifier = {
			add = 1  
			is_deviant_trigger = yes
		}
		modifier = {
			add = 1 
			exists = scope:stop_host_scope 
			scope:stop_host_scope = {
				is_deviant_trigger = yes
			}
		}
		# weight up for the vassal having multiple consorts
		modifier = {
			add = 1 
			exists = scope:stop_host_scope 
			scope:stop_host_scope = {
				has_multiple_consorts_trigger = yes
			}
		}
	}

	immediate = {
		scope:stop_host_scope = {
			# if stop host has 3 consorts, we save them all. otherwise, just the one
			random_consort = {
				save_scope_as = orgy_consort_1
				add_character_flag = is_naked
			}
			if = {
				limit = { has_multiple_consorts_trigger = yes }
				random_consort = {
					limit = {
						this != scope:orgy_consort_1
					}
					save_scope_as = orgy_consort_2
					add_character_flag = is_naked
				}
				random_consort = {
					limit = {
						NOR = {
							this = scope:orgy_consort_1
							this = scope:orgy_consort_2
						}
					}  
					save_scope_as = orgy_consort_3
					add_character_flag = is_naked
				}
			}
			add_character_flag = is_naked
		}
	}

	option = { # Join in on the sexy time
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = { is_deviant_trigger = yes }
						desc = tour_grounds_events.6000.b
					}
					desc = tour_grounds_events.6000.a
				}
			}
		}
		trigger = { might_cheat_on_every_partner_trigger = yes }
		scope:activity = {
			add_activity_log_entry = {
				key = tourgy_log
				tags = { good }
				character = scope:visiting_liege
				target = scope:stop_host_scope
				root = {
					tour_grounds_events_6000_sex_effect = yes
				}
			}
		}

		stress_impact = {
			shy = medium_stress_impact_gain
			temperate = medium_stress_impact_gain
			chaste = major_stress_impact_gain
			gregarious = minor_stress_impact_loss
			lustful = major_stress_impact_loss
			deviant = medium_stress_impact_loss
		}

		ai_chance = {
			base = 33
			ai_value_modifier = {
				ai_boldness = 1
				ai_sociability = 1
				ai_energy = 0.5
			}
			modifier = {
				add = 50
				OR = {
					has_trait = lustful 
					has_trait = deviant 
				}
			}
			modifier = {
				factor = 0 
				OR = {
					has_trait = chaste
					has_trait = temperate
					has_trait = shy 
				}
			}
		}
	}
	
	option = { # Refuse sexy time
		name = tour_grounds_events.6000.c

		stress_impact = {
			deviant = major_stress_impact_gain
			lustful = major_stress_impact_gain
			chaste = minor_stress_impact_loss
		}

		ai_chance = {
			base = 33 
			modifier = {
				add = 30 
				has_trait = chaste
			}
		}
	}
	after = {
		scope:stop_host_scope = {
			remove_character_flag = is_naked
		}
		scope:orgy_consort_1 = {
			remove_character_flag = is_naked
		}
		scope:orgy_consort_2 ?= {
			remove_character_flag = is_naked
		}
		scope:orgy_consort_3 ?= {
			remove_character_flag = is_naked
		}
	}
}

scripted_trigger tg_6100_appropriate_loved_one_memory_trigger = {
	OR = {
		has_memory_type = relative_died
		has_memory_type = spouse_died
		has_memory_type = friend_died
		has_memory_type = soulmate_died
	}
	any_memory_participant = {
		NOR = {
			has_relation_rival = root
			has_relation_nemesis = root
		}
		trigger_if = {
			limit = {
				is_alive = no
				exists = killer
			}
			killer != root
		}
	}
}

scripted_trigger tg_6100_not_religious_trigger = {
	OR = {
		has_trait = cynical
		any_secret = {
			type = secret_non_believer
		}
	}
}

scripted_trigger tg_6100_location_has_cathedral_trigger = {
	OR = {
		has_building_or_higher = holy_site_cathedral_01
		has_building_or_higher = holy_site_cologne_cathedral_01
		has_building_or_higher = holy_site_canterbury_cathedral_01
		has_building_or_higher = temple_of_uppsala_01
		has_building_or_higher = lund_cathedral_01
		has_building_or_higher = notre_dame_01
		has_building_or_higher = cluny_abbey_01
		has_building_or_higher = beta_giyorgis_01
		has_building_or_higher = holy_wisdom_01
		has_building_or_higher = duomo_florence_01
		has_building_or_higher = wawel_cathedral_01
	}
}

scripted_trigger tg_6100_location_has_mosque_trigger = {
	OR = {
		has_building_or_higher = holy_site_imam_ali_mosque_01
		has_building_or_higher = holy_site_great_mosque_of_mecca_01
		has_building_or_higher = holy_site_great_mosque_of_cordoba_01
		has_building_or_higher = holy_site_great_mosque_of_djenne_01
		has_building_or_higher = holy_site_great_mosque_of_samarra_01
		has_building_or_higher = holy_site_prophetic_mosque_01
		has_building_or_higher = damascus_mosque_01
	}
}

# Christian Cathedral / Mosque
tour_grounds_events.6100 = {
	type = activity_event
	title = tour_grounds_events.6100.t
	desc = {
		desc = tour_grounds_events.6100.desc.intro 
		first_valid = {
			triggered_desc = {
				trigger = {
					tg_6100_not_religious_trigger = yes
				}
				desc = tour_grounds_events.6100.desc.cynical
			}
			triggered_desc = {
				trigger = {
					has_trait = zealous
				}
				desc = tour_grounds_events.6100.desc.zealous
			}
			desc = tour_grounds_events.6100.desc
		}
	}

	theme = tour_grounds
	override_background = { reference = temple }

	left_portrait = {
		character = root
		triggered_animation = {
			trigger = {
				tg_6100_not_religious_trigger = yes
			}
			animation = eyeroll
		}
		triggered_animation = {
			trigger = {
				has_trait = zealous
			}
			animation = personality_zealous
		}
		animation = admiration
	}
	right_portrait = {
		character = scope:stop_host_scope
		animation = personality_honorable
	}
	
	trigger = {
		# check for a christian cathedral special building
		location = {
			has_special_building = yes
			OR = {
				tg_6100_location_has_cathedral_trigger = yes 
				tg_6100_location_has_mosque_trigger = yes
			}
		}
		# check that the host has the right religion
		scope:stop_host_scope = {
			trigger_if = {
				limit = {
					location = { tg_6100_location_has_cathedral_trigger = yes }
				}
				OR = { religion = religion:eastern_orthodox_religion religion = religion:catholic_religion religion = religion:protestant_religion }
			}
			trigger_if = {
				limit = { 
					location = { tg_6100_location_has_mosque_trigger = yes }
				}
				religion = religion:islam_religion
			}
		}
	}

	cooldown = { years = 5 }

	weight_multiplier = {
		base = 1
		modifier = {
			add = 1 
			scope:stop_host_scope = {
				has_trait = zealous
			}
		}
		modifier = {
			add = 2
			any_memory = {
				tg_6100_appropriate_loved_one_memory_trigger = yes
			}
		}
	}

	immediate = {
		# save scopes for loc
		save_scope_as = root_scope
		location = { save_scope_as = tour_grounds_event_location }

		# if root has a memory of a loved one dying, we pull that out to use in an option
		if = {
			limit = {
				any_memory = {
					tg_6100_appropriate_loved_one_memory_trigger = yes
				}
			}
			random_memory = {
				limit = { tg_6100_appropriate_loved_one_memory_trigger = yes }
				save_scope_as = tour_grounds_6100_beloved_memory
				random_memory_participant = {
					save_scope_as = tour_grounds_6100_beloved_char
				}
			}
		}
	}

	option = { # light a candle in memory of a dead loved one
		name = tour_grounds_events.6100.a

		trigger = {
			location = { tg_6100_location_has_cathedral_trigger = yes }
			exists = scope:tour_grounds_6100_beloved_memory
		}

		flavor = tour_grounds_events.6100.a.tt
		every_vassal_or_below = {
			custom = zealot_approves_of_religious_display
			vassal_stance = zealot
			add_opinion = {
				target = prev
				modifier = zealot_approves_of_religious_display_opinion
			}
		}
		if = {
			limit = {
				scope:activity = {
					has_activity_option = {
						category = special_type
						option = tour_type_majesty
					}
				}
			}
			increase_tour_success_effect = { POINTS = 1 }
		}

		add_piety = miniscule_piety_gain

		stress_impact = {
			base = minor_stress_impact_loss
			zealous = minor_stress_impact_loss
			cynical = medium_stress_impact_gain
		}

		ai_chance = {
			base = 33
			ai_value_modifier = {
				ai_boldness = 0.5
				ai_zeal = 1
			}
			modifier = {
				factor = 0 
				has_trait = cynical
			}
		}
	}

	option = { # pray for a dead loved one
		name = tour_grounds_events.6100.b

		trigger = {
			location = { tg_6100_location_has_mosque_trigger = yes }
			exists = scope:tour_grounds_6100_beloved_memory
		}

		flavor = tour_grounds_events.6100.b.tt
		every_vassal_or_below = {
			custom = zealot_approves_of_religious_display
			vassal_stance = zealot
			add_opinion = {
				target = prev
				modifier = zealot_approves_of_religious_display_opinion
			}
		}
		if = {
			limit = {
				scope:activity = {
					has_activity_option = {
						category = special_type
						option = tour_type_majesty
					}
				}
			}
			increase_tour_success_effect = { POINTS = 1 }
		}

		add_piety = miniscule_piety_gain

		stress_impact = {
			base = minor_stress_impact_loss
			zealous = minor_stress_impact_loss
			cynical = medium_stress_impact_gain
		}

		ai_chance = {
			base = 33
			ai_value_modifier = {
				ai_boldness = 0.5
				ai_zeal = 1
			}
			modifier = {
				factor = 0 
				has_trait = cynical
			}
		}
	}

	option = { # get a discount on building church holdings
		name = tour_grounds_events.6100.c

		add_character_modifier = {
			modifier = discounted_church_holding_build_cost_modifier
			years = 10
		}
		if = {
			limit = {
				scope:activity = {
					has_activity_option = {
						category = special_type
						option = tour_type_taxation
					}
				}
			}
			increase_tour_success_effect = { POINTS = 1 }
		}

		ai_chance = {
			base = 33 
			ai_value_modifier = {
				ai_rationality = 0.75
				ai_zeal = 0.5
				ai_sociability = 0.5
			}
			modifier = {
				factor = 0
				has_trait = cynical
			}
		}

		stress_impact = {
			cynical = major_stress_impact_gain
		}
	}
	
	option = { # ignore everything and there's a chance they find out your secret
		name = tour_grounds_events.6100.d

		trigger = {
			tg_6100_not_religious_trigger = yes
		}

		duel = {
			skills = { intrigue learning }
			target = scope:stop_host_scope
			50 = {
				desc = tour_grounds_events.6100.d.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				if = {
					limit = {
						any_secret = {
							type = secret_non_believer
						}
					}
					send_interface_toast = {
						left_icon = root
						right_icon = scope:stop_host_scope
						title = tour_grounds_events.6100.d.success
						add_character_modifier = {
							modifier = played_it_cool_modifier
							years = 10
						}
					}
				}
				else = {
					send_interface_toast = {
						left_icon = root
						right_icon = scope:stop_host_scope
						title = tour_grounds_events.6100.d.success
						every_vassal = {
							custom = zealot_approves_of_religious_display
							vassal_stance = zealot
							add_opinion = {
								target = prev
								modifier = zealot_approves_of_religious_display_opinion
							}
						}
					}
				}
			}
			50 = {
				desc = tour_grounds_events.6100.d.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				if = {
					limit = {
						any_secret = {
							type = secret_non_believer
						}
					}
					send_interface_toast = {
						left_icon = root
						right_icon = scope:stop_host_scope
						title = tour_grounds_events.6100.d.failure
						random_secret = {
							type = secret_non_believer
							reveal_to = scope:stop_host_scope
						}
					}
				}
				else = {
					send_interface_toast = {
						left_icon = root
						right_icon = scope:stop_host_scope
						title = tour_grounds_events.6100.d.failure
						every_vassal = {
							custom = zealot_disapproves_of_cynicism
							vassal_stance = zealot
							add_opinion = {
								target = prev
								modifier = zealot_disapproves_of_cynicism_opinion
							}
						}
					}
				}
			}
		}

		stress_impact = {
			zealous = medium_stress_impact_gain
			fickle = miniscule_stress_impact_loss
		}

		ai_chance = {
			ai_value_modifier = {
				ai_rationality = 0.5
				ai_zeal = 0.1
			}
		}
	}
}

# Pastures
# Orchards
# Cereal Fields
# Vassal let's it slip that they've had a bountiful harvest

# Checks that you, the liege, have the same building as the one you're seeing in your vassal's province
scripted_trigger tg_6200_does_root_have_matching_building_trigger = {
	OR = {
		AND = {
			root.var:building_focus = flag:pastures
			capital_province = { has_building_or_higher = pastures_01 }
		}
		AND = {
			root.var:building_focus = flag:orchard
			capital_province = { has_building_or_higher = orchards_01 }
		}
		AND = {
			root.var:building_focus = flag:cereal_fields
			capital_province = { has_building_or_higher = cereal_fields_01 }
		}
		AND = {
			root.var:building_focus = flag:hill_farms
			capital_province = { has_building_or_higher = hill_farms_01 }
		}
		AND = {
			root.var:building_focus = flag:plantations
			capital_province = { has_building_or_higher = plantations_01 }
		}
	}
}

# If there are multiple valid buildings for the event, pick one to focus on
scripted_effect tg_6200_pick_building_focus_effect = {
	random_list = {
		1 = {
			trigger = { 
				location.county = {
					any_county_province = { has_building_or_higher = pastures_01 } 
				}
			}
			set_variable = {
				name = building_focus 
				value = flag:pastures
			}
		}
		1 = {
			trigger = { 
				location.county = {
					any_county_province = { has_building_or_higher = orchards_01 } 
				}
			}
			set_variable = {
				name = building_focus 
				value = flag:orchard
			}
		}
		1 = {
			trigger = { 
				location.county = {
					any_county_province = { has_building_or_higher = cereal_fields_01 } 
				}
			}
			set_variable = {
				name = building_focus 
				value = flag:cereal_fields
			}
		}
		1 = {
			trigger = { 
				location.county = {
					any_county_province = { has_building_or_higher = hill_farms_01 } 
				}
			}
			set_variable = {
				name = building_focus 
				value = flag:hill_farms
			}
		}
		1 = {
			trigger = { 
				location.county = {
					any_county_province = { has_building_or_higher = plantations_01 } 
				}
			}
			set_variable = {
				name = building_focus 
				value = flag:plantations
			}
		}
	}
}

# Determine the difference in building level between the liege and vassal respectively
scripted_effect tg_6200_determine_building_level_diff_effect = {
	if = {
		limit = { root.var:building_focus = flag:pastures }
		# check vassal building level
		root.location = {
			switch = {
				trigger = has_building
				pastures_01 = {
					scope:root_scope = {
						set_variable = {
							name = vassal_building_level
							value = 1
						}
					}
				}
				pastures_02 = {
					scope:root_scope = {
						set_variable = {
							name = vassal_building_level
							value = 2
						}
					}
				}
				pastures_03 = {
					scope:root_scope = {
						set_variable = {
							name = vassal_building_level
							value = 3
						}
					}
				}
				pastures_04 = {
					scope:root_scope = {
						set_variable = {
							name = vassal_building_level
							value = 4
						}
					}
				}
				pastures_05 = {
					scope:root_scope = {
						set_variable = {
							name = vassal_building_level
							value = 5
						}
					}
				}
				pastures_06 = {
					scope:root_scope = {
						set_variable = {
							name = vassal_building_level
							value = 6
						}
					}
				}
				pastures_07 = {
					scope:root_scope = {
						set_variable = {
							name = vassal_building_level
							value = 7
						}
					}
				}
				pastures_08 = {
					scope:root_scope = {
						set_variable = {
							name = vassal_building_level
							value = 8
						}
					}
				}
			}
		}
		# check root building level
		root.capital_province = {
			switch = {
				trigger = has_building
				pastures_01 = {
					scope:root_scope = {
						set_variable = {
							name = root_building_level
							value = 1
						}
					}
				}
				pastures_02 = {
					scope:root_scope = {
						set_variable = {
							name = root_building_level
							value = 2
						}
					}
				}
				pastures_03 = {
					scope:root_scope = {
						set_variable = {
							name = root_building_level
							value = 3
						}
					}
				}
				pastures_04 = {
					scope:root_scope = {
						set_variable = {
							name = root_building_level
							value = 4
						}
					}
				}
				pastures_05 = {
					scope:root_scope = {
						set_variable = {
							name = root_building_level
							value = 5
						}
					}
				}
				pastures_06 = {
					scope:root_scope = {
						set_variable = {
							name = root_building_level
							value = 6
						}
					}
				}
				pastures_07 = {
					scope:root_scope = {
						set_variable = {
							name = root_building_level
							value = 7
						}
					}
				}
				pastures_08 = {
					scope:root_scope = {
						set_variable = {
							name = root_building_level
							value = 8
						}
					}
				}
			}
		}
	}
	else_if = {
		limit = { root.var:building_focus = flag:orchard }
		# check vassal building level
		root.location = {
			switch = {
				trigger = has_building
				orchards_01 = {
					root = {
						set_variable = {
							name = vassal_building_level
							value = 1
						}
					}
				}
				orchards_02 = {
					root = {
						set_variable = {
							name = vassal_building_level
							value = 2
						}
					}
				}
				orchards_03 = {
					root = {
						set_variable = {
							name = vassal_building_level
							value = 3
						}
					}
				}
				orchards_04 = {
					root = {
						set_variable = {
							name = vassal_building_level
							value = 4
						}
					}
				}
				orchards_05 = {
					root = {
						set_variable = {
							name = vassal_building_level
							value = 5
						}
					}
				}
				orchards_06 = {
					root = {
						set_variable = {
							name = vassal_building_level
							value = 6
						}
					}
				}
				orchards_07 = {
					root = {
						set_variable = {
							name = vassal_building_level
							value = 7
						}
					}
				}
				orchards_08 = {
					root = {
						set_variable = {
							name = vassal_building_level
							value = 8
						}
					}
				}
			}
		}
		# check root building level
		root.capital_province = {
			switch = {
				trigger = has_building
				orchards_01 = {
					root = {
						set_variable = {
							name = root_building_level
							value = 1
						}
					}
				}
				orchards_02 = {
					root = {
						set_variable = {
							name = root_building_level
							value = 2
						}
					}
				}
				orchards_03 = {
					root = {
						set_variable = {
							name = root_building_level
							value = 3
						}
					}
				}
				orchards_04 = {
					root = {
						set_variable = {
							name = root_building_level
							value = 4
						}
					}
				}
				orchards_05 = {
					root = {
						set_variable = {
							name = root_building_level
							value = 5
						}
					}
				}
				orchards_06 = {
					root = {
						set_variable = {
							name = root_building_level
							value = 6
						}
					}
				}
				orchards_07 = {
					root = {
						set_variable = {
							name = root_building_level
							value = 7
						}
					}
				}
				orchards_08 = {
					root = {
						set_variable = {
							name = root_building_level
							value = 8
						}
					}
				}
			}
		}
	}
	else_if = {
		limit = { root.var:building_focus = flag:cereal_fields }
		# check vassal building level
		root.location = {
			switch = {
				trigger = has_building
				cereal_fields_01 = {
					root = {
						set_variable = {
							name = vassal_building_level
							value = 1
						}
					}
				}
				cereal_fields_02 = {
					root = {
						set_variable = {
							name = vassal_building_level
							value = 2
						}
					}
				}
				cereal_fields_03 = {
					root = {
						set_variable = {
							name = vassal_building_level
							value = 3
						}
					}
				}
				cereal_fields_04 = {
					root = {
						set_variable = {
							name = vassal_building_level
							value = 4
						}
					}
				}
				cereal_fields_05 = {
					root = {
						set_variable = {
							name = vassal_building_level
							value = 5
						}
					}
				}
				cereal_fields_06 = {
					root = {
						set_variable = {
							name = vassal_building_level
							value = 6
						}
					}
				}
				cereal_fields_07 = {
					root = {
						set_variable = {
							name = vassal_building_level
							value = 7
						}
					}
				}
				cereal_fields_08 = {
					root = {
						set_variable = {
							name = vassal_building_level
							value = 8
						}
					}
				}
			}
		}
		# check root building level
		root.capital_province = {
			switch = {
				trigger = has_building
				cereal_fields_01 = {
					root = {
						set_variable = {
							name = root_building_level
							value = 1
						}
					}
				}
				cereal_fields_02 = {
					root = {
						set_variable = {
							name = root_building_level
							value = 2
						}
					}
				}
				cereal_fields_03 = {
					root = {
						set_variable = {
							name = root_building_level
							value = 3
						}
					}
				}
				cereal_fields_04 = {
					root = {
						set_variable = {
							name = root_building_level
							value = 4
						}
					}
				}
				cereal_fields_05 = {
					root = {
						set_variable = {
							name = root_building_level
							value = 5
						}
					}
				}
				cereal_fields_06 = {
					root = {
						set_variable = {
							name = root_building_level
							value = 6
						}
					}
				}
				cereal_fields_07 = {
					root = {
						set_variable = {
							name = root_building_level
							value = 7
						}
					}
				}
				cereal_fields_08 = {
					root = {
						set_variable = {
							name = root_building_level
							value = 8
						}
					}
				}
			}
		}	
	}
	else_if = {
		limit = { root.var:building_focus = flag:hill_farms }
		# check vassal building level
		root.location = {
			switch = {
				trigger = has_building
				hill_farms_01 = {
					root = {
						set_variable = {
							name = vassal_building_level
							value = 1
						}
					}
				}
				hill_farms_02 = {
					root = {
						set_variable = {
							name = vassal_building_level
							value = 2
						}
					}
				}
				hill_farms_03 = {
					root = {
						set_variable = {
							name = vassal_building_level
							value = 3
						}
					}
				}
				hill_farms_04 = {
					root = {
						set_variable = {
							name = vassal_building_level
							value = 4
						}
					}
				}
				hill_farms_05 = {
					root = {
						set_variable = {
							name = vassal_building_level
							value = 5
						}
					}
				}
				hill_farms_06 = {
					root = {
						set_variable = {
							name = vassal_building_level
							value = 6
						}
					}
				}
				hill_farms_07 = {
					root = {
						set_variable = {
							name = vassal_building_level
							value = 7
						}
					}
				}
				hill_farms_08 = {
					root = {
						set_variable = {
							name = vassal_building_level
							value = 8
						}
					}
				}
			}
		}
		# check root building level
		root.capital_province = {
			switch = {
				trigger = has_building
				hill_farms_01 = {
					root = {
						set_variable = {
							name = root_building_level
							value = 1
						}
					}
				}
				hill_farms_02 = {
					root = {
						set_variable = {
							name = root_building_level
							value = 2
						}
					}
				}
				hill_farms_03 = {
					root = {
						set_variable = {
							name = root_building_level
							value = 3
						}
					}
				}
				hill_farms_04 = {
					root = {
						set_variable = {
							name = root_building_level
							value = 4
						}
					}
				}
				hill_farms_05 = {
					root = {
						set_variable = {
							name = root_building_level
							value = 5
						}
					}
				}
				hill_farms_06 = {
					root = {
						set_variable = {
							name = root_building_level
							value = 6
						}
					}
				}
				hill_farms_07 = {
					root = {
						set_variable = {
							name = root_building_level
							value = 7
						}
					}
				}
				hill_farms_08 = {
					root = {
						set_variable = {
							name = root_building_level
							value = 8
						}
					}
				}
			}
		}	
	}
	else_if = {
		limit = { root.var:building_focus = flag:plantations }
		# check vassal building level
		root.location = {
			switch = {
				trigger = has_building
				plantations_01 = {
					root = {
						set_variable = {
							name = vassal_building_level
							value = 1
						}
					}
				}
				plantations_02 = {
					root = {
						set_variable = {
							name = vassal_building_level
							value = 2
						}
					}
				}
				plantations_03 = {
					root = {
						set_variable = {
							name = vassal_building_level
							value = 3
						}
					}
				}
				plantations_04 = {
					root = {
						set_variable = {
							name = vassal_building_level
							value = 4
						}
					}
				}
				plantations_05 = {
					root = {
						set_variable = {
							name = vassal_building_level
							value = 5
						}
					}
				}
				plantations_06 = {
					root = {
						set_variable = {
							name = vassal_building_level
							value = 6
						}
					}
				}
				plantations_07 = {
					root = {
						set_variable = {
							name = vassal_building_level
							value = 7
						}
					}
				}
				plantations_08 = {
					root = {
						set_variable = {
							name = vassal_building_level
							value = 8
						}
					}
				}
			}
		}
		# check root building level
		root.capital_province = {
			switch = {
				trigger = has_building
				plantations_01 = {
					root = {
						set_variable = {
							name = root_building_level
							value = 1
						}
					}
				}
				plantations_02 = {
					root = {
						set_variable = {
							name = root_building_level
							value = 2
						}
					}
				}
				plantations_03 = {
					root = {
						set_variable = {
							name = root_building_level
							value = 3
						}
					}
				}
				plantations_04 = {
					root = {
						set_variable = {
							name = root_building_level
							value = 4
						}
					}
				}
				plantations_05 = {
					root = {
						set_variable = {
							name = root_building_level
							value = 5
						}
					}
				}
				plantations_06 = {
					root = {
						set_variable = {
							name = root_building_level
							value = 6
						}
					}
				}
				plantations_07 = {
					root = {
						set_variable = {
							name = root_building_level
							value = 7
						}
					}
				}
				plantations_08 = {
					root = {
						set_variable = {
							name = root_building_level
							value = 8
						}
					}
				}
			}
		}
	}

	set_variable = {
		name = building_level_diff
		value = root.var:root_building_level
	}
	change_variable = {
		name = building_level_diff
		divide = root.var:vassal_building_level
	}
}

tour_grounds_events.6200 = {
	type = activity_event
	title = tour_grounds_events.6200.t
	desc = {
		desc = tour_grounds_events.6200.desc
		first_valid = {
			triggered_desc = {
				trigger = { root.var:building_focus = flag:pastures }
				desc = tour_grounds_events.6200.desc.pastures
			}
			triggered_desc = {
				trigger = { root.var:building_focus = flag:orchard }
				desc = tour_grounds_events.6200.desc.orchard
			}
			triggered_desc = {
				trigger = { root.var:building_focus = flag:cereal_fields }
				desc = tour_grounds_events.6200.desc.cereal_fields
			}
			triggered_desc = {
				trigger = { root.var:building_focus = flag:hill_farms }
				desc = tour_grounds_events.6200.desc.hill_farms
			}
			triggered_desc = {
				trigger = { root.var:building_focus = flag:plantations }
				desc = tour_grounds_events.6200.desc.plantations
			}
		}
		desc = tour_grounds_events.6200.outro
	}

	cooldown = { years = 5 }

	theme = tour_grounds
	override_background = { reference = farmland }

	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		character = scope:stop_host_scope
		animation = personality_honorable
	}
	
	trigger = {
		# check for pastures/orchards/cereal fields and that root has a matching building in their capital province
		location.county = {
			any_county_province = {
				OR = {
					trigger_if = {
						limit = { has_building_or_higher = pastures_01 }
						root.capital_province = { has_building_or_higher = pastures_01 }
					}
					trigger_if = {
						limit = { has_building_or_higher = orchards_01 }
						root.capital_province = { has_building_or_higher = orchards_01 }
					}
					trigger_if = {
						limit = { has_building_or_higher = cereal_fields_01 }
						root.capital_province = { has_building_or_higher = cereal_fields_01 }
					}
					trigger_if = {
						limit = { has_building_or_higher = hill_farms_01 }
						root.capital_province = { has_building_or_higher = hill_farms_01 }
					}
					trigger_if = {
						limit = { has_building_or_higher = plantations_01 }
						root.capital_province = { has_building_or_higher = plantations_01 }
					}
				}
			}
		}
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		# save scopes for loc
		save_scope_as = root_scope
		location.county = {
			random_county_province = {
				limit = {
					OR = {
						has_building_or_higher = pastures_01
						has_building_or_higher = orchards_01
						has_building_or_higher = cereal_fields_01
						has_building_or_higher = hill_farms_01
						has_building_or_higher = plantations_01
					}
				}
				save_scope_as = tour_grounds_event_location
			}
		}
		capital_province = { save_scope_as = root_capital_scope }

		# Pick which building we want to focus on
		tg_6200_pick_building_focus_effect = yes

		if = {
			limit = {
				# technically shouldn't be necessary, but prevents errors
				exists = root.var:building_focus
				# check if root has the right building
				tg_6200_does_root_have_matching_building_trigger = yes
			}
			# determine the difference in their building level
			tg_6200_determine_building_level_diff_effect = yes
		}
	}

	option = { # You're pulling in a lot of grain here, time to up the ole tax
		name = tour_grounds_events.6200.a

		custom_tooltip = tour_grounds_events.6200.a.tt

		# You attempt to extort your vassal 
		scope:stop_host_scope = {
			trigger_event = {
				id = tour_grounds_events.6201
				days = 5
			}
		}

		# decrease opinion with parochial vassals
		every_vassal = {
			custom = every_parochial_vassal
			add_opinion = {
				modifier = angry_opinion
				opinion = -20
				target = root
			}
		}

		if = {
			limit = {
				scope:activity = {
					has_activity_option = {
						category = special_type
						option = tour_type_taxation
					}
				}
			}
			increase_tour_success_effect = { POINTS = 1 }
		}

		stress_impact = {
			greedy = minor_stress_impact_loss
			diligent = minor_stress_impact_loss
			content = minor_stress_impact_gain
			generous = medium_stress_impact_gain
		}

		ai_chance = {
			base = 33
			ai_value_modifier = {
				ai_greed = 1
				ai_rationality = 0.5
				ai_sociability = 0.5
			}
			modifier = {
				add = 20 
				has_trait = greedy 
			}
			modifier = {
				add = -30
				OR = {
					has_trait = content
					has_trait = generous
				}
			}
		}
	}

	option = { # 
		name = tour_grounds_events.6200.b

		# learn the vassal's secret to success
		add_character_modifier = {
			modifier = bountiful_harvest_modifier
			years = 10
		}

		if = {
			# check if root has the right building
			limit = {
				has_lifestyle = stewardship_lifestyle
			}

			add_stewardship_lifestyle_xp = major_lifestyle_xp
		}

		stress_impact = {
			lazy = minor_stress_impact_gain
			diligent = minor_stress_impact_loss
		}

		ai_chance = {
			base = 33
			ai_value_modifier = {
				ai_rationality = 0.8
				ai_sociability = 0.8
			}
			modifier = {
				add = 20 
				has_trait = diligent 
			}
			modifier = {
				add = -30
				has_trait = lazy
			}
		}
	}
	
	option = { # Be nice and don't do anything
		name = tour_grounds_events.6200.c

		reverse_add_opinion = {
			target = scope:stop_host_scope
			modifier = pleased_opinion
			opinion = 20
		}

		if = {
			limit = {
				scope:activity = {
					has_activity_option = {
						category = special_type
						option = tour_type_majesty
					}
				}
			}
			increase_tour_success_effect = { POINTS = 1 }
		}

		stress_impact = {
			generous = minor_stress_impact_loss
			humble = minor_stress_impact_loss
			calm = miniscule_stress_impact_loss
		}

		ai_chance = {
			base = 33
			ai_value_modifier = {
				ai_greed = -0.5
				ai_sociability = 0.8
			}
		}
	}

	after = {
		if = {
			limit = { exists = root.var:building_focus }
			remove_variable = building_focus
		}
		if = {
			limit = { exists = root.var:vassal_building_level }
			remove_variable = vassal_building_level
		}
		if = {
			limit = { exists = root.var:root_building_level }
			remove_variable = root_building_level
		}
		if = {
			limit = { exists = root.var:building_level_diff }
			remove_variable = root_building_level
		}
	}
}

# follow-up event for vassal 
tour_grounds_events.6201 = {
	type = character_event 
	title = tour_grounds_events.6201.t
	desc = tour_grounds_events.6201.desc 

	theme = tour_grounds 

	left_portrait = {
		character = root
		animation = worry
	}
	right_portrait = {
		character = scope:visiting_liege
		animation = personality_rational
	}

	option = { # accept a tax obligation increase 
		name = tour_grounds_events.6201.a
		trigger = { vassal_contract_obligation_level_can_be_increased = feudal_government_taxes }
		# Increase vassal's tax obligation
		scope:visiting_liege = {
			send_interface_toast = {
				title = tour_grounds_events.6201.a.tt
				left_icon = scope:visiting_liege
				right_icon = scope:stop_host_scope
				scope:stop_host_scope = {
					vassal_contract_increase_obligation_level = feudal_government_taxes
					progress_towards_friend_effect = {
						REASON = friend_accepted_tax_increase
						CHARACTER = scope:visiting_liege
						OPINION = default_friend_opinion
					}
				}
			}
		}

		ai_chance = {
			base = 0 
		}
	}

	option = { # give your liege the extra profits
		name = tour_grounds_events.6201.b
		scope:visiting_liege = {
			send_interface_toast = {
				title = tour_grounds_events.6201.b.tt
				left_icon = scope:visiting_liege
				right_icon = scope:stop_host_scope
				scope:stop_host_scope = {
					pay_short_term_gold = {
						target = scope:visiting_liege
						gold = medium_gold_value
					}
					progress_towards_friend_effect = {
						REASON = friend_split_profits
						CHARACTER = scope:visiting_liege
						OPINION = default_friend_opinion
					}
				}
			}
		}

		ai_chance = {
			base = 0 
		}
	}

	option = { # deny your liege's demand
		name = tour_grounds_events.6201.c
		add_treasury_or_gold = medium_treasury_or_gold_value
		# give imprisonment reason
		scope:visiting_liege = {
			send_interface_toast = {
				title = tour_grounds_events.6201.c.tt
				left_icon = scope:visiting_liege
				right_icon = scope:stop_host_scope
				add_opinion = {
					target = scope:stop_host_scope
					modifier = embezzled_opinion
				}
			}
		}
		ai_chance = {
			base = 100 
		}
	}
}

# Tradeport
# Liege: Gold is stolen at Vassal's tradeport
tour_grounds_events.6202 = {
	type = activity_event
	title = tour_grounds_events.6202.t
	desc = tour_grounds_events.6202.desc

	theme = tour_grounds
	override_background = { reference = docks }

	left_portrait = {
		character = scope:stop_host_scope
		animation = shock
	}
	right_portrait = {
		character = scope:tiny_thief
		animation = schadenfreude
	}

	cooldown = { years = 5 }

	trigger = {
		location.county = {
			any_county_province = {
				has_building_or_higher = common_tradeport_01
			}
		}
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		save_scope_as = root_scope 
		location.county = {
			random_county_province = {
				limit = { has_building_or_higher = common_tradeport_01 }
				save_scope_as = event_location
			}
		}

		# create our tiny little thief to do the thieving
		create_character = {
			template = child_thief_character
			culture = scope:stop_host_scope.culture
			faith = scope:stop_host_scope.faith
			location = root.location
			save_scope_as = tiny_thief
		}

		# tiny_thief takes your gold!
		remove_short_term_gold = medium_gold_value

		set_variable = {
			name = gold_lost
			value = medium_gold_value
		}
	}

	option = { # Fix this, you dumb vassal!
		name = tour_grounds_events.6202.a

		custom_tooltip = tour_grounds_events.6202.a.tt
		random_list = {
			1 = {
				show_chance = no 
				desc = tour_grounds_events.6202.a.success
				custom_tooltip =  tour_grounds_events.6202.b.success
			}
			1 = {
				show_chance = no
				desc = tour_grounds_events.6202.a.failure
				custom_tooltip =  tour_grounds_events.6202.b.failure
			}
		}

		scope:stop_host_scope = {
			trigger_event = {
				id = tour_grounds_events.6203
				days = { 1 5 }
			}
		}

		stress_impact = {
			diligent = minor_stress_impact_gain
		}

		ai_chance = {
			base = 33
			ai_value_modifier = {
				ai_greed = 1
				ai_sociability = 0.5
				ai_energy = 0.1
				ai_vengefulness = 0.5
			}
		}
	}

	option = { # Chase after the tiny_thief yourself
		name = tour_grounds_events.6202.b

		duel = {
			skills = { prowess intrigue }
			target = scope:tiny_thief
			40 = { # You succeed in catching the tiny thief
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				custom_tooltip = tour_grounds_events.6202.b.success
				show_as_tooltip = {
					if = {
						limit = {
							scope:activity = {
								has_activity_option = {
									category = special_type
									option = tour_type_taxation
								}
							}
						}
						increase_tour_success_effect = { POINTS = 1 }
					}
				}
				add_character_flag = caught_tiny_thief
				trigger_event = {
					id = tour_grounds_events.6204
					days = { 1 5 }
				}
			}
			60 = { # You fail to catch them and they are lost forever
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				custom_tooltip = tour_grounds_events.6202.b.failure
				send_interface_toast = {
					left_icon = root
					right_icon = scope:tiny_thief
					title = tour_grounds_events.6202.b.failure
				}
			}
		}

		stress_impact = {
			lazy = minor_stress_impact_gain
			humble = minor_stress_impact_gain
		}

		ai_chance = {
			base = 33
			ai_value_modifier = {
				ai_greed = 1
				ai_sociability = 0.5
				ai_energy = 1
				ai_vengefulness = 0.5
			}
		}
	}

	option = { # Let tiny_thief go
		name = tour_grounds_events.6202.c
		add_piety = major_piety_gain
		every_vassal_or_below = {
			vassal_stance = parochial
			custom = every_parochial_vassal
			add_opinion = {
				modifier = disapproving_opinion
				target = root
				opinion = -10
			}
		}

		if = { 
			limit = { exists = root.var:gold_lost }
			remove_variable = gold_lost
		}
		if = {
			limit = {
				scope:activity = {
					has_activity_option = {
						category = special_type
						option = tour_type_majesty
					}
				}
			}
			increase_tour_success_effect = { POINTS = 1 }
		}

		stress_impact = {
			greedy = medium_stress_impact_gain
			forgiving = medium_stress_impact_loss
			calm = minor_stress_impact_loss
			humble = minor_stress_impact_loss
		}

		ai_chance = {
			base = 33
			ai_value_modifier = {
				ai_greed = -1
				ai_sociability = 0.5
				ai_vengefulness = -0.5
			}
			modifier = {
				factor = 0
				OR = {
					has_trait = greedy
					has_trait = vengeful 
					has_trait = wrathful 
				}
			}
			modifier = {
				add = 10
				has_trait = humble
			}
		}
	}
}

# Vassal: decide what to do about the tiny_thief
tour_grounds_events.6203 = {
	type = character_event
	title = tour_grounds_events.6203.t
	desc = tour_grounds_events.6203.desc

	theme = tour_grounds
	override_background = { reference = docks }

	left_portrait = {
		character = scope:visiting_liege
		animation = anger
	}
	right_portrait = {
		character = scope:tiny_thief
		animation = laugh
	}

	option = { # Pay your liege their lost gold
		name = tour_grounds_events.6203.a
		scope:visiting_liege = {
			send_interface_toast = {
				left_icon = scope:stop_host_scope
				right_icon = scope:tiny_thief
				title = tour_grounds_events.6203.toast
				scope:stop_host_scope = {
					pay_short_term_gold = {
						target = scope:visiting_liege
						gold = scope:visiting_liege.var:gold_lost
					}
				}
			}
		}

		stress_impact = {
			greedy = medium_stress_impact_gain
			disloyal = minor_stress_impact_gain
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_greed = -1
				ai_sociability = 0.5
				ai_energy = -1
				ai_vengefulness = 0.5
			}
			modifier = {
				factor = 0 
				has_trait = greedy 
			}
		}
	}

	option = { # Chase after the tiny_thief yourself
		name = tour_grounds_events.6203.b

		duel = {
			skills = { prowess intrigue }
			target = scope:tiny_thief
			40 = {
				desc = tour_grounds_events.6202.b.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				send_interface_toast = {
					title = tour_grounds_events.6202.b.success
					left_icon = root
					right_icon = scope:tiny_thief
				}
				scope:visiting_liege = {
					trigger_event = {
						id = tour_grounds_events.6204
						days = { 1 5 }
					}
				}
			}
			60 = {
				desc = tour_grounds_events.6202.b.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				send_interface_toast = {
					title = tour_grounds_events.6202.b.failure
					left_icon = root
					right_icon = scope:tiny_thief
				}
				scope:visiting_liege = {
					trigger_event = {
						id = tour_grounds_events.6205
						days = { 1 5 }
					}
				}
			}
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_greed = 1
				ai_energy = 1
			}
		}
	}

	option = { # ain't my problem
		name = tour_grounds_events.6203.c

		reverse_add_opinion = {
			target = scope:visiting_liege
			modifier = disappointed_opinion
			opinion = -30
		}

		scope:visiting_liege = {
			trigger_event = {
				id = tour_grounds_events.6205
				days = { 1 5 }
			}
		}

		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_energy = -0.5
			}
			modifier = {
				factor = 0 
				has_trait = ambitious
			}
		}
	}
}

# Liege: tiny_thief is caught (either by vassal or liege themself)
tour_grounds_events.6204 = {
	type = activity_event
	title = tour_grounds_events.6204.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { has_character_flag = caught_tiny_thief }
				desc = tour_grounds_events.6204.desc.caught_by_liege
			}
			desc = tour_grounds_events.6204.desc.caught_by_vassal
		}
	}

	theme = tour_grounds
	override_background = { reference = docks }

	left_portrait = {
		character = scope:stop_host_scope
		animation = happiness
	}
	right_portrait = {
		character = scope:tiny_thief
		animation = sadness
	}

	immediate = {
		involved_activity = { save_scope_as = current_activity }
	}

	option = { # Take the gold
		name = tour_grounds_events.6204.a
		add_gold = root.var:gold_lost
		if = {
			limit = {
				scope:activity = {
					has_activity_option = {
						category = special_type
						option = tour_type_taxation
					}
				}
			}
			increase_tour_success_effect = { POINTS = 1 }
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_greed = 1
			}
		}
	}

	option = { # Take the tiny_thief under your wing
		name = tour_grounds_events.6204.b

		add_courtier = scope:tiny_thief
		scope:tiny_thief = {
			add_to_activity_without_travel = scope:current_activity
		}
		current_travel_plan = {
			add_companion = scope:tiny_thief
		}

		if = {
			limit = { num_of_relation_ward < 2 }
			set_relation_ward = {
				target = scope:tiny_thief
				reason = ward_tiny_thief
			}
			scope:tiny_thief = {
				set_default_education = yes
			}
		}

		every_vassal_or_below = {
			vassal_stance = courtly
			custom = every_courtly_vassal
			add_opinion = {
				modifier = disapproving_opinion
				target = root
				opinion = -10
			}
		}
		if = {
			limit = {
				scope:activity = {
					has_activity_option = {
						category = special_type
						option = tour_type_majesty
					}
				}
			}
			increase_tour_success_effect = { POINTS = 1 }
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_sociability = 0.75
				ai_energy = 0.75
			}
		}
	}

	after = {
		if = { 
			limit = { exists = root.var:gold_lost }
			remove_variable = gold_lost
		}
		if = {
			limit = { has_character_flag = caught_tiny_thief }
			remove_character_flag = caught_tiny_thief
		}
	}
}

# Liege responds to vassal failing to catch the tiny_thief
tour_grounds_events.6205 = {
	type = activity_event
	title = tour_grounds_events.6205.t
	desc = tour_grounds_events.6205.desc

	theme = tour_grounds
	override_background = { reference = docks }

	left_portrait = {
		character = root
		animation = anger
	}
	right_portrait = {
		character = scope:stop_host_scope
		animation = sadness
	}
	lower_center_portrait = {
		character = scope:tiny_thief
	}

	option = { # Demand the gold
		name = tour_grounds_events.6205.a

		duel = {
			skills = { diplomacy }
			target = scope:stop_host_scope
			60 = {
				desc = tour_grounds_events.6205.a.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				send_interface_toast = {
					left_icon = root 
					right_icon = scope:stop_host_scope
					title = tour_grounds_events.6205.a.success
					show_as_tooltip = {
						scope:stop_host_scope = {
							pay_short_term_gold = {
								target = scope:visiting_liege
								gold = scope:visiting_liege.var:gold_lost
							}
						}
					}
				}
				hidden_effect = {	
					scope:stop_host_scope = {
						send_interface_toast = {
							left_icon = scope:stop_host_scope 
							right_icon = scope:visiting_liege
							title = tour_grounds_events.6205.a.success
							pay_short_term_gold = {
								target = scope:visiting_liege
								gold = scope:visiting_liege.var:gold_lost
							}
						}
					}
				}
			}
			40 = {
				desc = tour_grounds_events.6205.a.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				send_interface_toast = {
					left_icon = root
					right_icon = scope:tiny_thief
					title = tour_grounds_events.6205.a.failure
					add_prestige = minor_prestige_loss
				}
			}
		}

		ai_chance = {
			base = 33
			ai_value_modifier = {
				ai_greed = -1
				ai_sociability = 0.5
				ai_energy = -1
				ai_vengefulness = 0.5
			}
			modifier = {
				factor = 0 
				has_trait = greedy 
			}
		}
	}

	option = { # Have the vassal whipped
		name = tour_grounds_events.6205.b
		trigger = {
			OR = {
				has_trait = sadistic
				has_trait = wrathful 
				dread >= 50
			}
		}

		flavor = tour_grounds_events.6205.b.flavor
		scope:stop_host_scope = {
			increase_wounds_no_death_effect = { REASON = beaten }
		}
		add_dread = minor_dread_gain
		reverse_add_opinion = {
			target = scope:stop_host_scope
			modifier = whipped_me_opinion
		}

		stress_impact = {
			sadistic = minor_stress_impact_loss
			wrathful = minor_stress_impact_loss
			compassionate = minor_stress_impact_gain
		}

		ai_chance = {
			base = 33
			ai_value_modifier = {
				ai_sociability = -0.5
				ai_energy = 0.5
				ai_vengefulness = 1
			}
			modifier = {
				factor = 0 
				has_trait = compassionate 
			}
			modifier = {
				add = 30
				OR = {
					has_trait = wrathful
					has_trait = sadistic 
				}
			}
		}
	}

	option = { # Forgive the vassal
		name = tour_grounds_events.6205.c

		reverse_add_opinion = {
			modifier = forgiven_opinion
			years = 10
			target = scope:stop_host_scope
		}

		stress_impact = {
			base = minor_stress_impact_gain 
			forgiving = medium_stress_impact_loss
			greedy = major_stress_impact_gain
			vengeful = medium_stress_impact_gain
			calm = minor_stress_impact_loss
			sadistic = medium_stress_impact_gain
		}

		ai_chance = {
			base = 33
			ai_value_modifier = {
				ai_greed = -1
				ai_sociability = 0.5
				ai_energy = -1
				ai_vengefulness = 0.5
			}
			modifier = {
				factor = 0 
				OR = {
					has_trait = greedy 
					has_trait = wrathful 
					has_trait = sadistic 
				}
			}
			modifier = {
				add = 30 
				has_trait = forgiving
			}
		}
	}

	after = {
		if = { 
			limit = { exists = root.var:gold_lost }
			remove_variable = gold_lost
		}
	}
}

# Liege: Vassal challenges you to an educational sparring match
tour_grounds_events.6300 = {
	type = activity_event
	title = tour_grounds_events.6300.t
	desc = tour_grounds_events.6300.desc

	theme = tour_grounds
	override_background = { reference = army_camp }

	left_portrait = {
		character = scope:stop_host_scope
		animation = personality_bold
	}
	right_portrait = {
		character = scope:target_knight
		animation = celebrate_sword
	}
	lower_center_portrait = {
		trigger = { exists = scope:tg_6300_stand_in }
		character = scope:tg_6300_stand_in
	}

	cooldown = { years = 10 }

	trigger = {
		scope:stop_host_scope = {
			trigger_if = {
				limit = { is_ai = yes }
				has_vassal_stance = glory_hound
			}
			any_knight = {
				is_available_ai_adult = yes 
				location = root.location
			}
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = 1 
			current_travel_plan = {
				any_entourage_character = {
					is_knight = yes
				}
			}
		}
	}

	immediate = {
		save_scope_as = root_scope
		location = { save_scope_as = event_location }
		# if possible, find a knight in the entourage
		if = {
			limit = {
				current_travel_plan = {
					any_entourage_character = {
						is_knight = yes 
					}
				}
			}
			current_travel_plan = {
				random_entourage_character = {
					limit = { is_knight = yes }
					save_scope_as = tg_6300_stand_in
				}
			}
		}

		scope:stop_host_scope = {
			random_knight = {
				limit = { location = root.location }
				save_scope_as = target_knight
			}
		}
		scope:target_knight = {
			add_character_flag = wear_armor
		}
		scope:tg_6300_stand_in ?= {
			add_character_flag = wear_armor
		}
	}

	option = { # Accept the invitation to spar
		name = tour_grounds_events.6300.a
		flavor = tour_grounds_events.6300.flavor

		duel = {
			skills = { prowess martial }
			target = scope:target_knight
			50 = {
				desc = tour_grounds_events.6300.a.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				send_interface_toast = {
					left_icon = root
					right_icon = scope:target_knight
					title = tour_grounds_events.6300.a.success
					# opinion bonus with glory hound vassals
					every_vassal_or_below = {
						vassal_stance = glory_hound
						custom = every_glory_hound_vassal
						add_opinion = {
							modifier = respect_opinion
							target = root
							opinion = 20
						}
					}
					if = {
						limit = {
							scope:activity = {
								OR = {
									has_activity_option = {
										category = special_type
										option = tour_type_majesty
									}
									has_activity_option = {
										category = special_type
										option = tour_type_intimidation
									}
								}
							}
						}
						increase_tour_success_effect = { POINTS = 1 }
					}
				}
			}
			50 = {
				desc = tour_grounds_events.6300.a.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				send_interface_toast = {
					left_icon = root
					right_icon = scope:stop_host_scope
					title = tour_grounds_events.6300.a.failure
					# opinion malus with glory hound vassals
					every_vassal_or_below = {
						vassal_stance = glory_hound
						limit = { 
							is_ai = yes
						}
						custom = every_glory_hound_vassal
						add_opinion = {
							modifier = disappointed_opinion
							target = root 
							opinion = -20
						}
					}
				}
			}
		}

		stress_impact = {
			craven = medium_stress_impact_gain
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = 1
				ai_energy = 1
			}
			modifier = {
				add = 30 
				has_trait = brave 
			}
			modifier = {
				add = -30 
				has_trait = craven 
			}
		}
	}

	option = { # Suggest that your knight give a demonstration
		name = tour_grounds_events.6300.b
		
		trigger = { exists = scope:tg_6300_stand_in }

		scope:tg_6300_stand_in = {
			duel = {
				skills = { prowess martial }
				target = scope:target_knight
				50 = {
					desc = tour_grounds_events.6300.b.success
					compare_modifier = {
						value = scope:duel_value
						multiplier = 3.5
						min = -49
					}
					root = {
						send_interface_toast = {
							left_icon = root
							right_icon = scope:stop_host_scope
							title = tour_grounds_events.6300.b.success
							# county modifier for winning
							location.county = {
								add_county_modifier = {
									modifier = prowess_demonstration_modifier
									years = 30
								}
							}
						}
					}
				}
				50 = {
					desc = tour_grounds_events.6300.b.failure
					compare_modifier = {
						value = scope:duel_value
						multiplier = -3.5
						min = -49
					}
					root = {
						send_interface_toast = {
							left_icon = root
							right_icon = scope:stop_host_scope
							title = tour_grounds_events.6300.b.failure
							add_prestige = minor_prestige_loss
						}
					}
				}
			}
		}

		stress_impact = {
			craven = minor_stress_impact_loss
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = 0.5
				ai_energy = 0.1
			}
			modifier = {
				add = -30 
				has_trait = brave 
			}
			modifier = {
				add = 30 
				has_trait = craven 
			}
		}
	}

	option = { # Decline
		name = tour_grounds_events.6300.c
		every_vassal_or_below = {
			vassal_stance = glory_hound
			custom = every_glory_hound_vassal
			add_opinion = {
				modifier = disappointed_opinion
				target = root
				opinion = -10
			}
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = -0.4
				ai_sociability = -0.3
			}
			modifier = {
				add = -20 
				has_trait = brave 
			}
			modifier = {
				add = 20 
				has_trait = craven 
			}
		}
	}
	after = {
		scope:target_knight = {
			remove_character_flag = wear_armor
		}
		scope:tg_6300_stand_in ?= {
			remove_character_flag = wear_armor
		}
	}
}

