﻿
namespace = hunt_mystical_animal


#Effect to be used in the immediate of every event
scripted_effect hunt_mystical_animal_immediate_effect = {
	save_temporary_scope_value_as = {
		name = encounter
		value = flag:$ENCOUNTER$
	}
	scope:story = {
		set_variable = {
			name = had_event_hunt_mystical_animal_$EVENT_NUMBER$
			value = yes
		}
		var:legendary_county = { save_scope_as = legendary_county }
		if = { #You had yet another encounter with the animal itself
			limit = { scope:encounter = flag:yes }
			if = {
				limit = { exists = var:encounters }
				change_variable = {
					name = encounters
					add = 1
				}
			}
			else = {
				set_variable = {
					name = encounters
					value = 1
				}
			}
		}
	}
	set_variable = {
		name = animal_type
		value = scope:story.var:animal_type
	}
}

#You dream about the animal
#by Linnéa Thimrén
hunt_mystical_animal.1001 = {
	type = character_event
	title = hunt_mystical_animal.1001.t
	desc = hunt_mystical_animal.1001.desc
	theme = hunting
	override_background = { reference = bedchamber }
	left_portrait = {
		character = root
		animation = stress
		outfit_tags = { nightgown }
	}

	trigger = {
		scope:story = {
			NOT = { exists = var:had_event_hunt_mystical_animal_1001 }
		}
	}

	immediate = {
		hunt_mystical_animal_immediate_effect = {
			EVENT_NUMBER = 1001
			ENCOUNTER = yes
		}
	}

	option = {
		name = hunt_mystical_animal.1001.a
		add_character_modifier = {
			modifier = focused_on_mystical_animal_modifier
			years = 10
		}
	}
}

#You see the animal
#by Linnéa Thimrén
hunt_mystical_animal.1002 = {
	type = character_event
	title = hunt_mystical_animal.1001.t
	desc = hunt_mystical_animal.1002.desc
	theme = hunt_activity
	override_background = { reference = ep2_hunt_foggy_forest }
	left_portrait = {
		character = root
		animation = stress
	}

	trigger = {		
		any_owned_story = {
			type = story_cycle_hunt_mystical_animal
			NOT = { exists = var:had_event_hunt_mystical_animal_1002 }
			save_temporary_scope_as = story
		}
		location.county = scope:story.var:legendary_county
		NOT = { exists = involved_activity }
	}

	immediate = {
		random_owned_story = {
			type = story_cycle_hunt_mystical_animal
			limit = {
				NOT = { exists = var:had_event_hunt_mystical_animal_1002 }
			}			
			save_scope_as = story
		}
		hunt_mystical_animal_immediate_effect = {
			EVENT_NUMBER = 1002
			ENCOUNTER = yes
		}
	}

	option = {
		name = hunt_mystical_animal.1002.a
		add_stress = medium_stress_gain
	}
}

#Send people to look for the animal?
#by Linnéa Thimrén
hunt_mystical_animal.1003 = {
	type = character_event
	title = hunt_mystical_animal.1001.t
	desc = hunt_mystical_animal.1003.desc
	theme = hunting
	override_background = {
		reference = study
	}
	left_portrait = {
		character = root
		animation = worry
	}
	lower_right_portrait = scope:steward
	lower_center_portrait = scope:m_hunt

	trigger = {
		scope:story = {
			NOT = { exists = var:had_event_hunt_mystical_animal_1003 }
		}
		is_landed = yes
	}

	immediate = {
		hunt_mystical_animal_immediate_effect = {
			EVENT_NUMBER = 1003
			ENCOUNTER = no
		}
		if = {
			limit = {
				exists = cp:councillor_steward
			}
			cp:councillor_steward = { save_scope_as = steward }
		}
		if = {
			limit = {
				has_royal_court = yes
				employs_court_position = master_of_hunt_court_position
				any_court_position_holder = {
					type = master_of_hunt_court_position
					is_available_healthy_ai_adult = yes
				}
			}
			random_court_position_holder = {
				type = master_of_hunt_court_position
				limit = { is_available_healthy_ai_adult = yes }
				save_scope_as = m_hunt
			}
		}
	}

	option = { #Hire people to look for the animal
		name = hunt_mystical_animal.1003.a
		trigger = {
			gold >= medium_gold_value
			NOT = { exists = scope:m_hunt }
		}
		show_as_unavailable = {
			short_term_gold < medium_gold_value
		}
		remove_short_term_gold = medium_gold_value
		stress_impact = {
			greedy = medium_stress_impact_gain
		}
	}

	option = {		#Send Master of Hunt
		name = hunt_mystical_animal.1003.e
		trigger = {
			exists = scope:m_hunt
			gold >= minor_gold_value
		}
		show_as_unavailable = {
			short_term_gold < minor_gold_value
		}
		remove_short_term_gold = minor_gold_value	
		scope:m_hunt = {
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 15
			}
		}
		stress_impact = {
			greedy = minor_stress_impact_gain
		}
	}

	option = { #My steward will fix this
		name = hunt_mystical_animal.1003.c
		trigger = { exists = scope:steward }
		scope:steward = {
			add_opinion = {
				target = root
				modifier = cruelty_opinion
				opinion = -15
			}
		}
	}

	option = { #I'll keep it up!!
		name = hunt_mystical_animal.1003.d
		add_stress = medium_stress_gain
	}

	option = { #No
		name = hunt_mystical_animal.1003.b
		custom_tooltip = hunt_mystical_animal.1003.b.tt
		scope:story = {
			hidden_effect = { end_story = yes }
		}
	}
}

#Someone has seen the animal!
#by Linnéa Thimrén
hunt_mystical_animal.1004 = {
	type = character_event
	title = hunt_mystical_animal.1001.t
	desc = hunt_mystical_animal.1004.desc
	theme = hunting
	override_background = { reference = relaxing_room }
	left_portrait = {
		character = root
		animation = disbelief
	}
	right_portrait = {
		character = scope:m_hunt
		animation = admiration
	}

	trigger = {
		scope:story = {
			NOT = { exists = var:had_event_hunt_mystical_animal_1004 }
			NOT = { exists = var:had_event_hunt_mystical_animal_1007 }
			var:encounters >= 2
			exists = var:animal_type
			var:legendary_county = {
				this != root.location.county
				any_neighboring_county = { this = root.location.county }
			}
		}
	}

	weight_multiplier = {
		base = 1
		modifier = { #More likely to trigger if you've sent people to look for it
			add = 2
			scope:story = {
				exists = var:had_event_hunt_mystical_animal_1003
			}
		}
	}

	immediate = {
		hunt_mystical_animal_immediate_effect = {
			EVENT_NUMBER = 1004
			ENCOUNTER = yes
		}
		if = {
			limit = {
				employs_court_position = master_of_hunt_court_position
				court_position:master_of_hunt_court_position = { is_available = yes }
			}
			court_position:master_of_hunt_court_position = { save_scope_as = m_hunt }
		}
		else = {
			random_courtier = {
				limit = {
					can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root } 
				}
				weight = {
					base = 10
					modifier = {
						factor = 2
						has_trait = lifestyle_hunter
					}
					# Not priest
					modifier = {
						factor = 0
						is_clergy = yes
					}
					modifier = {
						factor = 0
						hunt_dharmic_pacificist_trigger = yes
					}
				}
				save_scope_as = m_hunt
			}
		}
		location.county = {
			# Create new sighting
			hunt_create_sighting_effect = {
				TYPE = legendary
				ANIMAL = scope:story.var:animal_type
				OWNER = root
			}
		}
		scope:story = {
			# Remove old sighting
			var:legendary_county = { hunt_remove_sighting_effect = yes }
			# Update legendary location
			set_variable = {
				name = legendary_county
				value = root.location.county
			}
		}
		save_scope_value_as = {
			name = integer
			value = { 3 5 }
		}
	}

	option = { #We ride!
		name = hunt_mystical_animal.1004.a
		flavor = hunt_mystical_animal.1004.a.tt

		scope:story = {
			set_variable = { #To safeguard against other events triggering at the same time as this goes down
				name = killing_animal
				value = yes
			}
		}
	}

	option = { #Nah
		name = hunt_mystical_animal.1004.b
		custom_tooltip = hunt_mystical_animal.1003.b.tt
		location.county = { hunt_remove_sighting_effect = yes }
		scope:story = {
			hidden_effect = { end_story = yes }
		}
	}
}

#You don't catch it....
#by Linnéa Thimrén
hunt_mystical_animal.1005 = {
	type = activity_event
	title = hunt.0510.t
	desc = {
		desc = hunt_mystical_animal.9001.desc
		desc = hunt_mystical_animal.1005.desc
	}
	theme = hunt_activity
	override_background = { reference = ep2_hunt_foggy_forest }
	left_portrait = {
		character = root
		animation = stress
	}

	trigger = {
		trigger_if = {
			limit = { exists = scope:activity }
			scope:activity = {
				has_activity_type = activity_hunt
				has_activity_option = { category = special_type option = hunt_type_legendary }
				NOR = {
					exists = var:hunt_4013
					exists = var:hunt_4017
					exists = var:hunt_4019
				}
			}
		}
		any_owned_story = { type = story_cycle_hunt_mystical_animal }
	}

	immediate = {
		scope:activity = {
			set_variable = {
				name = hunt_success
				value = flag:no
			}
		}
		random_owned_story = {
			limit = { story_type = story_cycle_hunt_mystical_animal }
			save_scope_as = story
		}
	}

	option = {
		name = hunt_mystical_animal.1005.a
		scope:story = { #To unlock events again
			remove_variable = killing_animal
		}
		add_stress = minor_stress_gain
	}
}

#You lose your mind
#by Linnéa Thimrén
hunt_mystical_animal.1006 = {
	type = character_event
	title = hunt_mystical_animal.1001.t
	desc = hunt_mystical_animal.1006.desc
	theme = hunting
	override_background = { reference = bedchamber }
	left_portrait = {
		character = root
		animation = paranoia
		outfit_tags = { nightgown }
	}

	trigger = {
		scope:story = {
			NOT = { exists = var:had_event_hunt_mystical_animal_1006 }
			var:encounters > 3
		}
		NOT = { has_trait = lunatic }
	}

	weight_multiplier = {
		base = 1
		modifier = { #More likely to trigger if you've encountered it more
			add = 1
			scope:story = {
				var:encounters > 4
			}
		}
	}

	immediate = {
		hunt_mystical_animal_immediate_effect = {
			EVENT_NUMBER = 1006
			ENCOUNTER = yes
		}
		add_trait = lunatic_1
	}

	option = {
		name = hunt_mystical_animal.1006.a
		trait = lunatic_1
	}

	option = { #Nah
		name = hunt_mystical_animal.1006.b
		trait = lunatic_1
		custom_tooltip = hunt_mystical_animal.1003.b.tt
		scope:story = {
			hidden_effect = { end_story = yes }
		}
	}
}

#Down the rabbit hole
#by Linnéa Thimrén
hunt_mystical_animal.1007 = {
	type = character_event
	title = hunt_mystical_animal.1001.t
	desc = hunt_mystical_animal.1007.desc
	theme = hunting
	override_background = { reference = ep2_hunt_foggy_forest }
	left_portrait = root

	trigger = {
		any_owned_story = {
			type = story_cycle_hunt_mystical_animal
			NOT = { exists = var:had_event_hunt_mystical_animal_1007 }
			NOT = { exists = var:had_event_hunt_mystical_animal_1004 }
			var:encounters >= 1
			var:animal_type = flag:hare
		}
		has_trait = lunatic
	}

	immediate = {
		random_owned_story = { #Unop ck3-tiger Used in hunt_mystical_animal_immediate_effect below
			limit = { story_type = story_cycle_hunt_mystical_animal }
			save_scope_as = story
		}
		hunt_mystical_animal_immediate_effect = {
			EVENT_NUMBER = 1007
			ENCOUNTER = yes
		}
		save_scope_value_as = {
			name = integer
			value = { 3 5 }
		}
	}

	option = {
		name = hunt_mystical_animal.1007.a
		flavor = hunt_mystical_animal.1004.a.tt
		trait = lunatic_1
		scope:story = {
			set_variable = { #To safeguard against other events triggering at the same time as this goes down
				name = killing_animal
				value = yes
			}
		}
		show_as_tooltip = {
			random = {
				chance = 50
				modifier = {
					has_trait_xp = {
						trait = lifestyle_hunter
						track = hunter
						value >= 50
					}
					add = 5
				}
				modifier = {
					has_trait_xp = {
						trait = lifestyle_hunter
						track = hunter
						value >= 100
					}
					add = 5
				}
				modifier = { add = scope:integer }
				custom_tooltip = hunt_mystical_animal.1004.a.success
			}
		}
		hidden_effect = {
			random_list = {
				50 = { #You get it!!
					modifier = {
						has_trait_xp = {
							trait = lifestyle_hunter
							track = hunter
							value >= 50
						}
						add = 5
					}
					modifier = {
						has_trait_xp = {
							trait = lifestyle_hunter
							track = hunter
							value >= 100
						}
						add = 5
					}
					modifier = { add = scope:integer }
					trigger_event = {
						id = hunt_mystical_animal.9001
						days = 1
					}
				}
				50 = { #You don't catch it....
					modifier = {
						add = {
							value = scope:integer
							multiply = -1
						}
					}
					trigger_event = {
						id = hunt_mystical_animal.1005
						days = 1
					}
				}
			}
		}
	}
	option = { #Nah
		name = hunt_mystical_animal.1007.b
		custom_tooltip = hunt_mystical_animal.1003.b.tt
		scope:story = {
			hidden_effect = { end_story = yes }
		}
		random_list = {
			80 = {
				desc = hunt_mystical_animal.1007.b.success
				send_interface_toast = {
					title = hunt_mystical_animal.1007.b.success
					add_character_modifier = {
						modifier = feast_good_food_modifier
						years = 5
					}
				}
			}
			20 = {
				desc = hunt_mystical_animal.1007.b.failure
				send_interface_toast = {
					title = hunt_mystical_animal.1007.b.failure
					add_character_modifier = {
						modifier = feast_bad_reaction_to_food
						years = 5
					}
				}
			}
		}
	}
}

#Ask peasants to look for it
#by Linnéa Thimrén
hunt_mystical_animal.1008 = {
	type = character_event
	title = hunt_mystical_animal.1001.t
	desc = hunt_mystical_animal.1008.desc
	theme = hunting
	left_portrait = {
		character = root
		animation = personality_cynical
	}
	right_portrait = scope:knight

	trigger = {
		scope:story = {
			NOT = { exists = var:had_event_hunt_mystical_animal_1008 }
		}
		any_knight = {
			basic_is_available_ai = yes
		}
	}

	immediate = {
		hunt_mystical_animal_immediate_effect = {
			EVENT_NUMBER = 1008
			ENCOUNTER = yes
		}
		if = {
			limit = {
				has_royal_court = yes
				employs_court_position = master_of_hunt_court_position
				any_court_position_holder = {
					type = master_of_hunt_court_position
					is_available_healthy_ai_adult = yes
				}
			}
			random_court_position_holder = {
				type = master_of_hunt_court_position
				limit = { is_available_healthy_ai_adult = yes }
				save_scope_as = knight
			}
		}
		else_if = {
			limit = {
				any_knight = {
					basic_is_available_ai = yes
				}
			}
			random_knight = {
				limit = {
					basic_is_available_ai = yes
				}
				save_scope_as = knight
			}
		}
	}

	option = { #Hire people to look for the animal
		name = hunt_mystical_animal.1008.a
		add_prestige = medium_prestige_loss
		stress_impact = {
			arrogant = medium_stress_impact_gain
		}
	}

	option = { #Send a knight (or Master of the Hunt)
		name = hunt_mystical_animal.1008.c
		trigger = { exists = scope:knight }
		scope:knight = {
			add_opinion = {
				target = root
				modifier = annoyed_opinion
				opinion = -10
			}
			add_character_modifier = {
				modifier = mystical_animal_distracted_knight_modifier
				years = 3
			}
		}
	}

	option = { #No
		name = hunt_mystical_animal.1008.b
		custom_tooltip = hunt_mystical_animal.1003.b.tt
		scope:story = {
			hidden_effect = { end_story = yes }
		}
	}
}

#Your court chaplain is worried
#by Linnéa Thimrén
hunt_mystical_animal.1009 = {
	type = character_event
	title = hunt_mystical_animal.1001.t
	desc = hunt_mystical_animal.1009.desc
	theme = hunting
	left_portrait = {
		character = scope:court_chaplain
		animation = worry
	}

	trigger = {
		scope:story = {
			NOT = { exists = var:had_event_hunt_mystical_animal_1009 }
		}
		exists = cp:councillor_court_chaplain
	}

	immediate = {
		hunt_mystical_animal_immediate_effect = {
			EVENT_NUMBER = 1009
			ENCOUNTER = no
		}
		cp:councillor_court_chaplain = {
			save_scope_as = court_chaplain
		}
	}

	option = { #It's God's will
		name = hunt_mystical_animal.1009.a
		duel = {
			skill = learning
			target = scope:court_chaplain
			30 = {
				desc = hunt_mystical_animal.1009.a.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 0.5
				}
				send_interface_toast = {
					title = hunt_mystical_animal.1009.a.success
					left_icon = root
					add_piety = medium_piety_gain
				}
			}
			10 = {
				desc = hunt_mystical_animal.1009.a.failure
				send_interface_toast = {
					title = hunt_mystical_animal.1009.a.failure
					left_icon = root
					scope:court_chaplain = {
						add_opinion = {
							target = root
							modifier = respect_opinion
							opinion = -15
						}
					}
				}
			}
		}
		skill = learning
	}

	option = { #Mind your own business
		name = hunt_mystical_animal.1009.b
		scope:court_chaplain = {
			add_opinion = {
				target = root
				modifier = insult_opinion
				opinion = -10
			}
		}
	}

	option = { #I will stop
		name = hunt_mystical_animal.1009.c
		custom_tooltip = hunt_mystical_animal.1003.b.tt
		scope:story = {
			hidden_effect = { end_story = yes }
		}
		add_piety = minor_piety_gain
	}
}

#You catch it! YOU GO, AHAB!!
#by Linnéa Thimrén
hunt_mystical_animal.9001 = {
	type = activity_event
	title = hunt.0510.t
	desc = hunt_mystical_animal.9001.desc
	theme = hunt_activity
	override_background = { reference = ep2_hunt_foggy_forest }
	left_portrait = {
		character = root
		animation = ecstasy
	}
	artifact = {
		position = lower_right_portrait
		target = scope:newly_created_artifact
	}

	trigger = {
		trigger_if = {
			limit = { exists = scope:activity }
			scope:activity = {
				has_activity_type = activity_hunt
				has_activity_option = { category = special_type option = hunt_type_legendary }
				NOR = {
					exists = var:hunt_4013
					exists = var:hunt_4019
				}
			}
		}
		any_owned_story = { type = story_cycle_hunt_mystical_animal }
	}

	immediate = {
		scope:activity = {
			set_variable = {
				name = hunt_success
				value = flag:yes
			}
		}
		end_hunt_mystical_animal_story_cycle_effect = yes
	}

	option = { #Shoot!
		name = hunt.1032.a
		trigger = {
			can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:host }
		}
		hunt_animal_bow_kill_effect = { DEATH = yes VAR = scope:activity.var:animal_type }
		stress_impact = {
			compassionate = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50
			modifier = {
				add = 40
				OR = {
					has_trait = impatient
					has_trait = callous
					has_trait = sadistic
				}
			}
		}
	}

	option = { #Take it down!
		name = hunt.1032.e
		custom_tooltip = hunt.1032.e.tt
		hunt_no_pelt_effect = yes # No pelt trophies
		stress_impact = {
			greedy = minor_stress_impact_gain
			arrogant = minor_stress_impact_gain
			brave = minor_stress_impact_gain
			diligent = minor_stress_impact_gain
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_compassion = -0.5
				ai_greed = -1
			}
		}
	}
}

#Someone else got it (fallback event for if it's been going on for too long)
#by Linnéa Thimrén
hunt_mystical_animal.9002 = {
	type = character_event
	title = hunt_mystical_animal.1001.t
	desc = hunt_mystical_animal.9002.desc
	theme = hunting
	override_background = { reference = relaxing_room }
	left_portrait = {
		character = root
		animation = disbelief
	}
	right_portrait = {
		character = scope:m_hunt
		animation = worry
	}

	trigger = {
		scope:story.var:encounters > 5
	}

	immediate = {
		hunt_save_master_or_hunter_courtier_effect = yes
		random_dummy_gender_soldier_effect = { SCOPE_NAME = dummy_gender }
		scope:story = {
			hidden_effect = { end_story = yes }
		}
	}

	option = {
		name = hunt_mystical_animal.9002.a
		add_character_modifier = {
			modifier = modifier_hunt_dog_trophy_modifier
			years = 5
		}
	}
}
