﻿namespace = travel_danger_events

scripted_effect randomize_frostbite_bodypart_effect = { #pick a body part that gets the frostbite
	 scope:frostbite_victim = {
		 random_list = {
			1 = {
				set_variable = {
					name = frostbite_bodypart
					value = flag:upper_limb
				}
			}
			1 = {
				set_variable = {
					name = frostbite_bodypart
					value = flag:lower_limb
				}
			}
			1 = {
				set_variable = {
					name = frostbite_bodypart
					value = flag:head
				}
			}
		}
	}
}

scripted_effect change_frostbite_modifier_with_severity_effect = { #outcome of each option
	 scope:frostbite_victim = {
		if = { #death
			limit = { exists = $SEVERITY$ $SEVERITY$ > 2 }
			death = { death_reason = death_hypothermia }
		}
		else_if = { #traits: maimed, one-legged, disfigured 
			limit = { $SEVERITY$ ?= 2 }
			change_severe_frostbite_modifier_to_trait_effect = yes
			get_rival_from_frostbite_effect = yes
		}
		else_if = { #severe frostbite character modifier
			limit = { $SEVERITY$ ?= 1 }
			add_severe_frostbite_modifier_effect = yes
			get_rival_from_frostbite_effect = yes
		}
		else_if = { #keep the modifier
			limit = { exists = $SEVERITY$ $SEVERITY$ < 0 $SEVERITY$ >= -3 }
			if = {
				limit = {has_character_modifier = travel_mild_frostbite_modifier}
				custom_tooltip = travel_danger_events.1011.c.tt_mild
			}
			else_if = {
				limit = {has_character_modifier = travel_severe_frostbite_modifier}
				custom_tooltip = travel_danger_events.1011.c.tt_severe
			}
		}
		else_if = { #remove modifiers
			limit = { exists = $SEVERITY$ $SEVERITY$ < -3 }
			cure_frostbite_modifier_effect = yes
		}
	}
}

scripted_effect tooltip_changed_frostbite_effect = { #display only as a tooltip what will happen to the frostbitten character depending on option outcome
	 show_as_tooltip = {
		change_frostbite_modifier_with_severity_effect = { SEVERITY = scope:frostbite_severity_value }
	}
}

scripted_effect change_severe_frostbite_modifier_to_trait_effect = { #change modifier into trait corresponding to affected body part
	remove_character_modifier = travel_severe_frostbite_modifier
	if = {
		limit = { var:frostbite_bodypart = flag:upper_limb }
		apply_maimed_trait_and_modifier_effect = yes
	}
	else_if = {
		limit = { var:frostbite_bodypart = flag:lower_limb }
		add_trait = one_legged
	}
	else_if = {
		limit = { var:frostbite_bodypart = flag:head }
		add_trait = disfigured
	}
}

scripted_effect add_severe_frostbite_modifier_effect = { #change mild into severe modifier
	remove_character_modifier = travel_mild_frostbite_modifier
	add_character_modifier = {
		modifier = travel_severe_frostbite_modifier
		years = 10
	}
}

scripted_effect cure_frostbite_modifier_effect = { #remove the correct modifier if successful
	if = {
		limit = {has_character_modifier = travel_mild_frostbite_modifier}
		remove_character_modifier = travel_mild_frostbite_modifier
	}
	else = {
		remove_character_modifier = travel_severe_frostbite_modifier
	}
}

scripted_effect get_friend_from_frostbite_effect = {
	progress_towards_friend_effect = {
		CHARACTER = scope:frostbite_victim
		REASON = friend_treated_wounds
		OPINION = default_friend_opinion
	}
}

scripted_effect get_rival_from_frostbite_effect = { #don't trigger if frostbite is going to kill them
	progress_towards_rival_effect = {
		CHARACTER = root
		REASON = botched_my_treatment_opinion
		OPINION = default_rival_opinion
	}
}

scripted_trigger has_frostbite_already_trigger = { #to affect only characters that got this before and got worse
	exists = this.var:frostbite_bodypart
	this.var:frostbite_severity > 0
	is_ai = yes
}

scripted_trigger knows_winter_trigger = { #to find a character that shouldn't be affected by winter or know what they are doing
	OR = {
		has_trait = winter_soldier
		culture = {
			OR = {
				has_cultural_tradition = tradition_himalayan_settlers
				has_cultural_tradition = tradition_winter_warriors
			}
		}
	}
}

scripted_trigger new_frostbite_victim_trigger = { #to pick a suitable character to get the frostbite
	is_ai = yes
	age >= 5
	knows_winter_trigger = no
	NOT = {has_character_flag = cured_from_frostbite_travel_danger_1011	}
}

travel_danger_events.1011 = { #Someone from your entourage gets a frostbite
	type = character_event
	title = { #it can trigger multiple times for the same target
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:frostbite_victim.var:frostbite_severity ?= 1
				}
				desc = travel_danger_events.1011.t_twice
			}
			triggered_desc = {
				trigger = {
					scope:frostbite_victim.var:frostbite_severity ?= 2
				}
				desc = travel_danger_events.1011.t_thrice
			}
			desc = travel_danger_events.1011.t
		}
	}
	desc = { #it can trigger multiple times for the same target and affect a particular body part which can differ between characters
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:frostbite_victim = {
						has_frostbite_already_trigger = yes
					}
				}
				desc = {
					first_valid = {
						triggered_desc = {
							trigger = {
								scope:frostbite_victim.var:frostbite_bodypart ?= flag:head
								scope:frostbite_victim.var:frostbite_severity ?= 2
							}
							desc = travel_danger_events.1011.desc_head_thrice
						}
						triggered_desc = {
							trigger = {
								scope:frostbite_victim.var:frostbite_bodypart ?= flag:upper_limb
								scope:frostbite_victim.var:frostbite_severity ?= 2
							}
							desc = travel_danger_events.1011.desc_upper_limb_thrice
						}
						triggered_desc = {
							trigger = {
								scope:frostbite_victim.var:frostbite_bodypart ?= flag:lower_limb
								scope:frostbite_victim.var:frostbite_severity ?= 2
							}
							desc = travel_danger_events.1011.desc_lower_limb_thrice
						}
						triggered_desc = {
							trigger = {
								scope:frostbite_victim.var:frostbite_bodypart ?= flag:head 
							}
							desc = travel_danger_events.1011.desc_head_twice
						}
						triggered_desc = {
							trigger = {
								scope:frostbite_victim.var:frostbite_bodypart ?= flag:upper_limb 
							}
							desc = travel_danger_events.1011.desc_upper_limb_twice
						}
						triggered_desc = {
							trigger = {
								scope:frostbite_victim.var:frostbite_bodypart ?= flag:lower_limb 
							}
							desc = travel_danger_events.1011.desc_lower_limb_twice
						}
					}
				}
			}
			desc = {
				first_valid = {
					triggered_desc = {
						trigger = {
							scope:frostbite_victim.var:frostbite_bodypart ?= flag:head 
						}
						desc = travel_danger_events.1011.desc_head
					}
					triggered_desc = {
						trigger = {
							scope:frostbite_victim.var:frostbite_bodypart ?= flag:upper_limb 
						}
						desc = travel_danger_events.1011.desc_upper_limb
					}
					triggered_desc = {
						trigger = {
							scope:frostbite_victim.var:frostbite_bodypart ?= flag:lower_limb 
						}
						desc = travel_danger_events.1011.desc_lower_limb
					}
				}
			}
		}
	}
	theme = travel

	left_portrait = {
		character = root
		triggered_animation = {
			trigger = { has_trait = callous }
			animation = schadenfreude
		}
		animation = worry
	}

	right_portrait = {
		character = scope:frostbite_victim
		animation = grief
	}

	lower_center_portrait = {
		trigger = { exists = scope:court_physician }
		character = scope:court_physician
	}

	cooldown = { years = 5 }

	trigger = {
		is_location_valid_for_travel_event_on_land = yes
		location = {
			OR = {
				has_province_modifier = winter_normal_modifier
				has_province_modifier = winter_harsh_modifier
			}
		}
		current_travel_plan = {
   			any_entourage_character = {
   				count >= 1 
   				new_frostbite_victim_trigger = yes
   			}
   		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = 5
			location = { has_province_modifier = winter_harsh_modifier }
		}
	}

	immediate = {
		mp_delay_travel_plan = { DAYS = 90 }
		current_travel_plan = {
			if = { #choose the same character again if you already had the event
				limit = {
					any_entourage_character = {
						has_frostbite_already_trigger = yes
					}
				}
				random_entourage_character = {
					limit = {
						has_frostbite_already_trigger = yes
					}
					save_scope_as = frostbite_victim
				}
			}
			else = { #pick someone random
				random_entourage_character = {
					limit = {
						new_frostbite_victim_trigger = yes
	   				}
					save_scope_as = frostbite_victim
				}
			}
		}
		traveler_danger_xp_effect = {
			MIN = 3
			MAX = 6
		}
		if = { #look for any insignificant artifact made from wood you have 
			limit = {
				has_any_artifact = yes
				any_character_artifact = {
					NOT = { has_variable = historical_unique_artifact }
					OR = {
						has_artifact_feature_group = generic_material_wood
						has_artifact_feature_group = wood_decoration
						has_artifact_feature_group = shaft_wood
						artifact_type = book
						artifact_type = bow
					}

				}
			}
			random_character_artifact = { #pick one artifact to be burned for warmth
				limit = {
					NOT = { has_variable = historical_unique_artifact }
					OR = {
						has_artifact_feature_group = generic_material_wood
						has_artifact_feature_group = wood_decoration
						has_artifact_feature_group = shaft_wood
						artifact_type = book
						artifact_type = bow
					}
				}
				save_scope_as = to_be_burned
			}
		}
		hidden_effect = {
			if = { #pick a body part to frostbite
				limit = { NOT = { exists = scope:frostbite_victim.var:frostbite_bodypart } }
				randomize_frostbite_bodypart_effect = yes
			}
			if = { #set initial severity and modifier
				limit = { NOT = { exists = scope:frostbite_victim.var:frostbite_severity } }
				scope:frostbite_victim = {
					set_variable = {
						name = frostbite_severity
						value = 0
					}
					add_character_modifier = {
						modifier = travel_mild_frostbite_modifier
						years = 10
					}
				}
			}
		}
		if = { #add a physician if you have one 
			limit = { 
				any_court_position_holder = {
					type = court_physician_court_position
					is_physically_able_ai_adult = yes
					is_travel_entourage_character = yes
					NOT = { this = scope:frostbite_victim }
				}
			}
			save_court_physician_as_effect = { SCOPE_NAME = court_physician }
		}
	}


	option = { #let it burn!
		name = { #new name when event triggers for the same character again
			trigger = { scope:frostbite_victim.var:frostbite_treatment ?= flag:frostbite_treatment_burn_failure }
			text = travel_danger_events.1011.a_frostbite_treatment_burn_failure
		}
		name = {
			trigger = { NOT = { scope:frostbite_victim.var:frostbite_treatment ?= flag:frostbite_treatment_burn_failure	} }
			text = travel_danger_events.1011.a
		}
		trigger = { #only if you have a flamable artifact
			exists = scope:to_be_burned
		}
		current_travel_plan = {
   			delay_travel_plan = { days = 2 }
        }
		get_friend_from_frostbite_effect = yes #get friendly regardless of the outcome, because you spent quality time by the fire
		random_list = {
			60 = { #fire cured the frostbite
				desc = travel_danger_events.1011.a.success
				modifier = {
					add = {
						value = scope:to_be_burned.artifact_wealth_quality_average_value
						multiply = 2
					}
				}
				modifier = {
					factor = 2
					knows_winter_trigger = yes
				}
				scope:frostbite_victim = {
					change_variable = {
						name = frostbite_severity
						add = -6
					}
				}
				save_temporary_scope_value_as = {
					name = frostbite_severity_value
					value = { value = scope:frostbite_victim.var:frostbite_severity add = -6 }
				}
				tooltip_changed_frostbite_effect = yes
				hidden_effect = {
					send_interface_toast = {
						title = travel_danger_events.1011.a.success
						left_icon = scope:frostbite_victim
						change_frostbite_modifier_with_severity_effect = { SEVERITY = var:frostbite_severity }
					}
				}
			}
			40 = { #it neither helped nor made it worse
				desc = travel_danger_events.1011.a.failure
				scope:frostbite_victim = {
					set_variable = {
						name = frostbite_treatment
						value = flag:frostbite_treatment_burn_failure
					}
					change_variable = {
						name = frostbite_severity
						add = -3
					}
				}
				save_temporary_scope_value_as = {
					name = frostbite_severity_value
					value = { value = scope:frostbite_victim.var:frostbite_severity add = -3 }
				}
				tooltip_changed_frostbite_effect = yes
				hidden_effect = {
					send_interface_toast = {
						title = travel_danger_events.1011.a.failure
						left_icon = scope:frostbite_victim
						change_frostbite_modifier_with_severity_effect = { SEVERITY = var:frostbite_severity }
					}
				}
			}
		}
		destroy_artifact = scope:to_be_burned #this has to be after the random list, so values from the artifact can be used inside the list
		stress_impact = {
			compassionate = minor_stress_impact_loss
			paranoid = minor_stress_impact_gain
			impatient = minor_stress_impact_gain
			greedy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				has_trait = paranoid
			}
			modifier = {
				add = -25
				has_trait = impatient
			}
			modifier = {
				add = -25
				has_trait = greedy
			}
		}
	}

	option = { #your physician should take a look at the frostbite
		name = { #new name when physician is the right person to do it
			trigger = { scope:court_physician ?= { knows_winter_trigger = yes } }
			text = travel_danger_events.1011.b_physician_knows_winter
		}
		name = { #new name when event triggers for the same character again
			trigger = { scope:frostbite_victim.var:frostbite_treatment ?= flag:frostbite_treatment_physician_failure }
			text = travel_danger_events.1011.b_frostbite_treatment_physician_failure
		}
		name = {
			trigger = { NOT = {	scope:frostbite_victim.var:frostbite_treatment ?= flag:frostbite_treatment_physician_failure }	}
			text = travel_danger_events.1011.b_physician
		}
		trigger = { exists = scope:court_physician }
		current_travel_plan = {
   			delay_travel_plan = { days = 14 }
        }
		random_list = {
			50 = { #successful treatment
				desc = travel_danger_events.1011.b_physician_success
				modifier = {
					add = { value = scope:court_physician.learning multiply = 2 }
				}
				modifier = {
					factor = 2
					scope:court_physician = { knows_winter_trigger = yes }
				}
				scope:frostbite_victim = {
					change_variable = {
						name = frostbite_severity
						add = -6
					}
				}
				save_temporary_scope_value_as = {
					name = frostbite_severity_value
					value = { value = scope:frostbite_victim.var:frostbite_severity add = -6 }
				}
				tooltip_changed_frostbite_effect = yes
				hidden_effect = {
					send_interface_toast = {
						title = travel_danger_events.1011.b_physician_success
						left_icon = scope:frostbite_victim
						change_frostbite_modifier_with_severity_effect = { SEVERITY = var:frostbite_severity }
					}
				}
			}
			50 = { #failed treatment
				desc = travel_danger_events.1011.b_physician_failure
				scope:frostbite_victim = {
					set_variable = {
						name = frostbite_treatment
						value = flag:frostbite_treatment_physician_failure
					}
					change_variable = {
						name = frostbite_severity
						add = 1
					}
				}
				save_temporary_scope_value_as = {
					name = frostbite_severity_value
					value = { value = scope:frostbite_victim.var:frostbite_severity add = 1 }
				}
				tooltip_changed_frostbite_effect = yes
				hidden_effect = {
					send_interface_toast = {
						title = travel_danger_events.1011.b_physician_failure
						left_icon = scope:frostbite_victim
						change_frostbite_modifier_with_severity_effect = { SEVERITY = var:frostbite_severity }
					}
				}
			}
		}
		stress_impact = {
			compassionate = minor_stress_impact_loss
			impatient = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			modifier = {
				add = scope:court_physician.learning
			}
			modifier = {
				add = -10
				has_trait = impatient
			}
		}
	}

	option = { #You will cure the frostbite, hopefully
		name = { #new name when you are the right person to do it
			trigger = { knows_winter_trigger = yes }
			text = travel_danger_events.1011.b_root_knows_winter
		}
		name = { #new name when event triggers for the same character again
			trigger = { scope:frostbite_victim.var:frostbite_treatment ?= flag:frostbite_treatment_root_failure }
			text = travel_danger_events.1011.b_frostbite_treatment_root_failure
		}
		name = {
			trigger = { 
				NOT = {
					scope:frostbite_victim.var:frostbite_treatment ?= flag:frostbite_treatment_root_success
					scope:frostbite_victim.var:frostbite_treatment ?= flag:frostbite_treatment_root_failure
				}
			}
			text = travel_danger_events.1011.b
		}
		current_travel_plan = {
   			delay_travel_plan = { days = 14 }
        }
		random_list = {
			50 = { #successful treatment
				desc = travel_danger_events.1011.b.success
				modifier = {
					add = { value = root.learning multiply = 2 }
				}
				modifier = {
					factor = 2
					knows_winter_trigger = yes
				}
				scope:frostbite_victim = {
					set_variable = {
						name = frostbite_treatment
						value = flag:frostbite_treatment_root_success
					}
					change_variable = {
						name = frostbite_severity
						add = -6
					}
				}
				save_temporary_scope_value_as = {
					name = frostbite_severity_value
					value = { value = scope:frostbite_victim.var:frostbite_severity add = -6 }
				}
				tooltip_changed_frostbite_effect = yes
				traveler_danger_xp_effect = {
					MIN = 3
					MAX = 6
				}
				hidden_effect = {
					send_interface_toast = {
						title = travel_danger_events.1011.b.success
						left_icon = scope:frostbite_victim
						change_frostbite_modifier_with_severity_effect = { SEVERITY = var:frostbite_severity }
					}
				}
			}
			50 = { #failed treatment
				desc = travel_danger_events.1011.b.failure
				scope:frostbite_victim = {
					set_variable = {
						name = frostbite_treatment
						value = flag:frostbite_treatment_root_failure
					}
					change_variable = {
						name = frostbite_severity
						add = 1
					}
				}
				save_temporary_scope_value_as = {
					name = frostbite_severity_value
					value = { value = scope:frostbite_victim.var:frostbite_severity add = 1 }
				}
				tooltip_changed_frostbite_effect = yes
				hidden_effect = {
					send_interface_toast = {
						title = travel_danger_events.1011.b.failure
						left_icon = scope:frostbite_victim
						change_frostbite_modifier_with_severity_effect = { SEVERITY = var:frostbite_severity }
					}
				}
			}
		}
		stress_impact = {
			brave = minor_stress_loss
			craven = minor_stress_gain
			impatient = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			modifier = {
				add = 10
				has_trait = brave
			}
			modifier = {
				add = -10
				has_trait = craven
			}
			modifier = {
				add = -10
				has_trait = impatient
			}
			modifier = {
				add = root.learning
			}
		}
	}

	option = { #You don't have time for that
		name = { #new name when event triggers for the same character again and it worked
			trigger = { scope:frostbite_victim.var:frostbite_treatment ?= flag:frostbite_treatment_none_success }
			text = travel_danger_events.1011.c_frostbite_treatment_none_success
		}
		name = { #new name when event triggers for the same character again and it failed
			trigger = { scope:frostbite_victim.var:frostbite_treatment ?= flag:frostbite_treatment_none_failure }
			text = travel_danger_events.1011.c_frostbite_treatment_none_failure
		}
		name = {
			trigger = { 
				NOT = { 
					scope:frostbite_victim.var:frostbite_treatment ?= flag:frostbite_treatment_none_success
					scope:frostbite_victim.var:frostbite_treatment ?= flag:frostbite_treatment_none_failure
				}
			}
			text = travel_danger_events.1011.c
		}
		trait = winter_soldier
		scope:frostbite_victim = {
			traveler_danger_xp_effect = {
				MIN = 3
				MAX = 6
			}
		}
		random_list = {
			50 = { 
				desc = travel_danger_events.1011.c.success
				scope:frostbite_victim = {
					set_variable = {
						name = frostbite_treatment
						value = flag:frostbite_treatment_none_success
					}
					change_variable = {
						name = frostbite_severity
						add = -3
					}
					save_temporary_scope_value_as = {
						name = frostbite_severity_value
						value = { value = scope:frostbite_victim.var:frostbite_severity add = -3 }
					}
				}
				tooltip_changed_frostbite_effect = yes
				hidden_effect = {
					send_interface_toast = {
						title = travel_danger_events.1011.c.success
						left_icon = scope:frostbite_victim
						change_frostbite_modifier_with_severity_effect = { SEVERITY = var:frostbite_severity }
					}
				}
			}
			50 = { 
				desc = travel_danger_events.1011.c.failure
				modifier = {
					factor = 0
					knows_winter_trigger = yes
				}
				scope:frostbite_victim = {
					set_variable = {
						name = frostbite_treatment
						value = flag:frostbite_treatment_none_failure
					}
					change_variable = {
						name = frostbite_severity
						add = 1
					}
				}
				save_temporary_scope_value_as = {
					name = frostbite_severity_value
					value = { value = scope:frostbite_victim.var:frostbite_severity add = 1 }
				}
				tooltip_changed_frostbite_effect = yes
				hidden_effect = {
					send_interface_toast = {
						title = travel_danger_events.1011.c.failure
						left_icon = scope:frostbite_victim
						change_frostbite_modifier_with_severity_effect = { SEVERITY = var:frostbite_severity }
					}
				}
			}
		}
		stress_impact = {
			impatient = minor_stress_impact_loss
			sadistic = minor_stress_impact_loss
			compassionate = minor_stress_impact_gain
		}
		ai_chance = {
			base = 1
			modifier = {
				add = 10
				has_trait = impatient
			}
			modifier = {
				add = -10
				has_trait = compassionate
			}
		}
	}

	after = {
		mp_resume_travel_plan = yes
		if = { #clean up the variables if cured and flag the character to be unable to be picked again
			limit = { exists = scope:frostbite_victim.var:frostbite_severity scope:frostbite_victim.var:frostbite_severity < 0 }
			scope:frostbite_victim = {
				remove_variable = frostbite_severity
				remove_variable = frostbite_treatment
				remove_variable = frostbite_bodypart
				add_character_flag = cured_from_frostbite_travel_danger_1011
			}
		}
	}
}

scripted_effect touched_poisonous_plant_effect = {
	random_list = {
		50 = {
			show_chance = no
			desc = travel_danger_events.1012.touched_poisonous_plant
			send_interface_toast = { #grant the modifier to both characters
				title = travel_danger_events.1012.touched_poisonous_plant
				left_icon = scope:poisonous_plant_eater
				add_character_modifier = {
					modifier = travel_touched_poisonous_plant_modifier
					years = 5
				}
				scope:poisonous_plant_eater = {
					add_character_modifier = {
						modifier = travel_touched_poisonous_plant_modifier
						years = 5
					}
				}
			}
		}
		50 = {
			show_chance = no
			modifier = { #use their learning skill, maybe they know what they're doing?
				add = scope:poisonous_plant_eater.learning
			}
			modifier = { #increase chance if you know plants
				add = 100
				increase_good_plant_effect_trigger = yes
			}
			desc = travel_danger_events.1012.regular_plant
			send_interface_toast = { #grant the xp to root only
				title = travel_danger_events.1012.regular_plant
				left_icon = scope:poisonous_plant_eater
				add_learning_lifestyle_xp = medium_lifestyle_xp
			}
		}
	}
}

scripted_effect ate_poisonous_plant_effect = {
	random_list = {
		50 = {
			show_chance = no
			desc = travel_danger_events.1012.ate_poisonous_plant
			root = {
				send_interface_toast = {
					title = travel_danger_events.1012.ate_poisonous_plant
					left_icon = scope:poisonous_plant_eater
					$PLANT_EATER$ = { #grant the modifier to the person that ate it
						add_character_modifier = {
							modifier = travel_ate_poisonous_plant_modifier
							years = 5
						}
					}
				}
			}
		}
		50 = {
			show_chance = no
			modifier = { #maybe you know what you're doing?
				add = $PLANT_EATER$.learning
			}
			desc = travel_danger_events.1012.regular_plant
			root = {
				send_interface_toast = { #grant the xp to the root
					title = travel_danger_events.1012.regular_plant
					left_icon = scope:poisonous_plant_eater
					add_learning_lifestyle_xp = medium_lifestyle_xp
				}
			}
		}
		1 = {
			show_chance = no
			modifier = { #increase chance if character eating it know plants
				add = 200
				$PLANT_EATER$ = { increase_good_plant_effect_trigger = yes }
			}
			desc = travel_danger_events.1012.ate_delicious_plant
			root = {
				send_interface_toast = {
					title = travel_danger_events.1012.ate_delicious_plant
					left_icon = scope:poisonous_plant_eater
					$PLANT_EATER$ = { #grant the modifier to the person that ate it
						add_character_modifier = {
							modifier = travel_good_poisonous_plant_modifier
							years = 5
						}
					}
				}
			}
		}
	}
	traveler_danger_xp_effect = {
		MIN = 3
		MAX = 6
	}
}

scripted_trigger poisonous_plant_eater_trigger = {
	NOT = { this = root }
	NOT = { has_court_position = food_taster_court_position }
	NOT = { has_character_flag = had_travel_danger_1012_twice }
	is_available_travelling = yes
	is_ai = yes
	NOT = { has_trait = lifestyle_gardener }
	NOT = { has_trait = lifestyle_herbalist }
	age > 3 #they have to be able to talk
	learning < average_skill_rating
}

scripted_trigger knows_about_plants_trigger = { #you know your plants
	OR = {
		has_trait = lifestyle_herbalist
		has_trait = lifestyle_gardener
		has_trait = lifestyle_physician
		has_trait = jungle_stalker
		has_trait = forest_fighter
		has_trait = logistician
		has_trait = witch
		learning >= high_skill_rating
	}
}

scripted_trigger increase_good_plant_effect_trigger = { #you know your plants
	OR = { 
		root = { knows_about_plants_trigger = yes }
		scope:poisonous_plant_eater = { knows_about_plants_trigger = yes }
		exists = scope:food_taster
	}
}

travel_danger_events.1012 = { #Someone from you entourage finds a plant
	type = character_event
	title = travel_danger_events.1012.t
	
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:poisonous_plant_eater ?= { has_character_flag = had_travel_danger_1012_once } }
				desc = travel_danger_events.1012.desc_again
			}
			triggered_desc = {
				trigger = { exists = scope:food_taster }
				desc = travel_danger_events.1012.desc_food_taster
			}
			desc = travel_danger_events.1012.desc_unknown
		}
	}
	
	theme = travel_danger

	left_portrait = {
		character = root
		animation = thinking
	}

	right_portrait = {
		character = scope:poisonous_plant_eater
		animation = happiness
	}

	lower_center_portrait = {
		trigger = { #don't show the taster if it's the same person trying to eat again, desc doesn't refer to them at all
			exists = scope:food_taster 
			NOT = { scope:poisonous_plant_eater ?= { has_character_flag = had_travel_danger_1012_once } }
		}
		character = scope:food_taster
	}

	cooldown = { years = 5 }

	trigger = {
		static_group_filter = {
			group = travel_danger_events.1012
			match = 0.25
		}
		is_available_travelling_adult = yes
		current_travel_plan = {
			any_entourage_character = { #check for anyone that could pick up a plant
				count >= 1
				poisonous_plant_eater_trigger = yes
			}
		}
		is_location_valid_for_travel_event_on_land = yes #you wouldn't find a shrub on a ship, would you?
		location = { #same with the desert
			NOT = {
				travel_danger_type = {
					travel_plan = root.current_travel_plan
					terrain = desert
				}
				travel_danger_type = {
					travel_plan = root.current_travel_plan
					terrain = desert_mountains
				}
			}
		}
	}

	weight_multiplier = {
		base = 1
		modifier = { #kids always get into troubles by trying to eat everything, amrite?
			add = 10
			any_heir = {
				is_adult = no
			}
		}
	}

	immediate = {
		mp_delay_travel_plan = { DAYS = 90 }
		current_travel_plan = {
			ordered_entourage_character = {
				limit = { poisonous_plant_eater_trigger = yes }
				order_by = { #search for the biggest dum-dum
					value = {
						value = learning
						multiply = -1
					}
					if = { #put heirs at the top to raise the stakes
						limit = { is_heir_of = root }
						add = 5
					}
					if = { #ensure that if there is a previous character they are picked again
						limit = { has_character_flag = had_travel_danger_1012_once }
						add = 100
					}
				}
				save_scope_as = poisonous_plant_eater
			}
		}

		if = { #find a food taster for flavor
            limit = {
                employs_court_position = food_taster_court_position
                current_travel_plan = {
					any_entourage_character = {
						has_court_position = food_taster_court_position
						employer = root
		                is_available_travelling_ai_adult = yes
		                NOT = { this = scope:poisonous_plant_eater }
                	}
                }
            }
            current_travel_plan = {
				random_entourage_character = {
	                limit = {
	                	has_court_position = food_taster_court_position
	                	employer = root
	                    is_available_travelling_ai_adult = yes
	                	NOT = { this = scope:poisonous_plant_eater }
	                }
	                save_scope_as = food_taster
	            }
		    }
        }
	}

	option = { #stop them
		name = {
			trigger = { scope:poisonous_plant_eater ?= { has_character_flag = had_travel_danger_1012_once } }
			text = travel_danger_events.1012.a_again
		}
		name = {
			trigger = { scope:poisonous_plant_eater ?= { NOT = { has_character_flag = had_travel_danger_1012_once } } }
			text = travel_danger_events.1012.a
		}
		flavor = travel_danger_events.1012.a.tt
		touched_poisonous_plant_effect = yes
		stress_impact = {
			paranoid = medium_stress_impact_loss
			compassionate = minor_stress_impact_loss
			cynical = minor_stress_impact_gain
		}
		ai_chance = {
			base = 1
			modifier = {
				add = 10
				has_trait = paranoid
			}
			modifier = {
				add = 10
				has_trait = compassionate
			}
			modifier = {
				add = -10
				has_trait = cynical
			}
		}
	}

	option = { #let them eat it
		name = travel_danger_events.1012.b
		ate_poisonous_plant_effect = { PLANT_EATER = scope:poisonous_plant_eater }
		stress_impact = {
			cynical = minor_stress_impact_loss
			paranoid = minor_stress_impact_gain
		}
		ai_chance = {
			base = 1
			modifier = {
				add = 5
				has_trait = cynical
			}
			modifier = {
				add = -5
				has_trait = paranoid
			}
		}
	}

	option = { #eat it yourself
		name = travel_danger_events.1012.c
		trigger = {
			OR = {
				has_trait = comfort_eater
				has_trait = arbitrary
				has_trait = gluttonous
			}
		}
		flavor = travel_danger_events.1012.c.tt
		ate_poisonous_plant_effect = { PLANT_EATER = root }
		stress_impact = {
			comfort_eater = minor_stress_impact_loss
			arbitrary = minor_stress_impact_loss
			gluttonous = minor_stress_impact_loss
			paranoid = medium_stress_impact_gain
			content = minor_stress_impact_gain
		}
		ai_chance = {
			base = 1
			modifier = {
				add = 10
				OR = {
					has_trait = comfort_eater
					has_trait = arbitrary
					has_trait = gluttonous
				}
			}
			modifier = {
				add = -10
				has_trait = paranoid
			}
			modifier = {
				add = -10
				has_trait = content
			}
		}
	}

	after = {
		mp_resume_travel_plan = yes
		if = {
			limit = { scope:poisonous_plant_eater = { has_character_flag = had_travel_danger_1012_once } }
			scope:poisonous_plant_eater = {
				remove_character_flag = had_travel_danger_1012_once
				add_character_flag = had_travel_danger_1012_twice #the character will never be picked again for this event
			}
		}
		else = {
			scope:poisonous_plant_eater = {
				add_character_flag = had_travel_danger_1012_once
			}
		}
	}
}

scripted_effect runaway_found_efect = {
	scope:runaway_character = {
		custom_tooltip = travel_danger_events.1013.runaway_return
		root.location = { save_scope_as = relationship_reason_province }
		progress_towards_rival_effect = {
			CHARACTER = root
			REASON = intrusive_liege_opinion
			OPINION = default_rival_opinion
		}
		clear_saved_scope = relationship_reason_province
	}
	hidden_effect = {
		if = { #learn about their lover secret
			limit = {
				scope:runaway_character.var:runaway_type ?= flag:runaway_lover
				scope:runaway_character = {
					any_secret = {
	  					secret_type = secret_lover
	   					secret_target = scope:current_location_holder
	   					NOT = { is_known_by = root }
	   				}
	   			}

   			}
			scope:runaway_character = {
				random_secret = {
					limit = {
	  					secret_type = secret_lover
	   					secret_target = scope:current_location_holder
	   					NOT = { is_known_by = root }
   					}
   					reveal_to = root
   				}
			}
		}
		scope:runaway_character = { #add them back to court and entourage
			add_to_court_and_entourage_effect = yes
		}
	}
}

scripted_effect runaway_lost_effect = {
	add_courtier = scope:runaway_character
	if = { #make sure they are knighted by the new liege
		limit = { 
			scope:runaway_character.var:runaway_type ?= flag:runaway_knight
			scope:runaway_character ?= { is_potential_knight = yes }
		}
		scope:runaway_character = { set_knight_status = allow }
	}
	if = { #add the modifier to prevent the child from being recruit back right away
		limit = { scope:runaway_character.var:runaway_type ?= flag:runaway_child }
		scope:runaway_character = {
			add_character_modifier = {
				modifier = lust_for_adventure
				years = 10
			}
		}
	}
}

scripted_trigger valid_runaway_character_trigger = {
	save_temporary_scope_as = temp_runaway
	NOT = { scope:temp_runaway = root }
	is_ai = yes
	is_available_travelling = yes
	is_landed = no
	has_been_promised_grand_wedding = no
	OR  = {						
		any_relation = { type = lover scope:temp_runaway = root.location.county.holder }
		any_secret = {
			secret_type = secret_lover 
			secret_target = root.location.county.holder 
			NOT = { is_known_by = root }
		}
		any_relation = { type = rival scope:temp_runaway = root }
		AND = {
			is_knight = yes
			NOR = { 
				has_trait = content
				has_trait = craven 
				has_trait = lazy
			}
			root.location.county.holder = { is_at_war = yes }
		}
		is_adult = no
	}
}

travel_danger_events.1013 = { #entourage character runs away from you
	type = character_event
	title = travel_danger_events.1013.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:runaway_character.var:runaway_type ?= flag:runaway_rival }
				desc = travel_danger_events.1013.desc_rival
			}
			triggered_desc = {
				trigger = { scope:runaway_character.var:runaway_type ?= flag:runaway_lover }
				desc = travel_danger_events.1013.desc_lover
			}
			triggered_desc = {
				trigger = { scope:runaway_character.var:runaway_type ?= flag:runaway_knight }
				desc = travel_danger_events.1013.desc_knight
			}
			triggered_desc = {
				trigger = { scope:runaway_character.var:runaway_type ?= flag:runaway_child }
				desc = travel_danger_events.1013.desc_child
			}
			desc = travel_danger_events.1013.desc
		}
	}
	
	theme = travel_danger

	left_portrait = {
		character = root
		triggered_animation = {
			trigger = { scope:runaway_character.var:runaway_type = flag:runaway_rival }
			animation = schadenfreude
		}
		animation = worry
	}

	right_portrait = {
		character = scope:runaway_character
		animation = schadenfreude
	}

	cooldown = { years = 5 }

	trigger = {
		is_location_valid_for_travel_event_on_land = yes
		is_landed = yes
		current_travel_plan ?= {
			any_entourage_character = {
				valid_runaway_character_trigger = yes
			}
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = 10
			current_travel_plan ?= {
				any_entourage_character = {
					is_knight = yes
				}
			}
			root.location.county.holder = { is_at_war = yes }
		}
	}

	immediate = {
		mp_pause_travel_plan = yes
		root.location.county.holder = { save_scope_as = current_location_holder }
		current_travel_plan = {
			random_entourage_character = {
				limit = {
					valid_runaway_character_trigger = yes
				}
				save_scope_as = runaway_character
				if = {
					limit = {
						OR = {
							any_relation = { type = lover this = scope:current_location_holder }
							any_secret = { 
								secret_type = secret_lover 
								secret_target = scope:current_location_holder 
								NOT = { is_known_by = root }
							}
						}
					}
					set_variable = {
						name = runaway_type
						value = flag:runaway_lover
					}
				}
				else_if = {
					limit = {
						is_knight = yes
						NOR = { 
							has_trait = content
							has_trait = craven 
							has_trait = lazy
						}
						scope:current_location_holder = { is_at_war = yes }
					}
					set_variable = {
						name = runaway_type
						value = flag:runaway_knight
					}
				}
				else_if = {
					limit = {
						any_relation = { type = rival this = root }
					}
					set_variable = {
						name = runaway_type
						value = flag:runaway_rival
					}
				}
				else = {
					set_variable = {
						name = runaway_type
						value = flag:runaway_child
					}
				}		
			}
			if = {
				limit = {
					any_entourage_character = {
						NOT = { this = scope:runaway_character }
						primary_title ?= {
							is_mercenary_company = yes
						}
					}
				}
				random_entourage_character = {
					limit = {
						NOT = { this = scope:runaway_character }
						primary_title ?= {
							is_mercenary_company = yes
						}
					}
					save_scope_as = mercenary_captain
				}
			}
		}
		hidden_effect = {
			scope:runaway_character = {
				move_to_pool = yes
			}
			current_travel_plan = {
				remove_character = scope:runaway_character
			}
		}
	}


	option = { #Send a searching party
		name = travel_danger_events.1013.a
		current_travel_plan = { delay_travel_plan = { days = 7 } }
		remove_short_term_gold = minor_gold_value
		random_list = {
			1 = {
				show_chance = no
				desc = travel_danger_events.1013.success
				modifier = {
					add = 10
					exists = scope:mercenary_captain
				}
				send_interface_toast = {
					title = travel_danger_events.1013.success
					left_icon = scope:runaway_character
					runaway_found_efect = yes
				}
			}
			1 = {
				show_chance = no
				desc = travel_danger_events.1013.failure
				send_interface_toast = {
					title = travel_danger_events.1013.failure
					left_icon = scope:runaway_character
				}
				hidden_effect = {
					scope:current_location_holder = {
						send_interface_toast = {
							title = travel_danger_events.1013.runaway_joins
							left_icon = scope:runaway_character
							runaway_lost_effect = yes
						}
					}
				}
			}
		}
		stress_impact = {
			compassionate = minor_stress_impact_loss
			impatient = minor_stress_impact_gain
			greedy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 1
			modifier = {
				short_term_gold < minor_gold_value
				factor = 0
			}
			modifier = {
				add = 10
				exists = scope:mercenary_captain
			}
			modifier = {
				add = -10
				has_trait = impatient
			}
			modifier = {
				add = -10
				has_trait = greedy
			}
		}
	}

	option = { #I'll find them myself
		name = travel_danger_events.1013.b
		current_travel_plan = { delay_travel_plan = { days = 14 } }
		add_prestige = miniscule_prestige_loss
		duel = {
			skills = { intrigue prowess }
			target = scope:runaway_character
			50 = {
				show_chance = no
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				modifier = { #success if you would be able to recruit them back to court anyway
					add = 100
					can_recruit_character_to_court_trigger = {
						RECRUITER = root
						RECRUITEE = scope:runaway_character
					}
				}
				desc = travel_danger_events.1013.success_root
				send_interface_toast = {
					title = travel_danger_events.1013.success_root
					left_icon = scope:runaway_character
					runaway_found_efect = yes
				}
			}
			50 = {
				show_chance = no
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = travel_danger_events.1013.failure_root
				send_interface_toast = {
					title = travel_danger_events.1013.failure_root
					left_icon = scope:runaway_character
					show_as_tooltip = { add_trait = ill }
				}
				contract_disease_effect = { DISEASE = ill TREATMENT_EVENT = yes }
				hidden_effect = {
					scope:current_location_holder = {
						send_interface_toast = {
							title = travel_danger_events.1013.runaway_joins
							left_icon = scope:runaway_character
							runaway_lost_effect = yes
						}
					}
				}
			}
		}
		stress_impact = {
			compassionate = minor_stress_impact_loss
			impatient = minor_stress_impact_gain
			craven = minor_stress_impact_gain
			callous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 1
			modifier = {
				add = -10
				OR = {
					has_trait = impatient
					has_trait = craven
					has_trait = callous
				}
			}
		}
	}

	option = { #I don't care
		name = travel_danger_events.1013.c
		add_piety = minor_piety_loss
		hidden_effect = {
			scope:current_location_holder = {
				send_interface_toast = {
					title = travel_danger_events.1013.runaway_joins
					left_icon = scope:runaway_character
					runaway_lost_effect = yes
				}
			}
		}
		stress_impact = {
			callous = minor_stress_impact_loss
			compassionate = minor_stress_impact_gain
		}
		ai_chance = {
			base = 0
			modifier = {
				add = 100
				scope:runaway_character.var:runaway_type = flag:runaway_rival
			}
			modifier = {
				add = 1
				has_trait = callous
			}
		}
	}

	after = {
		mp_resume_travel_plan = yes
		scope:runaway_character = {
			remove_variable = runaway_type
		}
	}
}