#Events handling rapta_maritus outcomes

# System by Petter Vilberg

namespace = rapta_maritus_outcome

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

rapta_maritus_outcome.0001 = {
	
	hidden = yes

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


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

######################
# Seize Roadside
######################
rapta_maritus_outcome.1001 = {
	type = character_event
	title = rapta_maritus_outcome.1001.t
	desc = {
		desc = rapta_maritus_outcome.1001.opening
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:arrival
				}
				desc = rapta_maritus_outcome.1001.arrival
			}
			desc = rapta_maritus_outcome.1001.no_arrival
		}
		desc = rapta_maritus_outcome.1001.ending
	}
	theme = intrigue
	left_portrait = {
		character = scope:target
		animation = personality_coward
	}
	widget = {
		gui = "event_window_widget_scheme"
		container = "custom_widgets_container"
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		save_scope_value_as = {
			name = rapta_maritus_method
			value = flag:seized_roadside
		}
		if = {
			limit = {
				exists = scope:target.location.county.holder.capital_county
			}
			scope:target.location.county.holder.capital_county = {
				save_scope_as = departure
			}
			scope:target.location.county.holder.top_liege = {
				random_sub_realm_county = {
					limit = {
						NOR = {
							this = scope:departure
							holder = scope:owner
						}
						scope:departure = {
							squared_distance = {
								target = prev
								value < 100000
							}
						}
					}
					save_scope_as = arrival
				}
			}
		}
		else = {
			scope:owner.capital_county = {
				save_scope_as = departure
			}
			scope:owner.top_liege = {
				random_sub_realm_county = {
					limit = {
						NOR = {
							this = scope:departure
							holder = scope:owner
						}
						scope:departure = {
							squared_distance = {
								target = prev
								value < 100000
							}
						}
					}
					save_scope_as = arrival
				}
			}
		}
		rapta_maritus_outcome_roll_setup_effect = yes
	}

	option = {
		name = rapta_maritus_outcome.1001.a
		remove_short_term_gold = minor_gold_value
		rapta_maritus_outcome_roll_effect = yes
		ai_chance = {
			base = 100
		}
	}

	option = {
		name = rapta_maritus_outcome.1001.b
		custom_tooltip = do_not_execute_rapta_maritus_tooltip

		scope:scheme = {
			add_scheme_progress = -10 # Reset scheme progress
		}

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


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

#######################
# Seized Roadside
#######################
rapta_maritus_outcome.2001 = {
	type = character_event
	title = rapta_maritus_outcome.1001.t
	desc = rapta_maritus_outcome.2001.desc
	theme = intrigue
	left_portrait = {
		character = scope:target
		animation = fear
	}
	widget = {
		gui = "event_window_widget_scheme"
		container = "custom_widgets_container"
	}
	
	trigger = {
		scope:rapta_maritus_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
			}
		}
		rapta_maritus_success_effect = yes
	}

	option = {
		name = rapta_maritus_outcome.2001.a
		play_music_cue = "mx_cue_prison"
		successful_rapta_maritus_outcome_event_option_effect = yes
	}
}

#################################
# FAILURE OUTCOMES 4000 - 4999
#################################
rapta_maritus_outcome.4001 = {
	type = character_event
	title = rapta_maritus_outcome.1001.t
	desc = {
		desc = rapta_maritus_outcome.4001.opening
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:scheme_discovered
				}
				desc = rapta_maritus_outcome.4001.owner_discovered
			}
			desc = rapta_maritus_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:rapta_maritus_method = flag:seized_roadside
	}

	immediate = {
		rapta_maritus_failure_effect = yes
	}

	option = { # Abandon scheme
		name = rapta_maritus_outcome.4001.a
		scope:scheme = {
			end_scheme = yes
		}
		stress_impact = {
			stubborn = medium_stress_impact_gain
		}
		ai_chance = { #They're charmed.  No way they back out.
			base = 100
		}
	}
}

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

#I have been abducted!
rapta_maritus_outcome.5001 = {
	type = character_event
	title = rapta_maritus_outcome.5001.t
	desc = {
		desc = rapta_maritus_outcome.5001.opening
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:rapta_maritus_method = flag:seized_roadside
				}
				desc = rapta_maritus_outcome.5001.seized_roadside
			}
			triggered_desc = {
				trigger = {
					scope:rapta_maritus_method = flag:on_the_way
				}
				desc = rapta_maritus_outcome.5001.on_the_way
			}
			triggered_desc = {
				trigger = {
					scope:rapta_maritus_method = flag:unwelcome_guests
				}
				desc = rapta_maritus_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 = rapta_maritus_outcome.5001.a
		play_music_cue = "mx_cue_stress"
		add_opinion = {
			target = scope:owner
			modifier = unfaithful_spouse_exposed_opinion
		}
		add_opinion = {
			target = global_var:magister_character
			modifier = abducted_me_opinion
		}
	}
}

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

rapta_maritus_outcome.5002 = {
	type = character_event
	title = rapta_maritus_outcome.5002.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:rapta_maritus_method = flag:seized_roadside
				}
				desc = rapta_maritus_outcome.5002.seized_roadside
			}
			triggered_desc = {
				trigger = {
					scope:rapta_maritus_method = flag:on_the_way
				}
				desc = rapta_maritus_outcome.5002.on_the_way
			}
			triggered_desc = {
				trigger = {
					scope:rapta_maritus_method = flag:unwelcome_guests
				}
				desc = rapta_maritus_outcome.5002.unwelcome_guests
			}
			desc = rapta_maritus_outcome.5002.fallback
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:scheme_discovered
				}
				desc = rapta_maritus_outcome.5002.owner_known
			}
			desc = rapta_maritus_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 = rapta_maritus_outcome.5002.a
		trigger = {
			exists = scope:scheme_discovered
		}
		add_opinion = {
			target = scope:owner
			modifier = unfaithful_spouse_exposed_opinion
		}
		add_character_modifier = {
			modifier = watchful_modifier
			days = watchful_modifier_duration
		}
	}

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


###################################
# MAGISTER SUCCESS NOTIFICATIONS
###################################


rapta_maritus_outcome.7001 = {
	type = letter_event
	
	opening = {
		desc = rapta_maritus_outcome.7001.opening
	}
	desc = rapta_maritus_outcome.7001.desc
	sender = {
		character = scope:owner
		animation = worry ### UPDATE - Put something relevant here.
	}

	# immediate ={
	# 	show_as_tooltip = { ransom_interaction_effect = yes }
	# }

	option = {
		name = rapta_maritus_outcome.7001.a
	}
}



###################################
# MAGISTER FAILURE NOTIFICATIONS
###################################

rapta_maritus_outcome.7002 = {
	type = letter_event
	opening = {
		desc = rapta_maritus_outcome.7002.opening
	}
	desc = rapta_maritus_outcome.7002.desc
	
	sender = scope:owner

	# immediate ={
	# 	show_as_tooltip = { ransom_interaction_effect = yes }
	# }

	option = {
		name = rapta_maritus_outcome.7002.a
	}
}