﻿
pets_expanded_enable_window_trigger = {
	is_valid = {
		custom_description = {
			text = pets_expanded_has_any_pet_trigger
			OR = {
				has_any_pet_trigger = yes
				AND = {
					has_variable_list = dead_pets_list
					any_in_list = {
						variable = dead_pets_list
						count >= 1
					}
				}
			}
		}
	}
}


PE_gui_toggle = {
	scope = character

	is_shown = {
		has_variable = PE_gui_toggle
	}

	effect = {
		toggle_pet_window_variable_effect = yes
	}
}

#To "convert" the vanilla cat/dog/warhorse stories to work in Pets Expanded
#Also, to add the "allowed breeding" variable to any stories that doesn't have it even tho you have no keeper (as a safe-guard, and as a conversion for older stories that weren't created with that variable)
PE_gui_start_game_effect = {
	scope = character

	effect = {
		#To convert old pet stories to the "new" system introduced by the mod
		#CAT
		if = {
			limit = {
				any_owned_story = {
					story_type = story_cycle_pet_cat
					NOT = { exists = var:updated_pet_story }
				}
			}
			random_owned_story = {
				limit = {
					story_type = story_cycle_pet_cat
					NOT = { exists = var:updated_pet_story }
				}
				save_scope_as = old_cat_story
			}
			set_variable = {
				name = original_pet_story
				value = scope:old_cat_story
			}
			if = {
				limit = { exists = scope:old_cat_story.var:cat_gender }
				set_variable = {
					name = pet_gender
					value = scope:old_cat_story.var:cat_gender
				}
			}
			if = {
				limit = { exists = scope:old_cat_story.var:cat_fur_color }
				set_variable = {
					name = body_color
					value = scope:old_cat_story.var:cat_fur_color
				}
			}
			if = {
				limit = { exists = scope:old_cat_story.var:cat_eye_color }
				set_variable = {
					name = eye_color
					value = scope:old_cat_story.var:cat_eye_color
				}
			}
			start_pet_story_cycle_effect = { PET_TYPE = cat }
		}
		#DOG
		if = {
			limit = {
				any_owned_story = {
					story_type = story_cycle_pet_dog
					NOT = { exists = var:updated_pet_story }
				}
			}
			random_owned_story = {
				limit = {
					story_type = story_cycle_pet_dog
					NOT = { exists = var:updated_pet_story }
				}
				save_scope_as = old_dog_story
			}
			set_variable = {
				name = original_pet_story
				value = scope:old_dog_story
			}
			if = {
				limit = { exists = scope:old_dog_story.var:dog_gender }
				set_variable = {
					name = pet_gender
					value = scope:old_dog_story.var:dog_gender
				}
			}
			if = {
				limit = { exists = scope:old_dog_story.var:dog_fur_color }
				set_variable = {
					name = body_color
					value = scope:old_dog_story.var:dog_fur_color
				}
			}
			if = {
				limit = { exists = scope:old_dog_story.var:dog_eye_color }
				set_variable = {
					name = eye_color
					value = scope:old_dog_story.var:dog_eye_color
				}
			}
			start_pet_story_cycle_effect = { PET_TYPE = dog }
		}
		#WARHORSE
		if = {
			limit = {
				any_owned_story = {
					story_type = story_cycle_martial_lifestyle_warhorse
					NOT = { exists = var:updated_pet_story }
				}
			}
			random_owned_story = {
				limit = {
					story_type = story_cycle_martial_lifestyle_warhorse
					NOT = { exists = var:updated_pet_story }
				}
				save_scope_as = old_horse_story
			}
			set_variable = {
				name = original_pet_story
				value = scope:old_horse_story
			}
			if = {
				limit = { exists = scope:old_horse_story.var:horse_gender }
				set_variable = {
					name = pet_gender
					value = scope:old_horse_story.var:horse_gender
				}
			}
			start_pet_story_cycle_effect = { PET_TYPE = horse }
		}

		#To avoid errors
		assign_cat_gender_effect = { GENDER = random }
		assign_cat_fur_color_effect = { COLOR = random }
		assign_cat_eye_color_effect = { COLOR = random }
		assign_dog_gender_effect = { GENDER = random }
		assign_dog_fur_color_effect = { COLOR = random }
		assign_dog_eye_color_effect = { COLOR = random }

		remove_variable = cat_eye_color
		remove_variable = cat_fur_color
		remove_variable = cat_gender
		remove_variable = dog_eye_color
		remove_variable = dog_fur_color
		remove_variable = dog_gender


		#To add the "allowed breeding" variable
		if = {
			limit = {
				any_owned_story = {
					is_pet_story_trigger = yes
					NOT = { exists = var:allowed_to_breed }
				}
				NOT = { employs_court_position = keeper_of_menagerie_court_position }
			}
			every_owned_story = {
				limit = {
					is_pet_story_trigger = yes
					NOT = { exists = var:allowed_to_breed }
				}
				set_variable = allowed_to_breed
			}
		}
	}
}






PE_dead_pet_is_cat_trigger = {
	scope = character
	saved_scopes = { story }
	is_valid = {
		has_variable_list = dead_cat_list
		any_in_list = {
			variable = dead_cat_list
			this = scope:story
		}
	}
}

PE_dead_pet_is_dog_trigger = {
	scope = character
	saved_scopes = { story }
	is_valid = {
		has_variable_list = dead_dog_list
		any_in_list = {
			variable = dead_dog_list
			this = scope:story
		}
	}
}

PE_dead_pet_is_badger_trigger = {
	scope = character
	saved_scopes = { story }
	is_valid = {
		has_variable_list = dead_badger_list
		any_in_list = {
			variable = dead_badger_list
			this = scope:story
		}
	}
}

PE_dead_pet_is_bear_trigger = {
	scope = character
	saved_scopes = { story }
	is_valid = {
		has_variable_list = dead_bear_list
		any_in_list = {
			variable = dead_bear_list
			this = scope:story
		}
	}
}

PE_dead_pet_is_falcon_trigger = {
	scope = character
	saved_scopes = { story }
	is_valid = {
		has_variable_list = dead_falcon_list
		any_in_list = {
			variable = dead_falcon_list
			this = scope:story
		}
	}
}

PE_dead_pet_is_ferret_trigger = {
	scope = character
	saved_scopes = { story }
	is_valid = {
		has_variable_list = dead_ferret_list
		any_in_list = {
			variable = dead_ferret_list
			this = scope:story
		}
	}
}

PE_dead_pet_is_fox_trigger = {
	scope = character
	saved_scopes = { story }
	is_valid = {
		has_variable_list = dead_fox_list
		any_in_list = {
			variable = dead_fox_list
			this = scope:story
		}
	}
}

PE_dead_pet_is_hedgehog_trigger = {
	scope = character
	saved_scopes = { story }
	is_valid = {
		has_variable_list = dead_hedgehog_list
		any_in_list = {
			variable = dead_hedgehog_list
			this = scope:story
		}
	}
}

PE_dead_pet_is_lion_trigger = {
	scope = character
	saved_scopes = { story }
	is_valid = {
		has_variable_list = dead_lion_list
		any_in_list = {
			variable = dead_lion_list
			this = scope:story
		}
	}
}

PE_dead_pet_is_monkey_trigger = {
	scope = character
	saved_scopes = { story }
	is_valid = {
		has_variable_list = dead_monkey_list
		any_in_list = {
			variable = dead_monkey_list
			this = scope:story
		}
	}
}

PE_dead_pet_is_nightingale_trigger = {
	scope = character
	saved_scopes = { story }
	is_valid = {
		has_variable_list = dead_nightingale_list
		any_in_list = {
			variable = dead_nightingale_list
			this = scope:story
		}
	}
}

PE_dead_pet_is_parrot_trigger = {
	scope = character
	saved_scopes = { story }
	is_valid = {
		has_variable_list = dead_parrot_list
		any_in_list = {
			variable = dead_parrot_list
			this = scope:story
		}
	}
}

PE_dead_pet_is_rabbit_trigger = {
	scope = character
	saved_scopes = { story }
	is_valid = {
		has_variable_list = dead_rabbit_list
		any_in_list = {
			variable = dead_rabbit_list
			this = scope:story
		}
	}
}

PE_dead_pet_is_squirrel_trigger = {
	scope = character
	saved_scopes = { story }
	is_valid = {
		has_variable_list = dead_squirrel_list
		any_in_list = {
			variable = dead_squirrel_list
			this = scope:story
		}
	}
}

PE_dead_pet_is_tiger_trigger = {
	scope = character
	saved_scopes = { story }
	is_valid = {
		has_variable_list = dead_tiger_list
		any_in_list = {
			variable = dead_tiger_list
			this = scope:story
		}
	}
}

PE_dead_pet_is_weasel_trigger = {
	scope = character
	saved_scopes = { story }
	is_valid = {
		has_variable_list = dead_weasel_list
		any_in_list = {
			variable = dead_weasel_list
			this = scope:story
		}
	}
}

PE_dead_pet_is_elephant_trigger = {
	scope = character
	saved_scopes = { story }
	is_valid = {
		has_variable_list = dead_elephant_list
		any_in_list = {
			variable = dead_elephant_list
			this = scope:story
		}
	}
}

PE_dead_pet_is_hawk_trigger = {
	scope = character
	saved_scopes = { story }
	is_valid = {
		has_variable_list = dead_hawk_list
		any_in_list = {
			variable = dead_hawk_list
			this = scope:story
		}
	}
}

PE_dead_pet_is_raven_trigger = {
	scope = character
	saved_scopes = { story }
	is_valid = {
		has_variable_list = dead_raven_list
		any_in_list = {
			variable = dead_raven_list
			this = scope:story
		}
	}
}

PE_dead_pet_is_horse_trigger = {
	scope = character
	saved_scopes = { story }
	is_valid = {
		has_variable_list = dead_horse_list
		any_in_list = {
			variable = dead_horse_list
			this = scope:story
		}
	}
}




PE_gui_named_pet_1_effect = {
	scope = character

	effect = {
		set_variable = {
			name = pet_chosen_name
			value = var:pet_name_1
		}
	}
}
PE_gui_named_pet_2_effect = {
	scope = character

	effect = {
		set_variable = {
			name = pet_chosen_name
			value = var:pet_name_2
		}
	}
}
PE_gui_named_pet_3_effect = {
	scope = character

	effect = {
		set_variable = {
			name = pet_chosen_name
			value = var:pet_name_3
		}
	}
}
#PE_gui_named_pet_custom_effect = {
#	scope = character
#
#	effect = {
#		if = {
#			limit = {
#				exists = var:is_naming_pet
#				var:is_naming_pet = { story_type = PE_story_cycle_horse}
#			}
#			var:is_naming_pet = {
#				set_variable = { #
#					name = story_cycle_horse_name
#					value = flag:yes
#				}
#			}
#		}
#	}
#}

PE_gift_pet_gui_toggle = {
	scope = character

	is_shown = {
		has_variable = PE_gift_pet_gui_toggle
	}

	effect = {
		if = {
			limit = {
				has_variable = PE_gift_pet_gui_toggle
			}
			remove_variable = PE_gift_pet_gui_toggle
		}
		else = {
			set_variable = PE_gift_pet_gui_toggle
		}
	}
}

PE_gift_pet_confirm = {
	scope = character

	effect = {
		var:PE_gift_pet_gui_recipient = { save_scope_as = recipient }
		save_scope_as = actor
		var:selected_story_scope = { save_scope_as = story }

		send_interface_message = {
			type = event_pets_expanded_neutral
			title = gift_pet_interaction_notification
			left_icon = scope:recipient
			
			scope:recipient = {
				if = {
					limit = {
						scope:actor.var:selected_story_type = flag:cat
					}
					show_as_tooltip = { start_pet_story_cycle_effect = { PET_TYPE = cat } }
				}
				else_if = {
					limit = {
						scope:actor.var:selected_story_type = flag:dog
					}
					show_as_tooltip = { start_pet_story_cycle_effect = { PET_TYPE = dog } }
				}
				else_if = {
					limit = {
						scope:actor.var:selected_story_type = flag:badger
					}
					show_as_tooltip = { start_pet_story_cycle_effect = { PET_TYPE = badger } }
				}
				else_if = {
					limit = {
						scope:actor.var:selected_story_type = flag:bear
					}
					show_as_tooltip = { start_pet_story_cycle_effect = { PET_TYPE = bear } }
				}
				else_if = {
					limit = {
						scope:actor.var:selected_story_type = flag:falcon
					}
					show_as_tooltip = { start_pet_story_cycle_effect = { PET_TYPE = falcon } }
				}
				else_if = {
					limit = {
						scope:actor.var:selected_story_type = flag:ferret
					}
					show_as_tooltip = { start_pet_story_cycle_effect = { PET_TYPE = ferret } }
				}
				else_if = {
					limit = {
						scope:actor.var:selected_story_type = flag:fox
					}
					show_as_tooltip = { start_pet_story_cycle_effect = { PET_TYPE = fox } }
				}
				else_if = {
					limit = {
						scope:actor.var:selected_story_type = flag:hedgehog
					}
					show_as_tooltip = { start_pet_story_cycle_effect = { PET_TYPE = hedgehog } }
				}
				else_if = {
					limit = {
						scope:actor.var:selected_story_type = flag:lion
					}
					show_as_tooltip = { start_pet_story_cycle_effect = { PET_TYPE = lion } }
				}
				else_if = {
					limit = {
						scope:actor.var:selected_story_type = flag:monkey
					}
					show_as_tooltip = { start_pet_story_cycle_effect = { PET_TYPE = monkey } }
				}
				else_if = {
					limit = {
						scope:actor.var:selected_story_type = flag:nightingale
					}
					show_as_tooltip = { start_pet_story_cycle_effect = { PET_TYPE = nightingale } }
				}
				else_if = {
					limit = {
						scope:actor.var:selected_story_type = flag:parrot
					}
					show_as_tooltip = { start_pet_story_cycle_effect = { PET_TYPE = parrot } }
				}
				else_if = {
					limit = {
						scope:actor.var:selected_story_type = flag:rabbit
					}
					show_as_tooltip = { start_pet_story_cycle_effect = { PET_TYPE = rabbit } }
				}
				else_if = {
					limit = {
						scope:actor.var:selected_story_type = flag:squirrel
					}
					show_as_tooltip = { start_pet_story_cycle_effect = { PET_TYPE = squirrel } }
				}
				else_if = {
					limit = {
						scope:actor.var:selected_story_type = flag:tiger
					}
					show_as_tooltip = { start_pet_story_cycle_effect = { PET_TYPE = tiger } }
				}
				else_if = {
					limit = {
						scope:actor.var:selected_story_type = flag:weasel
					}
					show_as_tooltip = { start_pet_story_cycle_effect = { PET_TYPE = weasel } }
				}
				else_if = {
					limit = {
						scope:actor.var:selected_story_type = flag:elephant
					}
					show_as_tooltip = { start_pet_story_cycle_effect = { PET_TYPE = elephant } }
				}
				else_if = {
					limit = {
						scope:actor.var:selected_story_type = flag:hawk
					}
					show_as_tooltip = { start_pet_story_cycle_effect = { PET_TYPE = hawk } }
				}
				else_if = {
					limit = {
						scope:actor.var:selected_story_type = flag:raven
					}
					show_as_tooltip = { start_pet_story_cycle_effect = { PET_TYPE = raven } }
				}
				else_if = {
					limit = {
						scope:actor.var:selected_story_type = flag:horse
					}
					show_as_tooltip = { start_pet_story_cycle_effect = { PET_TYPE = horse } }
				}
			}
			if = {
				limit = {
					scope:recipient = { is_ai = yes }
				}
				
				reverse_add_opinion = {
					target = scope:recipient
					modifier = gift_pet_opinion
					opinion = gift_pet_opinion_value
				}
			}
		}

		#Actually change owner of the story
		transfer_pet_story_cycle_to_effect = {
			CHARACTER = scope:recipient
			STORY = scope:story
		}

		scope:story = {
			set_variable = {
				name = pet_gifted_by
				value = scope:actor
			}

			if = {
				limit = { has_variable = pet_gifted_by }
				#This is just to avoid errors
			}
		}

		#Give a player an event about what happened
		if = {
			limit = {
				scope:recipient = { is_ai = no }
			}
			scope:recipient = { trigger_event = pets_expanded.0011 }
		}
	}
}

#effect used when you click the icon in an event to open the menagerie
PE_gui_event_widget_open_menagerie_effect = {
	is_valid = { always = yes }
	saved_scopes = { story }
	effect = {
		random_owned_story = {
			limit = {
				exists = var:pet_dummy
				var:pet_dummy = scope:story
			}
			save_scope_as = story_scope
		}
		set_variable = {
			name = selected_story_scope
			value = scope:story_scope
		}
		if = {
			limit = {
				scope:story_scope = { story_type = PE_story_cycle_cat }
			}
			set_variable = {
				name = selected_story_type
				value = flag:cat
			}
		}
		else_if = {
			limit = {
				scope:story_scope = { story_type = PE_story_cycle_dog }
			}
			set_variable = {
				name = selected_story_type
				value = flag:dog
			}
		}
		else_if = {
			limit = {
				scope:story_scope = { story_type = PE_story_cycle_badger }
			}
			set_variable = {
				name = selected_story_type
				value = flag:badger
			}
		}
		else_if = {
			limit = {
				scope:story_scope = { story_type = PE_story_cycle_bear }
			}
			set_variable = {
				name = selected_story_type
				value = flag:bear
			}
		}
		else_if = {
			limit = {
				scope:story_scope = { story_type = PE_story_cycle_falcon }
			}
			set_variable = {
				name = selected_story_type
				value = flag:falcon
			}
		}
		else_if = {
			limit = {
				scope:story_scope = { story_type = PE_story_cycle_ferret }
			}
			set_variable = {
				name = selected_story_type
				value = flag:ferret
			}
		}
		else_if = {
			limit = {
				scope:story_scope = { story_type = PE_story_cycle_fox }
			}
			set_variable = {
				name = selected_story_type
				value = flag:fox
			}
		}
		else_if = {
			limit = {
				scope:story_scope = { story_type = PE_story_cycle_hedgehog }
			}
			set_variable = {
				name = selected_story_type
				value = flag:hedgehog
			}
		}
		else_if = {
			limit = {
				scope:story_scope = { story_type = PE_story_cycle_lion }
			}
			set_variable = {
				name = selected_story_type
				value = flag:lion
			}
		}
		else_if = {
			limit = {
				scope:story_scope = { story_type = PE_story_cycle_monkey }
			}
			set_variable = {
				name = selected_story_type
				value = flag:monkey
			}
		}
		else_if = {
			limit = {
				scope:story_scope = { story_type = PE_story_cycle_nightingale }
			}
			set_variable = {
				name = selected_story_type
				value = flag:nightingale
			}
		}
		else_if = {
			limit = {
				scope:story_scope = { story_type = PE_story_cycle_parrot }
			}
			set_variable = {
				name = selected_story_type
				value = flag:parrot
			}
		}
		else_if = {
			limit = {
				scope:story_scope = { story_type = PE_story_cycle_rabbit }
			}
			set_variable = {
				name = selected_story_type
				value = flag:rabbit
			}
		}
		else_if = {
			limit = {
				scope:story_scope = { story_type = PE_story_cycle_squirrel }
			}
			set_variable = {
				name = selected_story_type
				value = flag:squirrel
			}
		}
		else_if = {
			limit = {
				scope:story_scope = { story_type = PE_story_cycle_tiger }
			}
			set_variable = {
				name = selected_story_type
				value = flag:tiger
			}
		}
		else_if = {
			limit = {
				scope:story_scope = { story_type = PE_story_cycle_weasel }
			}
			set_variable = {
				name = selected_story_type
				value = flag:weasel
			}
		}
		else_if = {
			limit = {
				scope:story_scope = { story_type = PE_story_cycle_elephant }
			}
			set_variable = {
				name = selected_story_type
				value = flag:elephant
			}
		}
		else_if = {
			limit = {
				scope:story_scope = { story_type = PE_story_cycle_hawk }
			}
			set_variable = {
				name = selected_story_type
				value = flag:hawk
			}
		}
		else_if = {
			limit = {
				scope:story_scope = { story_type = PE_story_cycle_raven }
			}
			set_variable = {
				name = selected_story_type
				value = flag:raven
			}
		}
		else_if = {
			limit = {
				scope:story_scope = { story_type = PE_story_cycle_horse }
			}
			set_variable = {
				name = selected_story_type
				value = flag:horse
			}
		}
	}
}

#Let's make sure you still own the pet  
PE_gui_check_pet_story_cycle_visible = {
	scope = character
	#saved_scopes = {
	#	story
	#}
	is_shown = {
		exists = var:selected_story_scope
		this = var:selected_story_scope.story_owner
	}
}

PE_gui_display_effects  = {
	is_valid = {
		always = yes
	}
	saved_scopes = {
		recipient
	}

	effect = {
		# Warning for multiple gifts
		if = {
			limit = {
				scope:recipient = {
					has_opinion_modifier = {
						target = root
						modifier = gift_artifact_opinion
					}
				}
			}
			custom_tooltip = ALREADY_SENT_GIFT_WARNING
		}

		if = {
			limit = {
				var:selected_story_type = flag:cat
			}
			if = {
				limit = {
					scope:recipient = { any_owned_story = { story_type = PE_story_cycle_cat } }
				}
				custom_description_no_bullet = { text = already_has_pet_tt }
			}
			scope:recipient = { start_pet_story_cycle_effect = { PET_TYPE = cat } }
		}
		if = {
			limit = {
				var:selected_story_type = flag:dog
			}
			if = {
				limit = {
					scope:recipient = { any_owned_story = { story_type = PE_story_cycle_dog } }
				}
				custom_description_no_bullet = { text = already_has_pet_tt }
			}
			scope:recipient = { start_pet_story_cycle_effect = { PET_TYPE = dog } }
		}
		if = {
			limit = {
				var:selected_story_type = flag:badger
			}
			if = {
				limit = {
					scope:recipient = { any_owned_story = { story_type = PE_story_cycle_badger } }
				}
				custom_description_no_bullet = { text = already_has_pet_tt }
			}
			scope:recipient = { start_pet_story_cycle_effect = { PET_TYPE = badger } }
		}
		if = {
			limit = {
				var:selected_story_type = flag:bear
			}
			if = {
				limit = {
					scope:recipient = { any_owned_story = { story_type = PE_story_cycle_bear } }
				}
				custom_description_no_bullet = { text = already_has_pet_tt }
			}
			scope:recipient = { start_pet_story_cycle_effect = { PET_TYPE = bear } }
		}
		if = {
			limit = {
				var:selected_story_type = flag:falcon
			}
			if = {
				limit = {
					scope:recipient = { any_owned_story = { story_type = PE_story_cycle_falcon } }
				}
				custom_description_no_bullet = { text = already_has_pet_tt }
			}
			scope:recipient = { start_pet_story_cycle_effect = { PET_TYPE = falcon } }
		}
		if = {
			limit = {
				var:selected_story_type = flag:ferret
			}
			if = {
				limit = {
					scope:recipient = { any_owned_story = { story_type = PE_story_cycle_ferret } }
				}
				custom_description_no_bullet = { text = already_has_pet_tt }
			}
			scope:recipient = { start_pet_story_cycle_effect = { PET_TYPE = ferret } }
		}
		if = {
			limit = {
				var:selected_story_type = flag:fox
			}
			if = {
				limit = {
					scope:recipient = { any_owned_story = { story_type = PE_story_cycle_fox } }
				}
				custom_description_no_bullet = { text = already_has_pet_tt }
			}
			scope:recipient = { start_pet_story_cycle_effect = { PET_TYPE = fox } }
		}
		if = {
			limit = {
				var:selected_story_type = flag:hedgehog
			}
			if = {
				limit = {
					scope:recipient = { any_owned_story = { story_type = PE_story_cycle_hedgehog } }
				}
				custom_description_no_bullet = { text = already_has_pet_tt }
			}
			scope:recipient = { start_pet_story_cycle_effect = { PET_TYPE = hedgehog } }
		}
		if = {
			limit = {
				var:selected_story_type = flag:lion
			}
			if = {
				limit = {
					scope:recipient = { any_owned_story = { story_type = PE_story_cycle_lion } }
				}
				custom_description_no_bullet = { text = already_has_pet_tt }
			}
			scope:recipient = { start_pet_story_cycle_effect = { PET_TYPE = lion } }
		}
		if = {
			limit = {
				var:selected_story_type = flag:monkey
			}
			if = {
				limit = {
					scope:recipient = { any_owned_story = { story_type = PE_story_cycle_monkey } }
				}
				custom_description_no_bullet = { text = already_has_pet_tt }
			}
			scope:recipient = { start_pet_story_cycle_effect = { PET_TYPE = monkey } }
		}
		if = {
			limit = {
				var:selected_story_type = flag:nightingale
			}
			if = {
				limit = {
					scope:recipient = { any_owned_story = { story_type = PE_story_cycle_nightingale } }
				}
				custom_description_no_bullet = { text = already_has_pet_tt }
			}
			scope:recipient = { start_pet_story_cycle_effect = { PET_TYPE = nightingale } }
		}
		if = {
			limit = {
				var:selected_story_type = flag:parrot
			}
			if = {
				limit = {
					scope:recipient = { any_owned_story = { story_type = PE_story_cycle_parrot } }
				}
				custom_description_no_bullet = { text = already_has_pet_tt }
			}
			scope:recipient = { start_pet_story_cycle_effect = { PET_TYPE = parrot } }
		}
		if = {
			limit = {
				var:selected_story_type = flag:rabbit
			}
			if = {
				limit = {
					scope:recipient = { any_owned_story = { story_type = PE_story_cycle_rabbit } }
				}
				custom_description_no_bullet = { text = already_has_pet_tt }
			}
			scope:recipient = { start_pet_story_cycle_effect = { PET_TYPE = rabbit } }
		}
		if = {
			limit = {
				var:selected_story_type = flag:squirrel
			}
			if = {
				limit = {
					scope:recipient = { any_owned_story = { story_type = PE_story_cycle_squirrel } }
				}
				custom_description_no_bullet = { text = already_has_pet_tt }
			}
			scope:recipient = { start_pet_story_cycle_effect = { PET_TYPE = squirrel } }
		}
		if = {
			limit = {
				var:selected_story_type = flag:tiger
			}
			if = {
				limit = {
					scope:recipient = { any_owned_story = { story_type = PE_story_cycle_tiger } }
				}
				custom_description_no_bullet = { text = already_has_pet_tt }
			}
			scope:recipient = { start_pet_story_cycle_effect = { PET_TYPE = tiger } }
		}
		if = {
			limit = {
				var:selected_story_type = flag:weasel
			}
			if = {
				limit = {
					scope:recipient = { any_owned_story = { story_type = PE_story_cycle_weasel } }
				}
				custom_description_no_bullet = { text = already_has_pet_tt }
			}
			scope:recipient = { start_pet_story_cycle_effect = { PET_TYPE = weasel } }
		}
		if = {
			limit = {
				var:selected_story_type = flag:elephant
			}
			if = {
				limit = {
					scope:recipient = { any_owned_story = { story_type = PE_story_cycle_elephant } }
				}
				custom_description_no_bullet = { text = already_has_pet_tt }
			}
			scope:recipient = { start_pet_story_cycle_effect = { PET_TYPE = elephant } }
		}
		if = {
			limit = {
				var:selected_story_type = flag:hawk
			}
			if = {
				limit = {
					scope:recipient = { any_owned_story = { story_type = PE_story_cycle_hawk } }
				}
				custom_description_no_bullet = { text = already_has_pet_tt }
			}
			scope:recipient = { start_pet_story_cycle_effect = { PET_TYPE = hawk } }
		}
		if = {
			limit = {
				var:selected_story_type = flag:raven
			}
			if = {
				limit = {
					scope:recipient = { any_owned_story = { story_type = PE_story_cycle_raven } }
				}
				custom_description_no_bullet = { text = already_has_pet_tt }
			}
			scope:recipient = { start_pet_story_cycle_effect = { PET_TYPE = raven } }
		}
		if = {
			limit = {
				var:selected_story_type = flag:horse
			}
			if = {
				limit = {
					scope:recipient = { any_owned_story = { story_type = PE_story_cycle_horse } }
				}
				custom_description_no_bullet = { text = already_has_pet_tt }
			}
			scope:recipient = { start_pet_story_cycle_effect = { PET_TYPE = horse } }
		}

		scope:recipient = {
			show_as_tooltip = {
				if = {
					limit = { is_ai = yes }
					add_opinion = {
						target = root
						modifier = gift_pet_opinion
						opinion = gift_pet_opinion_value
					}
				}
			}
			hidden_effect = {
				send_interface_message = {
					type = event_generic_neutral
					title = gift_artifact_interaction_notification
					left_icon = root

					show_as_tooltip = {
						if = {
							limit = { is_ai = yes }
							add_opinion = {
								target = root
								modifier = gift_pet_opinion
								opinion = gift_pet_opinion_value
							}
						}
					}
				}
			}			
		}
	}
}

PE_gui_gift_pet_clear_saved_stuff_effect = {
	effect = {
		every_in_list = {
			variable = story_cycles
			remove_variable = story_type
			#remove_variable = story_type_scope
		}
		clear_variable_list = story_cycles
		remove_variable = selected_story_type
		remove_variable = selected_story_scope
		remove_variable = PE_gift_pet_gui_recipient
	}
}


PE_gui_get_story_cycles_list_effect = {
	is_shown = { }
	is_valid = { }
	effect = {
		create_story_cycles_list_effect = yes
		update_menagerie_level_effect = yes
	}
}


select_cat = {
	is_valid = { always = yes }
	saved_scopes = { story }
	effect = {
		if = {
			limit = {
				var:selected_story_type ?= flag:cat
				var:selected_story_scope ?= scope:story
			}
			remove_variable = selected_story_type
			remove_variable = selected_story_scope
		}
		else = {
			set_variable = {
				name = selected_story_type
				value = flag:cat
			}
			set_variable = {
				name = selected_story_scope
				value = scope:story
			}
		}
	}
}
select_dog = {
	is_valid = { always = yes }
	saved_scopes = { story }
	effect = {
		if = {
			limit = {
				var:selected_story_type ?= flag:dog
				var:selected_story_scope ?= scope:story
			}
			remove_variable = selected_story_type
			remove_variable = selected_story_scope
		}
		else = {
			set_variable = {
				name = selected_story_type
				value = flag:dog
			}
			set_variable = {
				name = selected_story_scope
				value = scope:story
			}
		}
	}
}
select_badger = {
	is_valid = { always = yes }
	saved_scopes = { story }
	effect = {
		if = {
			limit = {
				var:selected_story_type ?= flag:badger
				var:selected_story_scope ?= scope:story
			}
			remove_variable = selected_story_type
			remove_variable = selected_story_scope
		}
		else = {
			set_variable = {
				name = selected_story_type
				value = flag:badger
			}
			set_variable = {
				name = selected_story_scope
				value = scope:story
			}
		}
	}
}
select_bear = {
	is_valid = { always = yes }
	saved_scopes = { story }
	effect = {
		if = {
			limit = {
				var:selected_story_type ?= flag:bear
				var:selected_story_scope ?= scope:story
			}
			remove_variable = selected_story_type
			remove_variable = selected_story_scope
		}
		else = {
			set_variable = {
				name = selected_story_type
				value = flag:bear
			}
			set_variable = {
				name = selected_story_scope
				value = scope:story
			}
		}
	}
}
select_falcon = {
	is_valid = { always = yes }
	saved_scopes = { story }
	effect = {
		if = {
			limit = {
				var:selected_story_type ?= flag:falcon
				var:selected_story_scope ?= scope:story
			}
			remove_variable = selected_story_type
			remove_variable = selected_story_scope
		}
		else = {
			set_variable = {
				name = selected_story_type
				value = flag:falcon
			}
			set_variable = {
				name = selected_story_scope
				value = scope:story
			}
		}
	}
}
select_ferret = {
	is_valid = { always = yes }
	saved_scopes = { story }
	effect = {
		if = {
			limit = {
				var:selected_story_type ?= flag:ferret
				var:selected_story_scope ?= scope:story
			}
			remove_variable = selected_story_type
			remove_variable = selected_story_scope
		}
		else = {
			set_variable = {
				name = selected_story_type
				value = flag:ferret
			}
			set_variable = {
				name = selected_story_scope
				value = scope:story
			}
		}
	}
}
select_fox = {
	is_valid = { always = yes }
	saved_scopes = { story }
	effect = {
		if = {
			limit = {
				var:selected_story_type ?= flag:fox
				var:selected_story_scope ?= scope:story
			}
			remove_variable = selected_story_type
			remove_variable = selected_story_scope
		}
		else = {
			set_variable = {
				name = selected_story_type
				value = flag:fox
			}
			set_variable = {
				name = selected_story_scope
				value = scope:story
			}
		}
	}
}
select_hedgehog = {
	is_valid = { always = yes }
	saved_scopes = { story }
	effect = {
		if = {
			limit = {
				var:selected_story_type ?= flag:hedgehog
				var:selected_story_scope ?= scope:story
			}
			remove_variable = selected_story_type
			remove_variable = selected_story_scope
		}
		else = {
			set_variable = {
				name = selected_story_type
				value = flag:hedgehog
			}
			set_variable = {
				name = selected_story_scope
				value = scope:story
			}
		}
	}
}
select_lion = {
	is_valid = { always = yes }
	saved_scopes = { story }
	effect = {
		if = {
			limit = {
				var:selected_story_type ?= flag:lion
				var:selected_story_scope ?= scope:story
			}
			remove_variable = selected_story_type
			remove_variable = selected_story_scope
		}
		else = {
			set_variable = {
				name = selected_story_type
				value = flag:lion
			}
			set_variable = {
				name = selected_story_scope
				value = scope:story
			}
		}
	}
}
select_monkey = {
	is_valid = { always = yes }
	saved_scopes = { story }
	effect = {
		if = {
			limit = {
				var:selected_story_type ?= flag:monkey
				var:selected_story_scope ?= scope:story
			}
			remove_variable = selected_story_type
			remove_variable = selected_story_scope
		}
		else = {
			set_variable = {
				name = selected_story_type
				value = flag:monkey
			}
			set_variable = {
				name = selected_story_scope
				value = scope:story
			}
		}
	}
}
select_nightingale = {
	is_valid = { always = yes }
	saved_scopes = { story }
	effect = {
		if = {
			limit = {
				var:selected_story_type ?= flag:nightingale
				var:selected_story_scope ?= scope:story
			}
			remove_variable = selected_story_type
			remove_variable = selected_story_scope
		}
		else = {
			set_variable = {
				name = selected_story_type
				value = flag:nightingale
			}
			set_variable = {
				name = selected_story_scope
				value = scope:story
			}
		}
	}
}
select_parrot = {
	is_valid = { always = yes }
	saved_scopes = { story }
	effect = {
		if = {
			limit = {
				var:selected_story_type ?= flag:parrot
				var:selected_story_scope ?= scope:story
			}
			remove_variable = selected_story_type
			remove_variable = selected_story_scope
		}
		else = {
			set_variable = {
				name = selected_story_type
				value = flag:parrot
			}
			set_variable = {
				name = selected_story_scope
				value = scope:story
			}
		}
	}
}
select_rabbit = {
	is_valid = { always = yes }
	saved_scopes = { story }
	effect = {
		if = {
			limit = {
				var:selected_story_type ?= flag:rabbit
				var:selected_story_scope ?= scope:story
			}
			remove_variable = selected_story_type
			remove_variable = selected_story_scope
		}
		else = {
			set_variable = {
				name = selected_story_type
				value = flag:rabbit
			}
			set_variable = {
				name = selected_story_scope
				value = scope:story
			}
		}
	}
}
select_squirrel = {
	is_valid = { always = yes }
	saved_scopes = { story }
	effect = {
		if = {
			limit = {
				var:selected_story_type ?= flag:squirrel
				var:selected_story_scope ?= scope:story
			}
			remove_variable = selected_story_type
			remove_variable = selected_story_scope
		}
		else = {
			set_variable = {
				name = selected_story_type
				value = flag:squirrel
			}
			set_variable = {
				name = selected_story_scope
				value = scope:story
			}
		}
	}
}
select_tiger = {
	is_valid = { always = yes }
	saved_scopes = { story }
	effect = {
		if = {
			limit = {
				var:selected_story_type ?= flag:tiger
				var:selected_story_scope ?= scope:story
			}
			remove_variable = selected_story_type
			remove_variable = selected_story_scope
		}
		else = {
			set_variable = {
				name = selected_story_type
				value = flag:tiger
			}
			set_variable = {
				name = selected_story_scope
				value = scope:story
			}
		}
	}
}
select_weasel = {
	is_valid = { always = yes }
	saved_scopes = { story }
	effect = {
		if = {
			limit = {
				var:selected_story_type ?= flag:weasel
				var:selected_story_scope ?= scope:story
			}
			remove_variable = selected_story_type
			remove_variable = selected_story_scope
		}
		else = {
			set_variable = {
				name = selected_story_type
				value = flag:weasel
			}
			set_variable = {
				name = selected_story_scope
				value = scope:story
			}
		}
	}
}
select_elephant = {
	is_valid = { always = yes }
	saved_scopes = { story }
	effect = {
		if = {
			limit = {
				var:selected_story_type ?= flag:elephant
				var:selected_story_scope ?= scope:story
			}
			remove_variable = selected_story_type
			remove_variable = selected_story_scope
		}
		else = {
			set_variable = {
				name = selected_story_type
				value = flag:elephant
			}
			set_variable = {
				name = selected_story_scope
				value = scope:story
			}
		}
	}
}
select_hawk = {
	is_valid = { always = yes }
	saved_scopes = { story }
	effect = {
		if = {
			limit = {
				var:selected_story_type ?= flag:hawk
				var:selected_story_scope ?= scope:story
			}
			remove_variable = selected_story_type
			remove_variable = selected_story_scope
		}
		else = {
			set_variable = {
				name = selected_story_type
				value = flag:hawk
			}
			set_variable = {
				name = selected_story_scope
				value = scope:story
			}
		}
	}
}
select_raven = {
	is_valid = { always = yes }
	saved_scopes = { story }
	effect = {
		if = {
			limit = {
				var:selected_story_type ?= flag:raven
				var:selected_story_scope ?= scope:story
			}
			remove_variable = selected_story_type
			remove_variable = selected_story_scope
		}
		else = {
			set_variable = {
				name = selected_story_type
				value = flag:raven
			}
			set_variable = {
				name = selected_story_scope
				value = scope:story
			}
		}
	}
}
select_horse = {
	is_valid = { always = yes }
	saved_scopes = { story }
	effect = {
		if = {
			limit = {
				var:selected_story_type ?= flag:horse
				var:selected_story_scope ?= scope:story
			}
			remove_variable = selected_story_type
			remove_variable = selected_story_scope
		}
		else = {
			set_variable = {
				name = selected_story_type
				value = flag:horse
			}
			set_variable = {
				name = selected_story_scope
				value = scope:story
			}
		}
	}
}

PE_gui_clear_saved_stuff_effect = {
	effect = {
		every_in_list = {
			variable = story_cycles
			remove_variable = story_type
			#remove_variable = story_type_scope
		}
		clear_variable_list = story_cycles
		remove_variable = selected_story_type
		remove_variable = selected_story_scope
	}
}

PE_gui_you_own_mother_pet_trigger = {
	scope = character
	saved_scopes = { story }
	is_valid = {
		any_owned_story = {
			exists = var:pet_dummy
			var:pet_dummy = {
				this = scope:story.var:pet_dummy.mother
			}
		}
	}
}

PE_gui_clicked_mother_button_effect = {
	scope = character

	saved_scopes = {
		pet_scope
	}

	effect = {
		scope:story.var:pet_dummy = { save_scope_as = pet_dummy }
		if = {
			limit = {
				any_owned_story = {
					exists = var:pet_dummy
					var:pet_dummy = {
						this = scope:pet_dummy.mother
					}
				}
			}
			random_owned_story = {
				limit = {
					exists = var:pet_dummy
					var:pet_dummy = {
						this = scope:pet_dummy.mother
					}
				}
				save_scope_as = mother_story
			}
			set_variable = {
				name = selected_story_scope
				value = scope:mother_story
			}
		}
	}
}

PE_gui_display_pet_story_cycle_details_mother_effect = {
	is_valid = { always = yes }
	saved_scopes = { story }

	effect = {
		scope:story.var:pet_dummy = { save_scope_as = pet_dummy }
		if = {
			limit = {
				scope:pet_dummy = {
					any_parent = {
						exists = this
						even_if_dead = yes
						is_female = yes
					}
				}
			}
			custom_description_no_bullet = {
				text = PE_display_pet_story_cycle_details_mother_tt
				subject = scope:pet_dummy
			}
		}
		else = {
			custom_description_no_bullet = {
				text = PE_display_pet_story_cycle_details_mother_unknown_tt
				subject = scope:pet_dummy
			}
		}
	}
}

PE_gui_you_own_father_pet_trigger = {
	scope = character
	saved_scopes = { story }
	is_valid = {
		any_owned_story = {
			exists = var:pet_dummy
			var:pet_dummy = {
				this = scope:story.var:pet_dummy.father
			}
		}
	}
}

PE_gui_clicked_father_button_effect = {
	scope = character

	saved_scopes = {
		pet_scope
	}

	effect = {
		scope:story.var:pet_dummy = { save_scope_as = pet_dummy }
		if = {
			limit = {
				any_owned_story = {
					exists = var:pet_dummy
					var:pet_dummy = {
						this = scope:pet_dummy.father
					}
				}
			}
			random_owned_story = {
				limit = {
					exists = var:pet_dummy
					var:pet_dummy = {
						this = scope:pet_dummy.father
					}
				}
				save_scope_as = father_story
			}
			set_variable = {
				name = selected_story_scope
				value = scope:father_story
			}
		}
	}
}

PE_gui_display_pet_story_cycle_details_father_effect = {
	is_valid = { always = yes }
	saved_scopes = { story }

	effect = {
		scope:story.var:pet_dummy = { save_scope_as = pet_dummy }
		if = {
			limit = {
				scope:pet_dummy = {
					any_parent = {
						exists = this
						even_if_dead = yes
						is_female = no
					}
				}
			}
			custom_description_no_bullet = {
				text = PE_display_pet_story_cycle_details_father_tt
				subject = scope:pet_dummy
			}
		}
		else = {
			custom_description_no_bullet = {
				text = PE_display_pet_story_cycle_details_father_unknown_tt
				subject = scope:pet_dummy
			}
		}
	}
}

PE_gui_display_pet_story_cycle_details_effect = {
	is_valid = { always = yes }
	saved_scopes = { story }

	effect = {
		if = {
			limit = {
				scope:story = { has_variable = age_variable }
			}
			custom_tooltip = display_pet_story_cycle_details_age
		}
		custom_tooltip = display_pet_story_cycle_details_gender
		if = {
			limit = {
				scope:story = { has_variable = personality }
			}
			custom_tooltip = display_pet_story_cycle_details_personality
		}
		if = {
			limit = {		
				scope:story = { has_variable = health }
			}
			custom_tooltip = display_pet_story_cycle_details_health
		}
		if = {
			limit = {		
				scope:story = { has_variable = opinion_of_owner }
			}
			custom_tooltip = display_pet_story_cycle_details_opinion
		}
		#custom_tooltip = line_break
		if = {
			limit = {
				scope:story = { has_variable = body_color }
			}
			custom_tooltip = display_pet_story_cycle_details_body_color
		}
		if = {
			limit = {
				scope:story = { has_variable = eye_color }
			}
			custom_tooltip = display_pet_story_cycle_details_eyes
		}		
	}
}

PE_gui_clicked_rename_pet_button_effect = {
	is_valid = { always = yes }
	saved_scopes = { story }

	effect = {
		trigger_event = pets_expanded.0001
		toggle_pet_window_variable_effect = yes
	}
}

PE_pet_can_free_roam_trigger = {
	scope = character
	saved_scopes = {
		story
	}
	is_valid = {
		has_menagerie_trigger = yes
		scope:story ?= { NOT = { exists = var:block_free_roam_toggle } }
	}
}

PE_toggle_pet_free_roam = {
	scope = character
	saved_scopes = {
		story
	}
	effect = {
		scope:story = {
			if = {
				limit = { exists = var:allowed_to_roam_free }
				remove_variable = allowed_to_roam_free
			}
			else = {
				set_variable = allowed_to_roam_free
			}
		}
	}
}

PE_pet_breeding_can_be_blocked_trigger = {
	scope = character
	saved_scopes = {
		story
	}
	is_valid = {
		has_menagerie_trigger = yes
		scope:story ?= { NOT = { exists = var:block_breeding_toggle } }
	}
}

PE_toggle_pet_breeding = {
	scope = character
	saved_scopes = {
		story
	}
	effect = {
		scope:story = {
			if = {
				limit = { exists = var:allowed_to_breed }
				remove_variable = allowed_to_breed
			}
			else = {
				set_variable = allowed_to_breed
			}
		}
	}
}

PE_sell_pet_confirm = {
	scope = character
	saved_scopes = {
		story
	}

	effect = {
		send_interface_message = {
			type = event_pets_expanded_neutral
			title = sell_pet_interaction_notification
			add_gold = sell_pet_price_value
			end_pet_story_cycle_from_story_scope_effect = {
				STORY = scope:story
			}
		}

		check_and_close_animal_window_effect = yes
	}
}

PE_release_pet_confirm = {
	scope = character
	saved_scopes = {
		story
	}

	effect = {
		send_interface_message = {
			type = event_pets_expanded_neutral
			title = release_pet_interaction_notification
			end_pet_story_cycle_from_story_scope_effect = {
				STORY = scope:story
			}
		}

		check_and_close_animal_window_effect = yes
	}
}

PE_gui_sell_pet_clear_saved_stuff_effect = {
	effect = {
		if = {
			limit = { exists = var:selected_story_scope }
			var:selected_story_scope = {
				if = {
					limit = { exists = var:story_type }
					remove_variable = story_type
				}
			}
		}

		remove_list_variable = {
			name = story_cycles
			target = var:selected_story_scope
		}
		#remove_variable = selected_story_type
		#remove_variable = selected_story_scope
	}
}


PE_gui_display_menagerie_level_effect = {
	scope = character

	effect = {
		update_menagerie_level_effect = yes
	}
}


PE_gui_display_menagerie_level_breakdown_effect  = {
	is_valid = {
		always = yes
	}

	effect = {
		# Number of animals
		custom_description_no_bullet = { text =  pet_window_menagerie_level_tooltip_number_of_animals }
		# Animal variety
		if = {
			limit = {
				menagerie_has_ok_animal_variety_trigger = yes
			}
			custom_description_no_bullet = { text =  pet_window_menagerie_level_tooltip_animal_variety }
		}
		# Status animal(s)
		if = {
			limit = {
				menagerie_has_status_animal_trigger = yes
			}
			custom_description_no_bullet = { text =  pet_window_menagerie_level_tooltip_status_animals }
		}
		# Animal health
		if = {
			limit = {
				OR = {
					menagerie_has_great_animal_health_trigger = yes
					menagerie_has_bad_animal_health_trigger = yes
				}
			}
			custom_description_no_bullet = { text =  pet_window_menagerie_level_tooltip_animal_health }
		}
		# Animal behavior
		if = {
			limit = {
				OR = {
					menagerie_has_good_animal_behavior_trigger = yes
					menagerie_has_bad_animal_behavior_trigger = yes
				}
			}
			custom_description_no_bullet = { text =  pet_window_menagerie_level_tooltip_animal_behavior }
		}
		# Employs Keeper
		if = {
			limit = {
				any_court_position_holder = { type = keeper_of_menagerie_court_position }
			}
			custom_description_no_bullet = { text =  pet_window_menagerie_level_tooltip_employs_keeper }
		}
	}
}


PE_gui_display_menagerie_level_effects_effect  = {
	is_valid = {
		always = yes
	}

	effect = {
		if = {
			limit = {
				var:PE_menagerie_level >= PE_menagerie_level_high_value
			}
			custom_description_no_bullet = { text = PE_pet_window_menagerie_level_effects_high }
		}
		else_if = {
			limit = {
				var:PE_menagerie_level >= PE_menagerie_level_medium_value
			}
			custom_description_no_bullet = { text = PE_pet_window_menagerie_level_effects_medium }
		}
		else = {
			custom_description_no_bullet = { text = PE_pet_window_menagerie_level_effects_low }
		}
	}
}