﻿# Events for handling the excavation activity

namespace = excavation

## excavation events
## by Linnéa Thimrén, Petter Vilberg, Bianca Savazzi, and Joe Parkin

############################
## Setup and maintenance events
## 0000-0999
############################

############################
## Random event chains
## 1000-3999
## by Linnéa Thimrén and Petter Vilberg
############################
#excavation.1001 - Generic excavation, chase the animal!
#excavation.1011 - A vassal rival, or a vassal that doesn't like you, is being an ass
#excavation.1021 - Beautiful Peasant Chain: Meet a beautiful peasant in the forest
#excavation.1023 - You have a dog that helps you to fell an animal

############################
## Random pulse
## 4000-4999
## by Linnéa Thimrén and Petter Vilberg
############################
#excavation.4003 - Run into poachers
#excavation.4005 - You bring down a particularly large animal - II
#excavation.4006 - Poor Peasants are foraging in the forest
#excavation.4007 - Run into a rampaging animal
#excavation.4008 - excavation with your heir
#excavation.4009 - Someone has a murder/abduct scheme against you
#excavation.4010 - Someone has a murder/abduct scheme against a close family member
#excavation.4011 - Your lover has come with, sneak away together
#excavation.4012 - See glimpse of mystical animal
#excavation.4014 - A courtier is injured
#excavation.4015 - You walk in (out?) on lovers
#excavation.4016 - You fake a catch
#excavation.4018 - You get another glimpse of the mystical white animal
#excavation.4020 - Rally your clan to fell a large beast
#excavation.5001 - You get the urge to pick herbs and flowers
#excavation.5002 - Someone in your excavationing party gets the urge to pick herbs and
#excavation.5060 - Find an eyas
#excavation.7001 - Meet local madman
#excavation.7020 - Boulder jumping
#excavation.7100 - Seduce intent convo
#excavation.7200 - Falconry Practice

############################
## Choose your artifact events 
## 8001 - 8999	 
## by Bianca Savazzi
############################
#excavation.8001 - Hide or Skull?

############################
## Complication events
############################
#excavation.1002 - Chase goes well
#excavation.1012 - Do you shoot your murder target or not? - Ambush
#excavation.1080 - EP2: Party murders you
#excavation.3020 - EP2: Tracks skill check
#excavation.4009 - Participant has murder/abduct scheme against you (or you heir dislikes you)
#excavation.4010 - Participant has murder/abduct scheme against close family
#excavation.4910 - A guest is injured
#excavation.5010 - EP2: Fawning doe
#excavation.7011 - EP2: Trapped guest
#excavation_mystical_animal.1007 # Alice in Wonderland trip
#excavation.4018 - You get the mystical white animal!
#excavation.5050 - EP2: Falcon snatched

############################
## Outcome events
############################
#excavation.1003 # Chase success
#excavation.1004 # Chase failure
#excavation.1032 # Ambush success
#excavation.1033 # Ambush failure
#excavation.4001 # Stealth success
#excavation.1043 # Stealth failure
#excavation.1062 # Falconry success
#excavation.1063 # Falconry failure
#excavation.1052 # Captive success
#excavation.1053 # Captive failure
#excavation.4017 # Legendary animal found and killed 
#excavation.4019 # Substitute animal found
#excavation_mystical_animal.9001 # Legendary animal found and killed
#excavation_mystical_animal.1005 # Legendary animal found but escaped
#excavation.1090 # Legendary animal escaped
		
############################
## End-events
## 9000-9999
############################
#excavation.9001 - excavation has ended in success
#excavation.9002 - excavation has ended in failure
#excavation.4004 - You bring down a particularly large animal - I

#Things to use in excavation-events:
	# excavation_activity_standard_game_effect - find a game animal
	# excavation_activity_dangerous_game_effect - find a dangerous animal
	# excavation_activity_falconry_game_effect - find a falcon prey
	# excavation_activity_random_subordinate_participant_effect - save a subordinate on the excavation
	# excavation_activity_random_interest_participant_effect - save a notable guest
	# excavation_animal_melee_kill_effect - fight animal alone
	# excavation_animal_melee_kill_group_effect - fight animal with all excavationers
	# excavation_animal_bow_kill_effect - try to shoot animal


#####################################
#	SETUP AND MAINTENANCE EVENTS	#
#	0000 - 0099						#
#####################################

#######################
#	excavation invalidated
#	by Joe Parkin
#######################

# Death
excavation.0080 = {
	type = character_event
	title = {
		first_valid = {
			triggered_desc = {
				trigger = {
					NOR = {
						this = scope:host
						is_in_list = attendees
					}
				}
				desc = excavation.0080.t.inheritor
			}
			desc = excavation.0080.t
		}
	}
	desc = {
		first_valid = { # Summary
			# Dead Host
			triggered_desc = {
				trigger = {
					NOR = {
						this = scope:host
						is_in_list = attendees
					}
				}
				desc = excavation.0080.death_inheritor
			}
			triggered_desc = {
				trigger = {
					exists = scope:host.killer
					this = scope:killer
					NOR = {
						this = scope:host
						is_in_list = attendees
					}
				}
				desc = excavation.0080.death_inheritor_killer
			}
			# Dead Guest
			triggered_desc = {
				trigger = {
					exists = scope:host.killer
					this = scope:killer
					NOR = {
						this = scope:host
						is_in_list = attendees
					}
				}
				desc = excavation.0080.death_inheritor_killer
			}
			desc = excavation.0080.death
		}
		first_valid = {			
			triggered_desc = {
				trigger = {
					OR = {
						is_in_list = attendees
						this = scope:host
					}
					NAND = {
						has_character_flag = excavation_heir
						exists = scope:death_invalidation
						scope:invalidated_flavor ?= scope:host
					}
				}
				desc = excavation.0080.desc
			}
			desc = excavation.0080.desc_inheritor
		}
	}
	left_portrait = {
		character = root
		animation = worry
		trigger = { 
			OR = {
				is_in_list = attendees 
				this = scope:host
			}
		}
	}
	right_portrait = {
		character = scope:host
		trigger = {
			NOR = {
				this = root
				scope:invalidated_culprit ?= this 
			}
		}
		triggered_animation = {
			trigger = { is_alive = no }
			animation = loss_1
		}
		animation = stress
	}
	center_portrait = {
		character = scope:invalidated_flavor
		trigger = {
			exists = scope:invalidated_flavor
			NOR = {
				scope:invalidated_flavor ?= root
				scope:invalidated_flavor ?= scope:host
			}
		}
	}
	artifact = {
		position = lower_left_portrait
		target = scope:newly_created_artifact
		trigger = { exists = scope:newly_created_artifact }
	}
	theme = hunt_activity
	override_background = {
		trigger = { is_participant_in_activity = scope:activity }
		reference = wilderness
	}
	override_background = {
		trigger = {
			NOT = { is_participant_in_activity = scope:activity }
		}
		reference = relaxing_room
	}
	cooldown = { weeks = 1 }

	immediate = {
		if = {
			limit = {
				this != scope:host
			}
			excavation_invalidation_event_effect = yes
		}
	}

	option = {
		name = excavation.0080.a
		if = {
			limit = { exists = scope:newly_created_artifact }
			hidden_effect = { destroy_artifact = scope:newly_created_artifact }
		}
		ai_chance = {
			base = 100
		}
	}
	option = {
		name = excavation.1013.a
		trigger = { this = scope:host }
		scope:activity = {
			set_variable = {
				name = excavation_invalidated
				value = flag:death
			}
			set_variable = {
				name = excavation_invalidated_flavor
				value = scope:invalidated_flavor
			}
			if = {
				limit = { exists = scope:invalidated_culprit }
				set_variable = {
					name = excavation_invalidated_culprit
					value = scope:invalidated_culprit
				}
			}
		}
		excavation_invalidation_event_effect = yes
		if = {
			limit = { exists = scope:newly_created_artifact }
			hidden_effect = { destroy_artifact = scope:newly_created_artifact }
		}
		ai_chance = {
			base = 25
		}
	}
}

# Dead before excavation
excavation.0087 = {
	type = character_event
	title = excavation.0080.t
	desc = excavation.0080.death
	left_portrait = {
		character = root
		animation = worry
	}
	right_portrait = {
		character = scope:host
		triggered_animation = {
			trigger = { is_alive = no }
			animation = loss_1
		}
		animation = stress
	}
	theme = hunt_activity
	cooldown = { weeks = 1 }

	immediate = {
		if = {
			limit = { NOT = { this = scope:host } }
			excavation_invalidation_event_effect = yes
		}
	}

	option = {
		name = excavation.0080.a
		custom_tooltip = excavation_ends_tt
	}
}

# Wound Decision
excavation.0081 = {
	type = activity_event
	title = excavation.0081.t
	desc = {
		first_valid = { # Summary
			triggered_desc = {
				trigger = {
					NOR = {
						has_trait = wounded
						has_trait = maimed
					}
				}
				desc = excavation.0081.sick
			}
			desc = excavation.0081.wounded
		}
		first_valid = {
			triggered_desc = {
				trigger = { this = scope:host }
				desc = excavation.0081.host
			}
			desc = excavation.0081.guest
		}
	}
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = {
				NOR = {
					has_trait = wounded
					has_trait = maimed
				}
			}
			animation = pain
		}
		triggered_animation = {
			trigger = {
				OR = {
					has_trait = wounded
					has_trait = maimed
				}
			}
			animation = sick
		}
	}
	right_portrait = {
		character = scope:host
		trigger = {
			this != scope:host
		}
		animation = worry
	}
	theme = hunt_activity

	trigger = {
		is_healthy = no
		OR = {
			has_trait = wounded
			has_character_flag = recent_excavation_wound
		}
		NOT = { has_character_flag = excavation_wound_ignored }
		NOT = { exists = scope:activity.var:excavation_success }
	}

	option = {
		name = excavation.0081.a
		if = {
			limit = { this = scope:host }
			scope:activity = {
				set_variable = {
					name = excavation_invalidated
					value = flag:wound
				}
				set_variable = {
					name = excavation_invalidated_flavor
					value = scope:host
				}
			}
			excavation_invalidation_event_effect = yes
		}
		else = {
			scope:host = {
				send_interface_toast = {
					title = excavation_wounded_guest_leaves_toast
					left_icon = root
					root = { remove_from_activity = scope:activity }
				}
			}
		}
		stress_impact = {
			brave = minor_stress_impact_gain
			arrogant = minor_stress_impact_gain
		}
	}

	option = {
		name = excavation.0081.b
		add_character_flag = excavation_wound_ignored
		stress_impact = {
			craven = minor_stress_impact_gain
			humble = minor_stress_impact_gain
		}
	}
}

# Host Imprisoned
excavation.0082 = {
	type = character_event
	title = excavation.0080.t
	desc = {
		first_valid = { # Summary
			# Host Imprisoned
			triggered_desc = {
				trigger = {
					scope:host = {
						is_alive = yes
						is_imprisoned = yes
					}
					this = scope:host
				}
				desc = excavation.0080.imprisoned_self
			}
			triggered_desc = {
				trigger = {
					scope:host = {
						is_alive = yes
						is_imprisoned = yes
					}
				}
				desc = excavation.0080.imprisoned
			}
		}
	}
	left_portrait = {
		character = root
		animation = worry
	}
	right_portrait = {
		character = scope:host
		animation = prisonhouse
	}
	lower_left_portrait = scope:host.imprisoner
	theme = hunt_activity
	cooldown = { weeks = 1 }

	immediate = {
		excavation_invalidation_event_effect = yes
		show_as_tooltip = {
			scope:host.imprisoner = {
				imprison = {
					target = scope:host
					type = house_arrest
				}
			}
		}
	}

	option = {
		name = excavation.0080.a
		custom_tooltip = excavation_ends_tt
	}
}

# Assassination Attempt
excavation.0083 = {
	type = character_event
	title = excavation.0082.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:invalidated_culprit }
				desc = excavation.0080.assassination_culprit
			}
			desc = excavation.0080.assassination
		}
	}
	left_portrait = {
		character = root
		animation = worry
		trigger = { is_in_list = attendees }
	}
	right_portrait = {
		character = scope:host
		trigger = {
			NOR = {
				this = root
				this = scope:invalidated_culprit
			}
		}
		animation = stress
	}
	lower_right_portrait = {
		character = scope:invalidated_flavor
		trigger = {
			exists = scope:invalidated_flavor
			NOR = {
				scope:invalidated_flavor = root
				scope:invalidated_flavor = scope:host
			}
		}
	}
	lower_center_portrait = {
		character = scope:invalidated_culprit
		trigger = {
			exists = scope:invalidated_culprit
			scope:invalidated_culprit != root
		}
	}
	theme = hunt_activity
	cooldown = { weeks = 1 }
	
	trigger = {
		# No need for invalidation ping for botched scheme targets
		NOR = {
			scope:invalidated_flavor ?= root
			scope:invalidated_culprit ?= root
		}
	}

	immediate = {
		if = {
			limit = {
				this != scope:host
			}
			excavation_invalidation_event_effect = yes
		}
		show_as_tooltip = {
			if = {
				limit = {
					exists = scope:invalidated_culprit
				}
				scope:invalidated_flavor = {
					add_opinion = {
						target = scope:invalidated_culprit
						modifier = attempted_murder_me_crime
					}
				}
			}
		}
	}

	option = {
		name = excavation.0082.a
		ai_chance = {
			base = 100
		}
	}

	option = {
		name = excavation.1013.a
		trigger = { this = scope:host }
		scope:activity = {
			set_variable = {
				name = excavation_invalidated
				value = flag:assassination_attempt
			}
			set_variable = {
				name = excavation_invalidated_flavor
				value = scope:invalidated_flavor
			}
			set_variable = {
				name = excavation_invalidated_culprit
				value = scope:invalidated_culprit
			}
		}
		excavation_invalidation_event_effect = yes
		ai_chance = {
			base = 25
		}
	}
}

# Abduction Attempt
excavation.0084 = {
	type = character_event
	title = excavation.0082.t
	desc = {
		desc = excavation.0080.abduction_attempt
		triggered_desc = {
			trigger = { exists = scope:invalidated_culprit }
			desc = excavation.0080.assassination_culprit
		}
	}
	left_portrait = {
		character = root
		animation = worry
		trigger = { is_in_list = attendees }
	}
	right_portrait = {
		character = scope:host
		trigger = {
			NOR = {
				this = root
				this = scope:invalidated_culprit
			}
		}
		animation = stress
	}
	lower_right_portrait = {
		character = scope:invalidated_flavor
		trigger = {
			exists = scope:invalidated_flavor
			NOR = {
				scope:invalidated_flavor = root
				scope:invalidated_flavor = scope:host
			}
		}
	}
	lower_center_portrait = {
		character = scope:invalidated_culprit
		trigger = {
			exists = scope:invalidated_culprit
			scope:invalidated_culprit != root
		}
	}
	theme = hunt_activity
	cooldown = { weeks = 1 }
	
	trigger = {
		# No need for invalidation ping for botched scheme targets
		NOR = {
			scope:invalidated_flavor ?= this
			scope:invalidated_culprit ?= this
		}
	}

	immediate = {
		if = {
			limit = {
				this != scope:host
			}
			excavation_invalidation_event_effect = yes
		}
		show_as_tooltip = {
			scope:invalidated_flavor = {
				add_opinion = {
					target = scope:invalidated_culprit
					modifier = attempted_abduct_me_crime
				}
			}
		}
	}

	option = {
		name = excavation.0082.a
		ai_chance = {
			base = 100
		}
	}

	option = {
		name = excavation.1013.a
		trigger = { this = scope:host }
		scope:activity = {
			set_variable = {
				name = excavation_invalidated
				value = flag:abduction_attempt
			}
			set_variable = {
				name = excavation_invalidated_flavor
				value = scope:invalidated_flavor
			}
			set_variable = {
				name = excavation_invalidated_culprit
				value = scope:invalidated_culprit
			}
		}
		excavation_invalidation_event_effect = yes
		ai_chance = {
			base = 25
		}
	}
}

# Abduction
excavation.0085 = {
	type = character_event
	title = excavation.0082.t
	desc = {
		desc = excavation.0080.abduction
		triggered_desc = {
			trigger = { exists = scope:invalidated_culprit }
			desc = excavation.0080.abduction_culprit
		}
	}
	left_portrait = {
		character = root
		animation = worry
		trigger = { is_in_list = attendees }
	}
	right_portrait = {
		character = scope:host
		trigger = {
			NOR = {
				this = root
				this = scope:invalidated_culprit
			}
		}
		animation = stress
	}
	lower_right_portrait = {
		character = scope:invalidated_flavor
		trigger = {
			exists = scope:invalidated_flavor
			NOR = {
				scope:invalidated_flavor = root
				scope:invalidated_flavor = scope:host
			}
		}
	}
	lower_center_portrait = {
		character = scope:invalidated_culprit
		trigger = {
			exists = scope:invalidated_culprit
			scope:invalidated_culprit != root
		}
	}
	theme = hunt_activity
	cooldown = { weeks = 1 }
	
	trigger = {
		# No need for invalidation ping for botched scheme targets
		NOR = {
			scope:abduct_target ?= this
			scope:invalidated_culprit ?= this
		}
	}

	immediate = {
		if = {
			limit = {
				this != scope:host
			}
			excavation_invalidation_event_effect = yes
		}
		show_as_tooltip = {
			hard_imprison_character_effect = {
				TARGET = scope:invalidated_flavor
				IMPRISONER = scope:invalidated_culprit
			}
			scope:invalidated_flavor = {
				add_opinion = {
					target = scope:invalidated_culprit
					modifier = abducted_me_opinion
				}
			}
		}
	}

	option = {
		name = excavation.0082.a
		ai_chance = {
			base = 100
		}
	}

	option = {
		name = excavation.1013.a
		trigger = { this = scope:host }
		scope:activity = {
			set_variable = {
				name = excavation_invalidated
				value = flag:abduction
			}
			set_variable = {
				name = excavation_invalidated_flavor
				value = scope:invalidated_flavor
			}
			set_variable = {
				name = excavation_invalidated_culprit
				value = scope:invalidated_culprit
			}
		}
		excavation_invalidation_event_effect = yes
		ai_chance = {
			base = 25
		}
	}
}

# Wound
excavation.0086 = {
	type = character_event
	title = excavation.0080.t
	desc = {
		first_valid = { # Summary
			# Wounded Guest
			triggered_desc = {
				trigger = { scope:invalidated_flavor ?= root }
				desc = excavation.0080.wounded_self
			}
			desc = excavation.0080.wounded
		}
	}
	left_portrait = {
		character = root
		animation = worry
		trigger = { is_in_list = attendees }
	}
	right_portrait = {
		character = scope:host
		trigger = {
			this != root
		}
		triggered_animation = {
			trigger = { is_alive = no }
			animation = loss_1
		}
		animation = stress
	}
	lower_right_portrait = {
		character = scope:invalidated_flavor
		trigger = {
			exists = scope:invalidated_flavor
			NOR = {
				scope:invalidated_flavor = root
				scope:invalidated_flavor = scope:host
			}
		}
	}
	theme = hunt_activity
	cooldown = { weeks = 1 }

	immediate = {
		excavation_invalidation_event_effect = yes
	}

	option = {
		name = excavation.0080.a
		custom_tooltip = excavation_ends_tt
	}
}

################
#	Standard start
#	by Joe Parkin
################

scripted_effect excavation_activity_random_attending_effect = {
	scope:activity = {
		if = {
			limit = {
				any_attending_character = {
					this != root
				}
			}
			random_attending_character = {
				limit = {
					OR = {
						has_court_position = antiquarian_court_position
						has_court_position = huntperson_camp_officer
						has_trait = lifestyle_hunter
					}
					OR = {
						has_trait = brave
						NOT = { has_trait = craven }
					}
					this != root
				}
				alternative_limit = {
					OR = {
						has_court_position = antiquarian_court_position
						has_court_position = huntperson_camp_officer
						has_trait = lifestyle_hunter
					}
					this != root
				}
				alternative_limit = {
					this != root
				}
				save_scope_as = excavation_participant
			}
		}
	}
}
excavation.0500 = {
	type = activity_event
	title = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:activity.activity_location = { has_building_or_higher = zone_rouge_01 }
				}
				desc = excavation.0500.t.tell
			}
			triggered_desc = {
				trigger = {
					scope:activity.activity_location = { terrain = tells }
				}
				desc = excavation.0500.t.tell
			}
		}
	}
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:excavation_participant
					scope:excavation_participant = {
						has_court_position = antiquarian_court_position
					}
				}
				desc = excavation_antiquarian
			}
			triggered_desc = {
				trigger = { exists = scope:excavation_participant }
				desc = excavation_opening_excavation_leader
			}
			desc = excavation_opening
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:activity.activity_location = { terrain = tells }
				}
				desc =  excavation_opening_tells
			}
			triggered_desc = {
				trigger = {
					scope:activity.activity_location = { has_building_or_higher = zone_rouge_01 }
				}
				desc = excavation_opening_excavationing_grounds
			}
			desc = excavation_opening_rural
		}
		first_valid = {
#			triggered_desc = {
#				trigger = {
#					scope:activity = {
#						activity_location.county = { has_building_or_higher = zone_rouge_01 }
#						has_activity_option = { category = excavation_option_attendants option = excavation_attendants_few }
#					}
#				}
#				desc = excavation_opening_entourage_few_dangerous
#			}
#			triggered_desc = {
#				trigger = {
#					scope:activity = {
#						activity_location.county = { has_building_or_higher = zone_rouge_01}
#						has_activity_option = { category = excavation_option_attendants option = excavation_attendants_normal }
#					}
#				}
#				desc = excavation_opening_entourage_normal_dangerous
#			}
#			triggered_desc = {
#				trigger = {
#					scope:activity = {
#						activity_location.county = { has_building_or_higher = zone_rouge_01}
#						has_activity_option = { category = excavation_option_attendants option = excavation_attendants_many }
#					}
#				}
#				desc = excavation_opening_entourage_many_dangerous
#			}
			triggered_desc = {
				trigger = {
					scope:activity = {
						has_activity_option = { category = excavation_option_attendants option = excavation_attendants_few }
					}
				}
				desc = excavation_opening_entourage_few
			}
			triggered_desc = {
				trigger = {
					scope:activity = {
						has_activity_option = { category = excavation_option_attendants option = excavation_attendants_normal }
					}
				}
				desc = excavation_opening_entourage_normal
			}
			triggered_desc = {
				trigger = {
					scope:activity = {
						has_activity_option = { category = excavation_option_attendants option = excavation_attendants_many }
					}
				}
				desc = excavation_opening_entourage_many
			}
		}
		first_valid = {
			triggered_desc = {
				trigger = { scope:activity.activity_location = { has_building_or_higher = zone_rouge_01 } }
				desc = excavation.0500.rouge
			}	
			triggered_desc = {
				trigger = { scope:activity.activity_location = { terrain = tells } }
				desc =  excavation.0500.tells
			}
			desc = excavation_opening_sighting			
		}
	}
	theme = hunt_activity_camp
	left_portrait = {
		character = scope:host
		animation = thinking
	}
	right_portrait = {
		character = scope:excavation_participant
		animation = storyteller
	}

	immediate = {
		excavation_activity_random_attending_effect = yes
	}

	trigger = {
		scope:activity = {
			has_activity_option = { category = special_type option = excavation_type_standard }
		}
	}

	option = { # We'll chase it!
		name = excavation.0500.a
		custom_tooltip = excavation_seek_current_tt
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_boldness = -0.5
				ai_energy = 1
			}
		}
	}
	after = {
		if = {
			limit = { this = scope:host }
			scope:activity = {
				every_attending_character = {
					limit = {
						this != scope:host
					}
					trigger_event = excavation.0500
				}
				set_variable = excavation_started
				add_activity_log_entry = {
					key = excavation_quarry_selected_log
					score = 25
					tags = { quarry }
					character = scope:host
				}
				excavation_activity_success_change_effect = { CHANGE = increase_medium }
				set_variable = {
					name = excavation_success_chance
					value = excavation_success_chance_value
				}
			}
		}
	}
}
###############
#
#
# Conclusion
#
###############

excavation.1003 = {
	type = activity_event
	title = hunt.1001.t
	desc = {
		desc = hunt.1003.desc
	}
	theme = hunt_activity
	left_portrait = {
		character = scope:host
		animation = throne_room_two_handed_passive_1
	}
	right_portrait = {
		trigger = { exists = scope:excavation_participant }
		character = scope:excavation_participant
		animation = admiration
	}
	lower_right_portrait = {
		trigger = {
			exists = scope:intentee
			NOT = { scope:excavation_participant ?= scope:intentee }
		}
		character = scope:intentee
	}
	cooldown = { weeks = 1 }

	trigger = {	
		always = yes
	}

	weight_multiplier = {
		base = 1
		modifier = { add = involved_activity.var:excavation_success_chance }
	}

	immediate = {
		scope:activity = {
			set_variable = {
				name = excavation_success
				value = flag:yes
			}
		}
		scope:activity = {
			random_attending_character = {
				limit = {
					this != scope:host
				}
				save_scope_as = hunt_participant
			}
		}
		save_scope_as = excavation_ending
		hunt_outcome_scope_effect = yes
	}

	option = { #Take the shot
		name = {
			trigger = {
			}
			text = hunt.1003.a
		}
		flavor = hunt.1003.a.flavor
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = 0.5
				ai_energy = 0.5
				ai_greed = 0.5
			}
		}
	}
}

#Corner escape
excavation.1004 = {
	type = activity_event
	title = excavation.1001.t
	desc = {
		first_valid = {
			desc = excavation.1004.desc
			triggered_desc = {
				trigger = { exists = scope:wounded_guest }
				desc = hunt.1004.wounded
			}
			triggered_desc = {
				trigger = { exists = scope:wounded_host }
				desc = excavation.1004.wounded_host
			}
		}
	}
	theme = hunt_activity
	left_portrait = {
		character = scope:host
		animation = disapproval
	}
	right_portrait = {
		character = scope:excavation_participant
		animation = stress
	}
	center_portrait = {
		character = root
		animation = worry
		trigger = {
			NOR = {
				scope:host ?= this
				scope:excavation_participant ?= this
			}
		}
	}
	cooldown = { weeks = 1 }

	trigger = {
		always = yes
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = {
				value = 100
				subtract = involved_activity.var:excavation_success_chance
			}
		}
	}

	immediate = {
		if = {
			limit = { this = scope:host }
			save_scope_as = excavation_ending
			scope:activity = {
				set_variable = {
					name = excavation_success
					value = flag:no
				}
			}
		}
		custom_tooltip = hunt_fails_tt
	}

	option = { #Drat!
		name = hunt.1004.a
		ai_chance = {
			base = 25
		}
	}
}




####Generico 
#######################
#	A excavation guest is about to share a secret about someone when they are interrupted
#	by Petter Vilberg
#######################

scripted_trigger excavation_4002_secret_knower_trigger = {
	this != root
	opinion = {
		target = root
		value > 0
	}
	save_temporary_scope_as = secret_knower_temp
	any_known_secret = {
		NOR = {
			secret_owner ?= scope:secret_knower_temp
			is_known_by = root
			secret_owner ?= root
		}
		secret_owner ?= {
			OR = {
				is_of_major_interest_trigger = { CHARACTER = root }
				is_of_minor_interest_trigger = { CHARACTER = root }
			}
		}
	}
}

excavation.4002 = {
	type = activity_event
	title = excavation.4002.t
	desc = excavation.4002.desc
	theme = hunt_activity
	left_portrait = {
		character = root
		animation = eavesdrop
	}
	right_portrait = {
		character = scope:secret_sharer
		animation = paranoia
	}
	lower_right_portrait = scope:secret_owner
	cooldown = { years = 2 }
	
	trigger = {
		scope:activity = {
			any_attending_character = { excavation_4002_secret_knower_trigger = yes }
		}
	}

	immediate = {
		scope:activity = {
			random_attending_character = {
				limit = { excavation_4002_secret_knower_trigger = yes }
				save_scope_as = secret_sharer
				random_known_secret = {
					limit = { #Prefer a secret about someone highly relevant to activity_host
						NOR = {
							secret_owner = scope:secret_sharer
							is_known_by = root
							secret_owner = root
						}
						secret_owner ?= {
							is_of_major_interest_trigger = { CHARACTER = root }
						}
					}
					alternative_limit = { #Fallback to minor interest characters
						NOR = {
							secret_owner = scope:secret_sharer
							is_known_by = root
							secret_target = root
						}
						secret_owner ?= {
							is_of_minor_interest_trigger = { CHARACTER = root }
						}
					}
					save_scope_as = secret_to_share
					secret_owner ?= {
						save_scope_as = secret_owner
					}
				}
			}
		}
	}

	option = { #Truly interesting, but get that animal!
		name = excavation.4002.a
		flavor = excavation.4002.a.flavor
		scope:activity = {
			add_activity_log_entry = {
				key = excavation_secret_animal_log
				score = 25
				tags = { random neutral social }
				character = root
				target = scope:secret_owner

				# Effect
				root = {
					add_prestige = minor_prestige_gain
					excavation_activity_success_change_effect = { CHANGE = increase_medium }
					stress_impact = {
						paranoid = minor_stress_impact_gain
						trusting = minor_stress_impact_loss
						diligent = minor_stress_impact_loss
						arrogant = minor_stress_impact_loss
						impatient = minor_stress_impact_loss
					}
				}
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = 0.5
				ai_compassion = -0.25
				ai_honor = 0.25
			}
		}
	}

	option = { #No wait, tell me!
		name = excavation.4002.b
		flavor = excavation.4002.b.tt
		scope:activity = {
			add_activity_log_entry = {
				key = excavation_secret_learned_log
				score = 25
				tags = { random neutral social }
				character = root
				target = scope:secret_owner

				# Effect
				root = {
					custom_tooltip = excavation.4002.b.reveal
					excavation_activity_success_change_effect = { CHANGE = decrease_minor }
					add_prestige = minor_prestige_loss
					hidden_effect = {
						scope:secret_to_share = { reveal_to = root }
					}
					stress_impact = {
						arrogant = minor_stress_impact_gain
						impatient = minor_stress_impact_gain
						trusting = minor_stress_impact_gain
						diligent = minor_stress_impact_gain
						paranoid = minor_stress_impact_loss
					}
				}
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 0.5
				ai_greed = 0.25
			}
		}
	}
}

#######################
#	Run into looters
#	by Petter Vilberg
#######################

excavation.4003 = {
	type = activity_event
	title = excavation.4003.t
	desc = excavation.4003.desc
	theme = hunt_activity
	left_portrait = {
		character = root
		animation = war_over_win
	}
	right_portrait = {
		character = scope:looter
		animation = beg
		outfit_tags = { travel_cloak }
	}
	cooldown = { years = 10 }

	trigger = {
		OR = {
			involved_activity.activity_host = this
			has_court_position = antiquarian_court_position
		}
		scope:activity.activity_location.county = {
			NOR = {
				has_county_modifier = excavation_punished_locals_modifier
			}
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			factor = 0.5
			scope:activity.activity_location = {
				NOR = {
					terrain = forest
					terrain = taiga
					terrain = jungle
				}
			}
		}
	}

	immediate = {
		create_character = {
			template = hunter_template
			faith = scope:activity.activity_location.faith
			culture = scope:activity.activity_location.culture
			location = scope:activity.activity_location
			save_scope_as = looter
		}
		scope:activity = {
			activity_location = {
				county = {
					save_scope_as = county
					holder = { save_scope_as = land_owner }
				}
			}
		}
	}

	option = {
		name = excavation.4003.adventurer
		trigger = { has_government = landless_adventurer_government }
		add_courtier = scope:looter
		excavation_activity_success_change_effect = { CHANGE = increase_minor }
		domicile = {
			change_provisions = microscopic_provisions_gain
		}
		stress_impact = {
			paranoid = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
		}
	}

	option = { #Punish them
		name = excavation.4003.a
		trigger = { scope:land_owner.top_liege = root.top_liege }
		scope:activity = {
			add_activity_log_entry = {
				key = excavation_looters_punished_log
				score = 25
				tags = { random bad }
				character = root
				target = scope:looter

				# Effect
				scope:activity.activity_location.county = {
					add_county_modifier = {
						modifier = excavation_punished_locals_modifier
						years = 10
					}
				}
				root = {
					stress_impact = {
						forgiving = minor_stress_impact_gain
						compassionate = minor_stress_impact_gain
						arbitrary = minor_stress_impact_loss
						vengeful = minor_stress_impact_loss
					}
				}
			}
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_compassion = -0.5
				ai_boldness = 1
			}
		}
	}

#	option = { #I will let you go if you teach me a thing or two
#		name = excavation.4003.b
#		trigger = {
#			antiquarian_lifestyle_track_less_trigger = { TRACK = archaeologist LESS_THAN = 100 }
#		}
#		scope:activity = {
#			add_activity_log_entry = {
#				key = excavation_looters_lesson_log
#				score = 25
#				tags = { random bad }
#				character = root
#				target = scope:poacher
#
#				# Effect
#				root = {
#					excavation_activity_success_change_effect = { CHANGE = decrease_minor }
#					add_character_modifier = {
#						modifier = excavation_looters_training_modifier
#						years = 10
#					}
#					hidden_effect = {
#						antiquarian_progress_point_gain_effect = { CHANGE = 1 RANDOM_CHANGE = 1 } #Gives points towards ranking up the excavationer Lifestyle
#					}
#					stress_impact = {
#						just = minor_stress_impact_loss
#						vengeful = minor_stress_impact_gain
#						forgiving = minor_stress_impact_loss
#						ambitious = minor_stress_impact_loss
#					}
#				}
#			}
#		}
#		ai_chance = {
#			base = 10
#			ai_value_modifier = {
#				ai_energy = 1
#				ai_honor = -0.5
#			}
#		}
#	}
	
	option = { #Claim the animals and a legal right to their lives
		name = excavation.4003.c
		scope:activity = {
			add_activity_log_entry = {
				key = excavation_looters_legal_log
				score = 25
				tags = { random bad }
				character = root
				target = scope:looter
				
				# Effect
				root = {
					if = {
						limit = {
							has_government = landless_adventurer_government
						}
						domicile = {
							change_provisions = microscopic_provisions_gain
						}
						add_treasury_or_gold = minor_treasury_or_gold_value
						excavation_activity_success_change_effect = { CHANGE = increase_minor }
					}
					else = {
						duel = {
							skill = stewardship
							value = average_skill_rating
							8 = {
								compare_modifier = {
									value = scope:duel_value
									multiplier = 0.25
								}
								desc = excavation.4003.c.tt_success
								send_interface_toast = {
									title = excavation.4003.c.tt_success
									add_treasury_or_gold = minor_treasury_or_gold_value
									add_prestige = medium_prestige_gain
									excavation_activity_success_change_effect = { CHANGE = increase_minor }
								}
							}
							12 = {
								compare_modifier = {
									value = scope:duel_value
									multiplier = -0.25
									min = -9
								}
								desc = excavation.4003.c.tt_failure
								send_interface_toast = {
									title = excavation.4003.c.tt_failure
									add_prestige = minor_prestige_loss
									scope:county = {
										add_county_modifier = {
											modifier = excavation_upset_excavationing_county_modifier
											years = 10
										}
									}
								}
								excavation_activity_success_change_effect = { CHANGE = decrease_major }
							}
						}
					}
					stress_impact = {
						compassionate = medium_stress_impact_gain
						honest = medium_stress_impact_gain
						vengeful = minor_stress_impact_loss
						arrogant = minor_stress_impact_loss
						ambitious = minor_stress_impact_loss
						arbitrary = minor_stress_impact_loss
					}
				}
			}
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = 1
				ai_boldness = -0.5
			}
		}
	}

	option = { #Let them off, as it's not your land
		name = {
			text = excavation.4003.d
			trigger = {
				NOR = {
					scope:land_owner.top_liege = root.top_liege
					has_relation_rival = scope:land_owner
				}
			}
		}
		name = {
			text = excavation.4003.d.rival
			trigger = { has_relation_rival = scope:land_owner }
		}
		name = {
			text = excavation.4003.d.vassal
			trigger = {
				root != root.top_liege
				scope:land_owner.top_liege = root.top_liege
			}
		}
		name = {
			text = excavation.4003.d.own
			trigger = { scope:land_owner.top_liege = root }
		}
		scope:activity = {
			add_activity_log_entry = {
				key = excavation_looters_pardon_log
				score = 25
				tags = { random bad }
				character = root
				target = scope:looter

				#Effect
				root = {
					if = {
						limit = {
							this != scope:land_owner
						}
						reverse_add_opinion = {
							target = scope:land_owner
							modifier = excavation_released_looters_opinion
							opinion = -10
						}
					}
					if = {
						limit = { has_relation_rival = scope:land_owner }
						stress_impact = {
							base = medium_stress_impact_loss
							just = minor_stress_impact_gain
							vengeful = minor_stress_impact_loss
						}
					}
					else_if = {
						limit = { scope:land_owner.top_liege = root.top_liege }
						stress_impact = {
							just = minor_stress_impact_gain
							vengeful = minor_stress_impact_loss
							callous = minor_stress_impact_loss
						}
					}
					else = {
						stress_impact = {
							just = minor_stress_impact_gain
							sadistic = minor_stress_impact_loss
						}
					}
				}
			}
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_compassion = 0.5
				ai_honor = -0.5
				ai_boldness = -0.5
			}
		}
	}

	after = {
		scope:looter = {
			if = {
				limit = {
					NOR = {
						root = { is_ai = no }
						is_courtier = yes
					}
				}
				silent_disappearance_effect = yes
			}
		}
	}
}