﻿HRT_nibelungen_activity_search = {
	is_shown = {
		is_ai = no
		has_character_flag = HRT_nibelungen_searching
		NOT = {
			title:c_aachen = { has_variable = HRT_nibelungen_helmet_found }
		}
	}

	can_start = {
		custom_description = {
			text = HRT_nibelungen_activity_search_month_requirement
			current_month >= 8
			current_month <= 10
		}
	}

	can_start_showing_failures_only = {
		is_available_adult = yes
	}

	is_valid = {
		NOT = {
			has_variable = activity_invalidated
		}
		scope:host = {
			is_landed = yes
			NOT = { is_incapable = yes }
		}
	}

	on_invalidated = {
		# Host becomes unlanded
		if = {
			limit = {
				scope:host = { is_landed = no }
			}
			scope:activity = {
				activity_type = { save_scope_as = activity_type }
			}
			every_attending_character = {
				trigger_event = activity_system.0320
			}
		}
		if = {
			limit = {
				scope:host = { is_incapable = yes }
			}
			scope:activity = {
				activity_type = { save_scope_as = activity_type }
			}
			scope:host = {
				trigger_event = activity_system.0330
			}
			every_attending_character = {
				limit = { NOT = { this = scope:host } }
				trigger_event = activity_system.0331
			}
		}
	}

	on_host_death = {
		scope:activity = {
			set_variable = {
				name = activity_invalidated
			}
		}
	}

	province_filter = top_realm
	wait_time_before_start = { days = 12 }

	###################
	# OPTIONS
	###################

	###################
	# PARAMETERS
	###################

	#is_single_location = yes

	###################
	# PHASES
	###################

	phases = {
		HRT_nibelungen_search_phase = {
			is_predefined = yes
			
			on_phase_active = {
				if = {
					limit = {
						this = scope:host
					}
					trigger_event = HRT_nibelungen.0011
				}		
			}
			on_end = {
				# Run conclusion stuff here
				# if = {
				# 	limit = { this = scope:host }
				# 	scope:activity = { progress_activity_phase_after = { weeks = 2 } }
				# }
			}
		}
	}

	max_guest_arrival_delay_time = { days = 12 }
	#allow_zero_guest_invites = yes

	ai_will_do = {
		value = 50
	}

	ai_check_interval = 128

	ai_will_select_province = {
		value = 10
	}
	
	is_location_valid = {
		trigger_if = {
			limit = {
				exists = barony
			}
			custom_description = {
				text = HRT_nibelungen_activity_barony_searched
				barony = { NOT = { has_variable = HRT_nibelungen_searched } }
			}
			custom_description = {
				text = HRT_nibelungen_activity_rhine_barony
				OR = {
					barony = title:b_baden
					barony = title:b_weissenburg
					barony = title:b_hockenheim
					barony = title:b_speyer
					barony = title:b_heidelberg
					barony = title:b_weinheim
					barony = title:b_besensheim
					barony = title:b_russelsheim
					barony = title:b_kreusnach
					barony = title:b_mainz
					barony = title:b_limburg
					barony = title:b_wiesbaden
					barony = title:b_katzenelnbogen
					barony = title:b_boppard
					barony = title:b_koblenz
					barony = title:b_worms
				}
			}
		}
	}

	max_province_icons = 1
	
	cost = {
		gold = {
			add = {
				add = {
					value = hunt_activity_base_cost #Base level
					desc = hunt_base_cost
				}
				add = {
					value = hunt_activity_base_cost
					multiply = activity_cost_scale_by_era
					subtract = hunt_activity_base_cost
					desc = activity_cost_scale_by_era_desc
				}
				if = {
					limit = {
						dynasty ?= {
							has_dynasty_perk = law_legacy_1
						}
					}
					subtract = {
						value = 0
						add = {
							value = hunt_activity_base_cost
							add = {
								value = hunt_activity_base_cost
								multiply = activity_cost_scale_by_era
								subtract = hunt_activity_base_cost
							}
						}
						multiply = law_legacy_cost_reduction_mult
						desc = law_legacy_1_name
					}
				}
			}
		}
	}

	ui_predicted_cost = {
		# All costs are balanced on County/Early Era starting point
		gold = {
			add = { # Base cost, scaled by era
				value = hunt_activity_base_cost
				multiply = activity_cost_scale_by_era
			}
			if = {
				limit = {
					dynasty ?= {
						has_dynasty_perk = law_legacy_1
					}
				}
				subtract = {
					value = hunt_activity_base_cost
					multiply = law_legacy_cost_reduction_mult
				}
			}
			
			# Make it a multiple of 5 (rounded up)
			divide = 5
			ceiling = yes
			multiply = 5
		}
	}

	cooldown = { days = 3650 }
	
	###################
	# ACTIVITY-SPECIFIC PULSES
	###################
	
	pulse_actions = { }

	on_start = { }

	on_enter_passive_state = { }

	###################
	# GUEST HANDLING
	###################

	max_guests = 30

	guest_invite_rules = {
		rules = {
			# Relations.
			#2 = activity_invite_rule_lovers
			#2 = activity_invite_rule_rivals_if_appropriate

			# Family.
			#3 = activity_invite_rule_extended_family
			#3 = activity_invite_spouses
			3 = activity_invite_rule_close_family

			# MP 
			6 = activity_invite_mp
		}
		defaults = {
			1 = activity_invite_rule_friends
			1 = activity_invite_rule_knights
			2 = activity_invite_rule_courtiers
			3 = activity_invite_rule_guests
			#4 = activity_invite_rule_vassals			
		}
	}

	can_be_activity_guest = {
		can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:host }
		faith.religion = scope:host.faith.religion
		is_adult = yes
		is_available = yes
		in_diplomatic_range = scope:host
	}

	host_intents = {
		intents = { HRT_nibelungen_find_treasure_intent }
		default = HRT_nibelungen_find_treasure_intent
	}

	guest_intents = {
		intents = { HRT_nibelungen_find_treasure_intent }
		default = HRT_nibelungen_find_treasure_intent
	}

	guest_join_chance = {
		base = 10
		base_activity_modifier = yes

		# Scripted Modifiers
		activity_guest_shared_ai_accept_modifier = yes
	}
	
	on_complete = {
		if = {
			limit = { this = scope:host }
			scope:host = {
				HRT_nibelungen_search_completed_log_entry_effect = yes
			}
		}
		scope:activity.activity_location.barony = {
			set_variable = {
				name = HRT_nibelungen_searched
				years = 50
			}
		}
		scope:host = {
			if = {
				limit = { has_character_flag = HRT_nibelungen_found_price }
				remove_character_flag = HRT_nibelungen_found_price
			}
		}
	}

	###################
	# GRAPHICS
	###################

	#map_entity = "building_western_hunt_01_entity"

	# Travel
	background = { # Bridge
		trigger = {
			NOT = { scope:host.location = scope:activity.activity_location }
			scope:host.location = {
				is_riverside_province = yes
				geographical_region = world_europe
				OR = {
					terrain = farmlands
					terrain = plains
					terrain = mountains
					terrain = hills
				}
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/ep2_travel_bridge.dds"
		environment = "environment_travel_bridge"
		ambience = "event:/SFX/Events/Backgrounds/mountains_day"
	}
	
	background = { # Farmland, settled
		trigger = {
			NOT = { scope:host.location = scope:activity.activity_location }
			scope:host.location = {
				terrain = farmlands
				exists = province_owner
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/ep2_travel_farm.dds"
		environment = "environment_travel_farmlands"
		ambience = "event:/SFX/Events/Backgrounds/fields_farms_day"
	}
	background = { # Farmland, unsettled
		trigger = {
			NOT = { scope:host.location = scope:activity.activity_location }
			scope:host.location = {
				terrain = farmlands
				NOT = { exists = province_owner }
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/farms.dds"
		environment = "environment_event_farms"
		ambience = "event:/SFX/Events/Backgrounds/fields_farms_day"
	}

	background = { #Desert, settled
		trigger = {
			NOT = { scope:host.location = scope:activity.activity_location }
			scope:host.location = {
				graphical_wilderness_desert_trigger = yes
				exists = province_owner
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/ep2_travel_desert.dds"
		environment = "environment_travel_desert"
		ambience = "event:/SFX/Events/Backgrounds/desert_day"
	}
	background = { #Desert, unsettled
		trigger = {
			NOT = { scope:host.location = scope:activity.activity_location }
			scope:host.location = {
				graphical_wilderness_desert_trigger = yes
				NOT = { exists = province_owner }
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/desert.dds"
		environment = "environment_event_bp1_desert"
		ambience = "event:/SFX/Events/Backgrounds/desert_day"
	}

	background = { #forest snowy
		trigger = {
			NOT = { scope:host.location = scope:activity.activity_location }
			scope:host.location ?= { hunt_snowy_forest_trigger = yes }
		}
		texture = "gfx/interface/illustrations/event_scenes/ep2_hunt_snowy_forest.dds"
		environment = "environment_hunt_snowy_forest"
		ambience = "event:/SFX/Events/Backgrounds/mountains_day"
	}

	background = { #forest_pine
		trigger = {
			NOT = { scope:host.location = scope:activity.activity_location }
			scope:host.location = {
				graphical_wilderness_forest_pine_trigger = yes
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/forest_pine.dds"
		environment = "environment_event_forest_pine"
		ambience = "event:/SFX/Events/Backgrounds/coniferous_forest_day"
	}

	background = { #forest
		trigger = {
			NOT = { scope:host.location = scope:activity.activity_location }
			scope:host.location = {
				graphical_wilderness_forest_trigger = yes
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/forest.dds"
		environment = "environment_event_forest"
		ambience = "event:/SFX/Events/Backgrounds/deciduous_forest_day"
	}

	background = { #mountains, settled
		trigger = {
			NOT = { scope:host.location = scope:activity.activity_location }
			scope:host.location = {
				graphical_wilderness_mountains_trigger = yes
				exists = province_owner
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/ep2_travel_mountains.dds"
		environment = "environment_travel_mountain_settlement"
		ambience = "event:/SFX/Events/Backgrounds/mountains_day"
	}
	background = { #mountains, unsettled
		trigger = {
			NOT = { scope:host.location = scope:activity.activity_location }
			scope:host.location = {
				graphical_wilderness_mountains_trigger = yes
				NOT = { exists = province_owner }
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/mountains.dds"
		environment = "environment_event_mountains"
		ambience = "event:/SFX/Events/Backgrounds/mountains_day"
	}

	background = { #steppe, settled
		trigger = {
			NOT = { scope:host.location = scope:activity.activity_location }
			scope:host.location = {
				graphical_wilderness_steppe_trigger = yes
				exists = province_owner
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/ep2_travel_steppe.dds"
		environment = "environment_travel_steppe_settlement"
		ambience = "event:/SFX/Events/Backgrounds/steppe_day"
	}
	background = { #steppe, unsettled
		trigger = {
			NOT = { scope:host.location = scope:activity.activity_location }
			scope:host.location = {
				graphical_wilderness_steppe_trigger = yes
				NOT = { exists = province_owner }
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/steppe.dds"
		environment = "environment_event_steppe"
		ambience = "event:/SFX/Events/Backgrounds/steppe_day"
	}

	background = { #drylands (formerly desert)
		trigger = {
			NOT = { scope:host.location = scope:activity.activity_location }
			scope:host.location = {
				graphical_drylands_trigger = yes
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/drylands.dds"
		environment = "environment_event_desert"
		ambience = "event:/SFX/Events/Backgrounds/desert_day"
	}

	background = { #wetlands
		trigger = {
			NOT = { scope:host.location = scope:activity.activity_location }
			scope:host.location = {
				graphical_wilderness_wetlands_trigger = yes
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/bp1_wetlands.dds"
		environment = "environment_event_bp1_wetlands" 
		ambience = "event:/SFX/Events/Backgrounds/deciduous_forest_day"
	}

	background = { #jungle
		trigger = {
			NOT = { scope:host.location = scope:activity.activity_location }
			scope:host.location = {
				graphical_wilderness_jungle_trigger = yes
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/bp1_jungle.dds"
		environment = "environment_event_bp1_jungle"
		ambience = "event:/SFX/Events/Backgrounds/deciduous_forest_day"
	}

	background = { #plains, settled
		trigger = {
			NOT = { scope:host.location = scope:activity.activity_location }
			scope:host.location = {
				graphical_plains_trigger = yes
				exists = province_owner
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/ep2_travel_hills.dds"
		environment = "environment_travel_hills_settlement"
		ambience = "event:/SFX/Events/Backgrounds/fields_farms_day"
	}
	background = { #plains, unsettled
		trigger = {
			NOT = { scope:host.location = scope:activity.activity_location }
			scope:host.location = {
				graphical_plains_trigger = yes
				NOT = { exists = province_owner }
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/bp1_plains.dds"
		environment = "environment_event_bp1_plains"
		ambience = "event:/SFX/Events/Backgrounds/fields_farms_day"
	}

	background = { #hills, settled
		trigger = {
			NOT = { scope:host.location = scope:activity.activity_location }
			scope:host.location = {
				graphical_hills_trigger = yes
				exists = province_owner
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/ep2_travel_hills.dds"
		environment = "environment_travel_hills_settlement"
		ambience = "event:/SFX/Events/Backgrounds/fields_farms_day"
	}
	background = { #hills, unsettled
		trigger = {
			NOT = { scope:host.location = scope:activity.activity_location }
			scope:host.location = {
				graphical_hills_trigger = yes
				NOT = { exists = province_owner }
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/bp1_hills.dds"
		environment = "environment_event_bp1_hills"
		ambience = "event:/SFX/Events/Backgrounds/fields_farms_day"
	}

	background = { #sea
		trigger = {
			NOT = { scope:host.location = scope:activity.activity_location }
			scope:host.location = {
				is_sea_province = yes
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/fp1_ocean.dds"
		environment = "environment_event_fp1_ocean"
		ambience = "event:/DLC/FP1/SFX/Events/event_ocean_longship"
	}

	# End Travel

	background = { # Bridge
		texture = "gfx/interface/illustrations/event_scenes/ep2_travel_bridge.dds"
		environment = "environment_travel_bridge"
		ambience = "event:/SFX/Events/Backgrounds/coniferous_forest_day"
	}


	window_characters = {

		treasure_hunter = {
			camera = camera_event_right
			
			effect = {
				every_attending_character = {
					limit = {
						scope:host.location = scope:activity.activity_location
					}
					add_to_list = characters
				}
			}

			scripted_animation = {
				#triggered_animation = {
				#	trigger = {
				#		scope:character = {
				#			OR = {
				#				has_trait = cynical
				#				has_trait = lazy
				#				has_trait = shy
				#			}
				#		}
				#	}
				#	animation = { boredom eyeroll dismissal worry paranoia }
				#}
				#triggered_animation = {
				#	trigger = {
				#		scope:character = {
				#			has_activity_intent = #HRT_nibelungen_find_treasure_intent
				#		}
				#	}
				#	animation = { hunting_knife_start #hunting_shortbow_rest_arrow_default crossbow marshal }
				#}
				#Fallback
				animation = throne_room_two_handed_passive_1
			}
		}

		treasure_hunter = {
			camera = camera_event_center
			
			effect = {
				every_attending_character = {
					limit = {
						scope:host.location = scope:activity.activity_location
					}
					add_to_list = characters
				}
			}

			scripted_animation = {
				#triggered_animation = {
				#	trigger = {
				#		scope:character = {
				#			OR = {
				#				has_trait = cynical
				#				has_trait = lazy
				#				has_trait = shy
				#			}
				#		}
				#	}
				#	animation = { boredom eyeroll dismissal worry paranoia }
				#}
				#triggered_animation = {
				#	trigger = {
				#		scope:character = {
				#			has_activity_intent = #HRT_nibelungen_find_treasure_intent
				#		}
				#	}
				#	animation = { hunting_knife_start #hunting_shortbow_rest_arrow_default crossbow marshal }
				#}
				#Fallback
				animation = hunting_horn
			}
		}
		
		host = {
			camera = camera_event_center
			
			effect = {
				if = {
					limit = {
						scope:host.location = scope:activity.activity_location
					}
					scope:host = {
						add_to_list = characters
					}
				}
			}

			scripted_animation = {
				animation = lantern
			}
		}
		
		travel_host = {
			camera = camera_activity_horse
			
			effect = {
				if = {
					limit = {
						NOT = {
							scope:host.location = scope:activity.activity_location
						}
					}
					scope:host = {
						add_to_list = characters
					}
				}
			}

			scripted_animation = {
				animation = jockey_walk
			}
		}

		treasure_hunter = {
			camera = camera_event_center
			
			effect = {
				every_attending_character = {
					limit = {
						scope:host.location = scope:activity.activity_location
					}
					add_to_list = characters
				}
			}

			scripted_animation = {
				#triggered_animation = {
				#	trigger = {
				#		scope:character = {
				#			OR = {
				#				has_trait = cynical
				#				has_trait = lazy
				#				has_trait = shy
				#			}
				#		}
				#	}
				#	animation = { boredom eyeroll dismissal worry paranoia }
				#}
				#triggered_animation = {
				#	trigger = {
				#		scope:character = {
				#			has_activity_intent = #HRT_nibelungen_find_treasure_intent
				#		}
				#	}
				#	animation = { hunting_knife_start #hunting_shortbow_rest_arrow_default crossbow marshal }
				#}
				#Fallback
				animation = throne_room_two_handed_passive_1
			}
		}

		treasure_hunter = {
			camera = camera_event_left
			
			effect = {
				every_attending_character = {
					limit = {
						scope:host.location = scope:activity.activity_location
					}
					add_to_list = characters
				}
			}

			scripted_animation = {
				#triggered_animation = {
				#	trigger = {
				#		scope:character = {
				#			OR = {
				#				has_trait = cynical
				#				has_trait = lazy
				#				has_trait = shy
				#			}
				#		}
				#	}
				#	animation = { boredom eyeroll dismissal worry paranoia }
				#}
				#triggered_animation = {
				#	trigger = {
				#		scope:character = {
				#			has_activity_intent = #HRT_nibelungen_find_treasure_intent
				#		}
				#	}
				#	animation = { hunting_knife_start #hunting_shortbow_rest_arrow_default crossbow marshal }
				#}
				#Fallback
				animation = crossbow
			}
		}
	}
}
