﻿#Effects used in hunt events


#####################################################################
# EFFECT LIST
#####################################################################
# !!! Remember to add all new effects with a short description here !!!
#

#select_root_vegetable_effect - scripted loc, gives you the name of a regionally appropriate vegetable
#tour_generic_arrival_effect - Generic effects that happen when you arrive at a vassal's holding, stress impacts
#tour_distribute_control - Decides how much control to give to counties within a stop_host's domain
#tour_monthly_pulse_effect - Fires on the monthly pulse for all phases

######################################################################
# EFFECTS
######################################################################


#Used to find a local animal to hunt
#Note: Don't add more here without also revisiting artifact creation for Skulls and hides.
select_root_vegetable_effect = {
	hidden_effect = {
		if = {
			limit = {
				NOT = { exists = var:root_vegetable }
			}
			random_list = {
				10 = {
					# they're everywhere
					set_variable = {
						name = root_vegetable
						value = flag:onion
					}
				}
				20 = {
					trigger = { province_has_vegetable_carrot_trigger = yes }
					set_variable = {
						name = root_vegetable
						value = flag:carrot
					}
				}
				20 = {
					trigger = { province_has_vegetable_parsnip_trigger = yes }
					set_variable = {
						name = root_vegetable
						value = flag:parsnip
					}
				}
				20 = {
					trigger = { province_has_vegetable_turnip_trigger = yes }
					set_variable = {
						name = root_vegetable
						value = flag:turnip
					}
				}
				20 = {
					trigger = { province_has_vegetable_yams_trigger = yes }
					set_variable = {
						name = root_vegetable
						value = flag:yam
					}
				}
				20 = {
					trigger = { province_has_vegetable_kokoro_trigger = yes }
					set_variable = {
						name = root_vegetable
						value = flag:kokoro
					}
				}
				20 = {
					trigger = { province_has_vegetable_ginger_trigger = yes }
					set_variable = {
						name = root_vegetable
						value = flag:ginger
					}
				}
				20 = {
					trigger = { province_has_vegetable_taro_trigger = yes }
					set_variable = {
						name = root_vegetable
						value = flag:taro
					}
				}
				20 = {
					trigger = { province_has_vegetable_daikon_radish_trigger = yes }
					set_variable = {
						name = root_vegetable
						value = flag:daikon_radish
					}
				}
				20 = {
					trigger = { province_has_vegetable_lotus_root_trigger = yes }
					set_variable = {
						name = root_vegetable
						value = flag:lotus_root
					}
				}
				20 = {
					trigger = { province_has_vegetable_burdock_root_trigger = yes }
					set_variable = {
						name = root_vegetable
						value = flag:burdock_root
					}
				}
				20 = {
					trigger = { province_has_vegetable_arrowroot_trigger = yes }
					set_variable = {
						name = root_vegetable
						value = flag:arrowroot
					}
				}
			}
		}
	}
}

traveler_progress_point_gain_effect = {
	if = {
		limit = {
			is_alive = yes
			NOT = { exists = var:travel_provinces_traversed }
		}
		set_variable = {
			name = travel_provinces_traversed
			value = $CHANGE$
		}
	}
	else = {
		change_variable = {
			name = travel_provinces_traversed
			add = $CHANGE$
		}
	}
	save_scope_value_as = {
		name = travel_base_increase
		value = $CHANGE$
	}
	# Tooltips
	if = {
		limit = { has_trait = lifestyle_traveler }
		if = {
			limit = { scope:travel_base_increase <= 1 }
			custom_tooltip = travel_progress_towards_trait_1_tt
		}
		else_if = {
			limit = { scope:travel_base_increase = 2 }
			custom_tooltip = travel_progress_towards_trait_2_tt
		}
		else = { custom_tooltip = travel_progress_towards_trait_3_tt }
	}
	else = { custom_tooltip = travel_progress_towards_trait_0_tt }
	#Random chance of additional point to increase unpredictability
	hidden_effect = {
		random = {
			chance = 50
			change_variable = {
				name = travel_provinces_traversed
				add = $RANDOM_CHANGE$
			}
		}
	}
}

traveler_lifestyle_rank_up_check_effect = {
	if = {
		limit = {
			NOT = { has_trait = lifestyle_traveler }
		}
		hidden_effect = {
			random_list = {
				15 = {
					modifier = {
						add = 5
						exists = var:travel_provinces_traversed
						var:travel_provinces_traversed >= traveler_rank_up_10_threshold
					}
					modifier = {
						add = 5
						exists = var:travel_provinces_traversed
						var:travel_provinces_traversed >= traveler_rank_up_9_threshold
					}
					modifier = {
						add = 5
						exists = var:travel_provinces_traversed
						var:travel_provinces_traversed >= traveler_rank_up_8_threshold
					}
					modifier = {
						add = 5
						exists = var:travel_provinces_traversed
						var:travel_provinces_traversed >= traveler_rank_up_7_threshold
					}
					modifier = {
						add = 5
						exists = var:travel_provinces_traversed
						var:travel_provinces_traversed >= traveler_rank_up_6_threshold
					}
					modifier = {
						add = 5
						exists = var:travel_provinces_traversed
						var:travel_provinces_traversed >= traveler_rank_up_5_threshold
					}
					modifier = {
						add = 5
						exists = var:travel_provinces_traversed
						var:travel_provinces_traversed >= traveler_rank_up_4_threshold
					}
					modifier = {
						add = 5
						exists = var:travel_provinces_traversed
						var:travel_provinces_traversed >= traveler_rank_up_3_threshold
					}
					modifier = {
						add = 5
						exists = var:travel_provinces_traversed
						var:travel_provinces_traversed >= traveler_rank_up_2_threshold
					}
					modifier = {
						add = 5
						exists = var:travel_provinces_traversed
						var:travel_provinces_traversed >= traveler_rank_up_1_threshold
					}
					trigger_event = {
						id = travel_events.0050
						days = { 5 10 }
					}
				}
				85 = {}
			}
		}
	}
	else = {
		send_interface_toast = {
			title = travel_xp_gain_message
			if = {
				limit = { exists = var:travel_provinces_traversed }
				if = {
					limit = { var:travel_provinces_traversed >= traveler_rank_up_10_threshold }
					add_trait_xp = {
						trait = lifestyle_traveler
						track = travel
						value = 11
					}
				}
				else_if = {
					limit = { var:travel_provinces_traversed >= traveler_rank_up_9_threshold }
					add_trait_xp = {
						trait = lifestyle_traveler
						track = travel
						value = 10
					}
				}
				else_if = {
					limit = { var:travel_provinces_traversed >= traveler_rank_up_8_threshold }
					add_trait_xp = {
						trait = lifestyle_traveler
						track = travel
						value = 9
					}
				}
				else_if = {
					limit = { var:travel_provinces_traversed >= traveler_rank_up_7_threshold }
					add_trait_xp = {
						trait = lifestyle_traveler
						track = travel
						value = 8
					}
				}
				else_if = {
					limit = { var:travel_provinces_traversed >= traveler_rank_up_6_threshold }
					add_trait_xp = {
						trait = lifestyle_traveler
						track = travel
						value = 7
					}
				}
				else_if = {
					limit = { var:travel_provinces_traversed >= traveler_rank_up_5_threshold }
					add_trait_xp = {
						trait = lifestyle_traveler
						track = travel
						value = 6
					}
				}				
				else_if = {
					limit = { var:travel_provinces_traversed >= traveler_rank_up_4_threshold }
					add_trait_xp = {
						trait = lifestyle_traveler
						track = travel
						value = 5
					}
				}
				else_if = {
					limit = { var:travel_provinces_traversed >= traveler_rank_up_3_threshold }
					add_trait_xp = {
						trait = lifestyle_traveler
						track = travel
						value = 4
					}
				}
				else_if = {
					limit = { var:travel_provinces_traversed >= traveler_rank_up_2_threshold }
					add_trait_xp = {
						trait = lifestyle_traveler
						track = travel
						value = 3
					}
				}
				else_if = {
					limit = { var:travel_provinces_traversed >= traveler_rank_up_1_threshold }
					add_trait_xp = {
						trait = lifestyle_traveler
						track = travel
						value = 2
					}
				}
				else = {
					add_trait_xp = {
						trait = lifestyle_traveler
						track = travel
						value = 1
					}
				}
			}			
		}
	}
}

traveler_danger_xp_effect = {
	if = {
		limit = { has_trait = lifestyle_traveler }
		if = {
			limit = {
				has_perk = journey_perk
			}
			add_trait_xp = {
				trait = lifestyle_traveler
				track = danger
				value = {
					integer_range = {
						min = {
							value = $MIN$
							add = 2
						}
						max = {
							value = $MAX$
							add = 2
						}
					}
				}
			}
		}
		else = {
			add_trait_xp = {
				trait = lifestyle_traveler
				track = danger
				value = {
					integer_range = {
						min = $MIN$
						max = $MAX$
					}
				}
			}
		}
	}
}

traveler_travel_xp_effect = {
	if = {
		limit = { has_trait = lifestyle_traveler }
		if = {
			limit = {
				has_perk = journey_perk
			}
			add_trait_xp = {
				trait = lifestyle_traveler
				track = travel
				value = {
					integer_range = {
						min = {
							value = $MIN$
							add = 2
						}
						max = {
							value = $MAX$
							add = 2
						}
					}
				}
			}
		}
		else = {
			add_trait_xp = {
				trait = lifestyle_traveler
				track = travel
				value = {
					integer_range = {
						min = $MIN$
						max = $MAX$
					}
				}
			}
		}
	}
}

increase_tour_success_effect = {
	if = {
		limit = {
			scope:activity = {
				has_activity_option = {
					category = special_type
					option = tour_type_majesty
				}
			}
		}
		custom_tooltip = tour_becomes_more_majestic_tt
	}
	else_if = {
		limit = {
			scope:activity = {
				has_activity_option = {
					category = special_type
					option = tour_type_taxation
				}
			}
		}
		custom_tooltip = tour_becomes_more_avaricious_tt
	}
	else_if = {
		limit = {
			scope:activity = {
				has_activity_option = {
					category = special_type
					option = tour_type_intimidation
				}
			}
		}
		custom_tooltip = tour_becomes_more_intimidating_tt
	}
	scope:activity = {
		change_variable = {
			name = tour_success_var
			add = {
				value = $POINTS$
				multiply = 5
			}
		}
	}
}

decrease_tour_success_effect = {
	if = {
		limit = {
			scope:activity = {
				has_activity_option = {
					category = special_type
					option = tour_type_majesty
				}
			}
		}
		custom_tooltip = tour_becomes_less_majestic_tt
	}
	else_if = {
		limit = {
			scope:activity = {
				has_activity_option = {
					category = special_type
					option = tour_type_taxation
				}
			}
		}
		custom_tooltip = tour_becomes_less_avaricious_tt
	}
	else_if = {
		limit = {
			scope:activity = {
				has_activity_option = {
					category = special_type
					option = tour_type_intimidation
				}
			}
		}
		custom_tooltip = tour_becomes_less_intimidating_tt
	}
	scope:activity = {
		change_variable = {
			name = tour_success_var
			subtract = $POINTS$
		}
	}
}

tour_stop_host_effect = {
	set_variable = {
		name = stop_host
		value = scope:host.location.county.holder
	}
	var:stop_host = {
		# Remove character flag which prevents vassals to be visited from starting other activities
		if = {
			limit = { has_character_flag = being_visited_on_tour }
			remove_character_flag = being_visited_on_tour
		}
		add_to_activity_without_travel = scope:activity
		save_scope_as = stop_host_scope
		scope:host = {
			save_scope_as = visiting_liege
		}
	}
	add_to_variable_list = {
		name = tour_visited_vassals
		target = var:stop_host
	}
}

tour_generic_arrival_effect = {
	add_prestige = 50
	stress_impact = {
		base = medium_stress_impact_loss
		gregarious = minor_stress_impact_loss
		arrogant = minor_stress_impact_loss
	}
}

show_tour_option_start_effect = {
	if = {
		limit = {
			NAND = {
				OR = {
					involved_activity = {
						has_activity_option = {
							category = tour_luxuries
							option = tour_luxuries_bad
						}
					}
					involved_activity = {
						has_activity_option = {
							category = tour_luxuries
							option = tour_luxuries_normal
						}
					}
				}
				involved_activity = {
					has_activity_option = {
						category = tour_entourage
						option = tour_entourage_small
					}
				}
			}
		}
		custom_tooltip = due_to_activity_options_tt
		show_as_tooltip = {
			add_prestige = {
				value = 0
				if = {
					limit = {
						involved_activity = {
							has_activity_option = {
								category = tour_luxuries
								option = tour_luxuries_good
							}
						}
					}
					add = 30
				}
				else_if = {
					limit = {
						involved_activity = {
							has_activity_option = {
								category = tour_luxuries
								option = tour_furniture_normal
							}
						}
					}
					add = medium_prestige_gain
				}
				else_if = {
					limit = {
						involved_activity = {
							has_activity_option = {
								category = tour_luxuries
								option = tour_furniture_good
							}
						}
					}
					add = major_prestige_gain
				}
				if = {
					limit = {
						involved_activity = {
							has_activity_option = {
								category = tour_entourage
								option = tour_entourage_normal
							}
						}
					}
					add = medium_prestige_gain
				}
				else_if = {
					limit = {
						involved_activity = {
							has_activity_option = {
								category = tour_entourage
								option = tour_entourage_grand
							}
						}
					}
					add = major_prestige_gain
				}
			}
		}
	}
}

tour_distribute_control = {
	scope:activity = {
		add_activity_log_entry = {
			key = increased_control_log
			tags = { good }
			character = scope:visiting_liege
			target = scope:stop_host_scope
			show_in_conclusion = yes
			if = {
				limit = {
					$CAPITAL$ > 0
					NOR = { # Do not apply if CAPITAL and HELD_COUNTIES are the same
						$CAPITAL$ = $HELD_COUNTIES$
						$CAPITAL$ = $HELD_AND_VASSAL_COUNTIES$
					}
				}
				root.location.county = { change_county_control = $CAPITAL$ }
			}
			if = { # County titles held by your vassal and their vassals
				limit = {
					$HELD_AND_VASSAL_COUNTIES$ > 0
				}
				if = {
					limit = {
						$CAPITAL$ = $HELD_AND_VASSAL_COUNTIES$ # Apply to capital if the values are the same
					}
					root.location.county.holder = {
						every_sub_realm_county = {
							custom = every_title_held_by_vassal_and_vassals
							change_county_control = $HELD_AND_VASSAL_COUNTIES$
						}
					}
				}
				else = {
					root.location.county.holder = {
						every_sub_realm_county = {
							custom = every_title_held_by_vassal_and_vassals
							limit = {
								this != root.location.county
							}
							change_county_control = $HELD_AND_VASSAL_COUNTIES$
						}
					}
				}
			}
			else_if = { # Only apply if HELD_AND_VASSAL_COUNTIES is not applied, prevent double tooltips
				limit = {
					$HELD_COUNTIES$ > 0
				}
				if = {
					limit = {
						$CAPITAL$ = $HELD_COUNTIES$ # Apply to capital if the values are the same
					}
					root.location.county.holder = {
						every_held_title = {
							custom = every_title_held_by_vassal
							title_tier = county
							change_county_control = $HELD_COUNTIES$
						}
					}
				}
				else = {
					root.location.county.holder = {
						every_held_title = {
							custom = every_title_held_by_vassal
							limit = {
								this != root.location.county
							}
							change_county_control = $HELD_COUNTIES$
						}
					}
				}
			}
		}
	}
}

tour_monthly_pulse_effect = {
	scope:host = {
		save_scope_as = visiting_liege
	}
	scope:activity.var:stop_host = {
		save_scope_as = stop_host_scope
	}
	if = {
		limit = {
			scope:host = this
			NOT = {
				scope:activity = { exists = var:just_had_vassal_event }
			}
		}
		set_variable = {
			name = just_had_liege_event
			value = yes
			days = 3
		}
		trigger_event = {
			on_action = $ON_ACTION_POOL$_liege
		}
	}
	else_if = {
		limit = {
			scope:activity.var:stop_host = this
			NOT = {
				scope:activity = { exists = var:just_had_liege_event }
			}
		}
		set_variable = {
			name = just_had_vassal_event
			value = yes
			days = 3
		}
		trigger_event = {
			on_action = $ON_ACTION_POOL$_vassal
		}
	}
}

tour_progress_effect = {
	# Progress the activity
	if = {
		limit = {
			scope:activity = { exists = var:months_of_stop }
			scope:activity = { var:months_of_stop >= 2 }
		}
		scope:host = {
			save_scope_as = visiting_liege
			location.province_owner ?= {
				save_scope_as = stop_host_scope
				if = {
					limit = { has_character_flag = being_visited_on_tour }
					remove_character_flag = being_visited_on_tour
				}
			}
		}
		trigger_event = tour_general.0510
	}
	if = {
		limit = {
			scope:activity = { NOT = { exists = var:months_of_stop } }
		}
		scope:activity = { 
			set_variable = {
				name = months_of_stop
				value = 1
			}
		}
	}
	else = {
		scope:activity = { 
			change_variable = {
				name = months_of_stop
				add = 1
			}
		}
	}
}

play_arrival_music_effect = {
	if = {
		limit = {
			involved_activity.activity_location.culture = { has_graphical_india_culture_group_trigger = yes }
		}
		play_sound_effect = "event:/DLC/EP2/SFX/Events/Grand_Activities/Tours/ep2_event_grand_tour_set_india"
	}
	else_if = {
		limit = {
			involved_activity.activity_location.culture = { has_graphical_mena_culture_group_trigger = yes }
		}
		play_sound_effect = "event:/DLC/EP2/SFX/Events/Grand_Activities/Tours/ep2_event_grand_tour_set_mena"
	}
	else = {
		play_sound_effect = "event:/DLC/EP2/SFX/Events/Grand_Activities/Tours/ep2_event_grand_tour_set_west"
	}
	if = {
		limit = {
			$WELCOME_LEVEL$ = welcome
		}
		play_sound_effect = "event:/DLC/EP2/SFX/Events/Grand_Activities/Tours/ep2_event_grand_tour_arrival_welcome"
	}
	else_if = {
		limit = {
			$WELCOME_LEVEL$ = neutral
		}
		play_sound_effect = "event:/DLC/EP2/SFX/Events/Grand_Activities/Tours/ep2_event_grand_tour_arrival_neutral"
	}
	else_if = {
		limit = {
			$WELCOME_LEVEL$ = suspicious
		}
		play_sound_effect = "event:/DLC/EP2/SFX/Events/Grand_Activities/Tours/ep2_event_grand_tour_arrival_suspicious"
	}
}
