﻿#Events handling Abduction outcomes

# System by Petter Vilberg

namespace = abduct_outcome

##################################
# MAINTENANCE EVENTS 0000 - 0099
##################################

abduct_outcome.0001 = {

	hidden = yes

	immediate = {
		add_character_flag = { #Only resolve one abduction in the same day
			flag = is_in_event_abduct_outcome_0001
			days = 1
		}
		trigger_event = {
			on_action = abduct_setup
		}
	}
}


#################
# METHOD SELECTION EVENTS
# 1000-1999
#################

######################
# Seize Roadside
######################
abduct_outcome.1001 = {
	type = character_event
	title = abduct_outcome.1001.t
	desc = {
		desc = abduct_outcome.1001.opening
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:arrival
				}
				desc = abduct_outcome.1001.arrival
			}
			desc = abduct_outcome.1001.no_arrival
		}
		desc = abduct_outcome.1001.ending
	}
	theme = intrigue
	left_portrait = {
		character = scope:target
		animation = personality_coward
	}

	override_background = {
		trigger = { scope:target = { is_travelling = yes } }
		reference = terrain
	}

	widget = {
		gui = "event_window_widget_scheme"
		container = "custom_widgets_container"
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		save_scope_value_as = {
			name = abduct_method
			value = flag:seized_roadside
		}
		
		scope:target.capital_province ?= { save_scope_as = departure }
		if = {
			limit = {
				NOT = { exists = scope:departure }
			}
			scope:target.location ?= { save_scope_as = departure }
		}

		# Save arrival location
		if = {
			limit = { scope:target = { is_travelling = yes } }
			scope:target = {
				current_travel_plan = {
					next_destination_province = { save_scope_as = arrival }
				}
			}
		}
		else = {
			scope:owner.top_liege = {
				random_sub_realm_county = {
					limit = {
						NOR = {
							this.capital_province ?= scope:departure
							holder = scope:owner
						}
						scope:departure = {
							squared_distance = {
								target = prev
								value < 100000
							}
						}
					}
					save_scope_as = arrival
				}
			}
		}
		abduct_outcome_roll_setup_effect = yes
	}

	option = {
		name = abduct_outcome.1001.a
		remove_short_term_gold = minor_gold_value
		abduct_outcome_roll_effect = yes
		ai_chance = {
			base = 100
		}
	}

	option = {
		name = abduct_outcome.1001.b
		custom_tooltip = do_not_execute_abduct_tooltip

		scope:scheme = {
			reset_failed_scheme_effect = yes
		}

		ai_chance = {
			base = 0
		}
		stress_impact = {
			impatient = medium_stress_impact_gain
			stubborn = medium_stress_impact_gain
		}
	}
}

######################
# On the Way
######################
abduct_outcome.1002 = {
	type = character_event
	title = abduct_outcome.1002.t
	desc = abduct_outcome.1002.desc
	theme = intrigue
	left_portrait = {
		character = scope:target
		animation = personality_coward
	}
	widget = {
		gui = "event_window_widget_scheme"
		container = "custom_widgets_container"
	}

	override_background = {
		trigger = { scope:target = { is_travelling = yes } }
		reference = terrain
	}

	trigger = {
		scope:target = {
			is_travelling = yes
		}
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		save_scope_value_as = {
			name = abduct_method
			value = flag:on_the_way
		}
		abduct_outcome_roll_setup_effect = yes

		# Save travel information for loc 
		scope:target = {
			capital_province = { save_scope_as = departure }
			current_travel_plan = {
				next_destination_province = { save_scope_as = arrival }
			}
		}
	}

	option = {
		name = abduct_outcome.1002.a
		abduct_outcome_roll_effect = yes
		ai_chance = {
			base = 100
		}
	}

	option = {
		name = abduct_outcome.1001.b
		custom_tooltip = do_not_execute_abduct_tooltip

		scope:scheme = {
			reset_failed_scheme_effect = yes
		}

		ai_chance = {
			base = 0
		}
		stress_impact = {
			impatient = medium_stress_impact_gain
			stubborn = medium_stress_impact_gain
		}
	}
}

######################
# Unwelcome Guests
######################
abduct_outcome.1003 = {
	type = character_event
	title = abduct_outcome.1003.t
	desc = abduct_outcome.1003.desc
	theme = intrigue
	left_portrait = {
		character = scope:target
		animation = personality_coward
	}
	widget = {
		gui = "event_window_widget_scheme"
		container = "custom_widgets_container"
	}

	trigger = {
		scope:scheme = {
			any_scheme_agent_character = { count >= 2 }
		}
		scope:target = {
			is_pool_character = no
			is_travelling = no 
		}
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		scope:target.court_owner.capital_province.barony = {
			save_scope_as = court_location
		}
		save_scope_value_as = {
			name = abduct_method
			value = flag:unwelcome_guests
		}
		abduct_outcome_roll_setup_effect = yes
	}

	option = {
		name = abduct_outcome.1003.a
		abduct_outcome_roll_effect = yes
		ai_chance = {
			base = 100
		}
	}

	option = {
		name = abduct_outcome.1001.b
		custom_tooltip = do_not_execute_abduct_tooltip

		scope:scheme = {
			reset_failed_scheme_effect = yes
		}

		ai_chance = {
			base = 0
		}
		stress_impact = {
			impatient = medium_stress_impact_gain
			stubborn = medium_stress_impact_gain
		}
	}
}


#####################################
# SUCCESS OUTCOMES 2001 - 2999
#####################################

#######################
# Seized Roadside
#######################
abduct_outcome.2001 = {
	type = character_event
	window = scheme_successful_event
	title = abduct_outcome.1001.t
	desc = abduct_outcome.2001.desc
	theme = intrigue
	left_portrait = {
		character = scope:target
		animation = fear
	}
	widget = {
		gui = "event_window_widget_scheme"
		container = "custom_widgets_container"
	}

	trigger = {
		scope:abduct_method = flag:seized_roadside
	}

	immediate = {
		if = {
			limit = {
				exists = capital_county
			}
			capital_county = {
				save_scope_as = prison_location
			}
		}
		else_if = {
			limit = {
				exists = location.county
			}
			location.county = {
				save_scope_as = prison_location
			}
		}
		abduct_success_effect = yes
	}

	option = {
		name = abduct_outcome.2001.a
		play_music_cue = "mx_cue_prison"
		successful_abduct_outcome_event_option_effect = yes
	}
}

#######################
# On the Way
#######################
abduct_outcome.2002 = {
	type = character_event
	window = scheme_successful_event
	title = abduct_outcome.1002.t
	desc = abduct_outcome.2002.desc
	theme = intrigue
	center_portrait = {
		character = root
		animation = scheme
	}
	right_portrait = {
		character = scope:target
		animation = prisonhouse
	}
	widget = {
		gui = "event_window_widget_scheme"
		container = "custom_widgets_container"
	}

	trigger = {
		scope:abduct_method = flag:on_the_way
	}

	immediate = {
		abduct_success_effect = yes
	}

	option = {
		name = abduct_outcome.2001.a
		play_music_cue = "mx_cue_prison"
		successful_abduct_outcome_event_option_effect = yes
	}
}

#######################
# Unwelcome Guests
#######################
abduct_outcome.2003 = {
	type = character_event
	window = scheme_successful_event
	title = abduct_outcome.1003.t
	desc = abduct_outcome.2003.desc
	theme = intrigue
	left_portrait = {
		character = scope:target
		animation = fear
	}
	widget = {
		gui = "event_window_widget_scheme"
		container = "custom_widgets_container"
	}

	trigger = {
		scope:abduct_method = flag:unwelcome_guests
	}

	immediate = {
		abduct_success_effect = yes
	}

	option = {
		name = abduct_outcome.2001.a
		play_music_cue = "mx_cue_prison"
		successful_abduct_outcome_event_option_effect = yes
	}
}


#################################
# FAILURE OUTCOMES 4000 - 4999
#################################
abduct_outcome.4001 = {
	type = character_event
	window = scheme_failed_event
	title = abduct_outcome.1001.t
	desc = {
		desc = abduct_outcome.4001.opening
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:scheme_discovered
				}
				desc = abduct_outcome.4001.owner_discovered
			}
			desc = abduct_outcome.4001.owner_secret
		}
	}
	theme = intrigue
	left_portrait = {
		character = scope:target
		animation = rage
	}
	widget = {
		gui = "event_window_widget_scheme"
		container = "custom_widgets_container"
	}

	trigger = {
		scope:abduct_method = flag:seized_roadside
	}

	immediate = {
		abduct_failure_effect = yes
	}

	option = { # Abandon scheme
		name = abduct_outcome.4001.a
		scope:scheme = {
			end_scheme = yes
		}
		stress_impact = {
			stubborn = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
		}
	}

	option = { # Try again!
		name = abduct_outcome.4001.b
		play_music_cue = "mx_cue_stress"
		custom_tooltip = restart_scheme_tt

		scope:scheme = {
			reset_failed_scheme_effect = yes
		}

		ai_chance = {
			base = 10
			modifier = {
				add = 200
				has_trait = stubborn
			}
		}
	}
}

### On the Way
abduct_outcome.4002 = {
	type = character_event
	window = scheme_failed_event
	title = abduct_outcome.1001.t
	desc = {
		desc = abduct_outcome.4002.opening
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:scheme_discovered
				}
				desc = abduct_outcome.4002.owner_discovered
			}
			desc = abduct_outcome.4002.owner_secret
		}
	}
	theme = intrigue
	left_portrait = {
		character = scope:target
		animation = rage
	}
	widget = {
		gui = "event_window_widget_scheme"
		container = "custom_widgets_container"
	}

	trigger = {
		scope:abduct_method = flag:on_the_way
	}

	immediate = {
		abduct_failure_effect = yes
	}

	option = { # Abandon scheme
		name = abduct_outcome.4001.a
		scope:scheme = {
			end_scheme = yes
		}
		stress_impact = {
			stubborn = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
		}
	}

	option = { # Try again!
		name = abduct_outcome.4001.b
		play_music_cue = "mx_cue_stress"
		custom_tooltip = restart_scheme_tt

		scope:scheme = {
			reset_failed_scheme_effect = yes
		}

		ai_chance = {
			base = 10
			modifier = {
				add = 200
				has_trait = stubborn
			}
		}
	}
}

### Unwelcome Guests
abduct_outcome.4003 = {
	type = character_event
	window = scheme_failed_event
	title = abduct_outcome.1001.t
	desc = {
		desc = abduct_outcome.4003.opening
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:scheme_discovered
				}
				desc = abduct_outcome.4003.owner_discovered
			}
			desc = abduct_outcome.4003.owner_secret
		}
	}
	theme = intrigue
	left_portrait = {
		character = scope:target
		animation = rage
	}
	widget = {
		gui = "event_window_widget_scheme"
		container = "custom_widgets_container"
	}

	trigger = {
		scope:abduct_method = flag:unwelcome_guests
	}

	immediate = {
		abduct_failure_effect = yes
	}

	option = { # Abandon scheme
		name = abduct_outcome.4001.a
		scope:scheme = {
			end_scheme = yes
		}
		stress_impact = {
			stubborn = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
		}
	}

	option = { # Try again!
		name = abduct_outcome.4001.b
		play_music_cue = "mx_cue_stress"
		custom_tooltip = restart_scheme_tt

		scope:scheme = {
			reset_failed_scheme_effect = yes
		}

		ai_chance = {
			base = 10
			modifier = {
				add = 200
				has_trait = stubborn
			}
		}
	}
}


########################################
# TARGET SUCCESS NOTIFICATIONS
########################################

#I have been abducted!
abduct_outcome.5001 = {
	type = character_event
	window = scheme_target_event
	title = abduct_outcome.5001.t
	desc = {
		desc = abduct_outcome.5001.opening
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:abduct_method = flag:seized_roadside
				}
				desc = abduct_outcome.5001.seized_roadside
			}
			triggered_desc = {
				trigger = {
					scope:abduct_method = flag:on_the_way
				}
				desc = abduct_outcome.5001.on_the_way
			}
			triggered_desc = {
				trigger = {
					scope:abduct_method = flag:unwelcome_guests
				}
				desc = abduct_outcome.5001.unwelcome_guests
			}
		}
	}
	theme = prison
	left_portrait = {
		character = scope:owner
		animation = scheme
	}

	immediate = {
		show_as_tooltip = {
			hard_imprison_character_effect = {
				TARGET = scope:target
				IMPRISONER = scope:owner
			}
		}
	}

	option = {
		name = abduct_outcome.5001.a
		play_music_cue = "mx_cue_stress"
		add_opinion = {
			target = scope:owner
			modifier = abducted_me_opinion
		}
	}
}

###################################
# TARGET FAILURE NOTIFICATIONS
###################################

#I was almost abducted
abduct_outcome.5002 = {
	type = character_event
	window = scheme_target_event
	title = abduct_outcome.5002.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:abduct_method = flag:seized_roadside
				}
				desc = abduct_outcome.5002.seized_roadside
			}
			triggered_desc = {
				trigger = {
					scope:abduct_method = flag:on_the_way
				}
				desc = abduct_outcome.5002.on_the_way
			}
			triggered_desc = {
				trigger = {
					scope:abduct_method = flag:unwelcome_guests
				}
				desc = abduct_outcome.5002.unwelcome_guests
			}
			desc = abduct_outcome.5002.fallback
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:scheme_discovered
				}
				desc = abduct_outcome.5002.owner_known
			}
			desc = abduct_outcome.5002.owner_not_known
		}
	}
	theme = intrigue
	left_portrait = {
		character = scope:revealed_owner
		animation = disbelief
	}

	immediate = {
		if = {
			limit = {
				exists = scope:scheme_discovered
			}
			scope:owner = {
				save_scope_as = revealed_owner
			}
		}
	}

	option = {
		name = abduct_outcome.5002.a
		trigger = {
			exists = scope:scheme_discovered
		}
		add_opinion = {
			target = scope:owner
			modifier = attempted_abduction_opinion
		}
		add_character_modifier = {
			modifier = watchful_modifier
			days = watchful_modifier_duration
		}
	}

	option = {
		name = abduct_outcome.5002.b
		trigger = {
			NOT = { exists = scope:scheme_discovered }
		}
		add_character_modifier = {
			modifier = watchful_modifier
			days = watchful_modifier_duration
		}
	}
}
