﻿#Events handling Claim Throne outcomes

# System by Petter Vilberg

namespace = claim_throne_outcome

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


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

######################
# Distant Relation
# by Petter Vilberg
######################
claim_throne_outcome.1001 = {
	type = character_event
	title = claim_throne_outcome.1001.t
	desc = claim_throne_outcome.1001.desc
	theme = claim_throne_scheme
	left_portrait = scope:target
	widget = {
		gui = "event_window_widget_scheme"
		container = "custom_widgets_container"
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		save_scope_value_as = {
			name = claim_throne_method
			value = flag:distant_relation
		}
		claim_throne_outcome_roll_setup_effect = yes
	}

	option = {
		name = claim_throne_outcome.1001.a
		claim_throne_outcome_roll_effect = yes
		stress_impact = {
			humble = major_stress_impact_gain
		}
		ai_chance = { # The AI should generally not back out of a planned Scheme
			base = 100
		}
	}

	option = {
		name = claim_throne_outcome.1001.b
		claim_throne_decline_execution_effect = yes
		ai_chance = {
			base = 0
		}
		stress_impact = {
			ambitious = major_stress_impact_gain
			arrogant = medium_stress_impact_gain
			impatient = medium_stress_impact_gain
			stubborn = medium_stress_impact_gain
		}
	}
}

######################
# Connection to Mythical Founder
# by Petter Vilberg
######################
claim_throne_outcome.1002 = {
	type = character_event
	title = claim_throne_outcome.1001.t
	desc = claim_throne_outcome.1002.desc
	theme = claim_throne_scheme
	left_portrait = scope:target
	widget = {
		gui = "event_window_widget_scheme"
		container = "custom_widgets_container"
	}

	trigger = {
		scope:target_title = {
			has_mythical_founder_trigger = yes
		}
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		save_scope_value_as = {
			name = claim_throne_method
			value = flag:mythical_founder
		}
		claim_throne_outcome_roll_setup_effect = yes
		if = {
			limit = {
				OR = {
					scope:owner = { is_ai = no }
					scope:target = { is_ai = no }
				}
			}
			claim_throne_set_mythical_founder_variable_effect = yes
		}
	}

	option = {
		name = claim_throne_outcome.1001.a
		claim_throne_outcome_roll_effect = yes
		stress_impact = {
			humble = major_stress_impact_gain
		}
		ai_chance = { # The AI should generally not back out of a planned Scheme
			base = 100
		}
	}

	option = {
		name = claim_throne_outcome.1001.b
		claim_throne_decline_execution_effect = yes
		ai_chance = {
			base = 0
		}
		stress_impact = {
			ambitious = major_stress_impact_gain
			arrogant = medium_stress_impact_gain
			impatient = medium_stress_impact_gain
			stubborn = medium_stress_impact_gain
		}
	}
}

######################
# Designated by Previous Holder
# by Petter Vilberg
######################
claim_throne_outcome.1003 = {
	type = character_event
	title = claim_throne_outcome.1001.t
	desc = claim_throne_outcome.1003.desc
	theme = claim_throne_scheme
	left_portrait = scope:target
	right_portrait = scope:previous_title_holder
	widget = {
		gui = "event_window_widget_scheme"
		container = "custom_widgets_container"
	}
	orphan = yes

	trigger = {
		is_adult = yes
		exists = scope:target_title.previous_holder # Does a previous holder even exist?
		scope:target_title.previous_holder = { is_alive = no } # It's important that the previous holder isn't around to contradict the scheme owner
		scope:target_title = {
			recent_history = { # Make sure there's a relatively recent inheritance
				type = inheritance
				years = 16
			}
			NOT = { # Was not recently conquered
				recent_history = {
					type = conquest
					years = 30
				}
			}
		}
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		save_scope_value_as = { # Set execution method
			name = claim_throne_method
			value = flag:previous_holder_promise
		}
		scope:target_title.previous_holder = { # For use in loc
			save_scope_as = previous_title_holder
		}
		claim_throne_outcome_roll_setup_effect = yes
	}

	option = {
		name = claim_throne_outcome.1001.a
		claim_throne_outcome_roll_effect = yes
		stress_impact = {
			humble = major_stress_impact_gain
		}
		ai_chance = { # The AI should generally not back out of a planned Scheme
			base = 100
		}
	}

	option = {
		name = claim_throne_outcome.1001.b
		claim_throne_decline_execution_effect = yes
		ai_chance = {
			base = 0
		}
		stress_impact = {
			ambitious = major_stress_impact_gain
			arrogant = medium_stress_impact_gain
			impatient = medium_stress_impact_gain
			stubborn = medium_stress_impact_gain
		}
	}
}


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

#######################
# Distant Relation
#######################
claim_throne_outcome.2001 = {
	type = character_event
	window = scheme_successful_event
	title = claim_throne_outcome.1001.t
	desc = {
		desc = claim_throne_outcome.2001.opening
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:scheme_discovered }
				desc = claim_throne_outcome.2001.discovered
			}
			desc = claim_throne_outcome.2001.no_awareness
		}
	}
	theme = claim_throne_scheme
	left_portrait = {
		character = scope:target
		animation = anger
	}
	widget = {
		gui = "event_window_widget_scheme"
		container = "custom_widgets_container"
	}
	
	trigger = {
		scope:claim_throne_method = flag:distant_relation
		scope:target = { is_landed = yes } # You never know what might happen...
	}

	immediate = {
		claim_throne_check_target_title_effect = yes
		claim_throne_success_effect = yes
	}

	option = {
		name = claim_throne_outcome.2001.a
		trigger = {
			NOT = { exists = scope:scheme_discovered }
		}
		successful_claim_throne_event_option_effect = yes
	}

	option = {
		name = claim_throne_outcome.2001.b
		trigger = {
			exists = scope:scheme_discovered
		}
		successful_claim_throne_event_option_effect = yes
	}
}
#######################
# Mythical Founder
########################
claim_throne_outcome.2002 = {
	type = character_event
	window = scheme_successful_event
	title = claim_throne_outcome.1001.t
	desc = {
		desc = claim_throne_outcome.2001.opening
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:scheme_discovered }
				desc = claim_throne_outcome.2002.discovered
			}
			desc = claim_throne_outcome.2002.no_awareness
		}
	}
	theme = claim_throne_scheme
	left_portrait = {
		character = scope:target
		animation = anger
	}
	widget = {
		gui = "event_window_widget_scheme"
		container = "custom_widgets_container"
	}
	
	trigger = {
		scope:claim_throne_method = flag:mythical_founder
		scope:target = { is_landed = yes } # You never know what might happen...
	}

	immediate = {
		claim_throne_check_target_title_effect = yes
		claim_throne_success_effect = yes
	}

	option = {
		name = claim_throne_outcome.2001.a
		trigger = {
			NOT = { exists = scope:scheme_discovered }
		}
		successful_claim_throne_event_option_effect = yes
	}

	option = {
		name = claim_throne_outcome.2001.b
		trigger = {
			exists = scope:scheme_discovered
		}
		successful_claim_throne_event_option_effect = yes
	}

	after = {
		hidden_effect = {
			if = {
				limit = { has_variable = mythical_founder }
				trigger_event = { # Variable cleanup
					id = claim_throne_outcome.9998
					days = 20
				}
			}
		}
	}
}
########################
## Promised inheritance
########################
claim_throne_outcome.2003 = {
	type = character_event
	window = scheme_successful_event
	title = claim_throne_outcome.1001.t
	desc = {
		desc = claim_throne_outcome.2001.opening
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:scheme_discovered }
				desc = claim_throne_outcome.2003.discovered
			}
			desc = claim_throne_outcome.2003.no_awareness
		}
	}
	theme = claim_throne_scheme
	orphan = yes
	left_portrait = {
		character = scope:target
		animation = anger
	}
	widget = {
		gui = "event_window_widget_scheme"
		container = "custom_widgets_container"
	}
	
	trigger = {
		scope:claim_throne_method = flag:previous_holder_promise
		scope:target = { is_landed = yes } # You never know what might happen over the course of a few days...
	}

	immediate = {
		claim_throne_check_target_title_effect = yes
		claim_throne_success_effect = yes
	}

	option = {
		name = claim_throne_outcome.2001.a
		trigger = {
			NOT = { exists = scope:scheme_discovered }
		}
		successful_claim_throne_event_option_effect = yes
	}

	option = {
		name = claim_throne_outcome.2001.b
		trigger = {
			exists = scope:scheme_discovered
		}
		successful_claim_throne_event_option_effect = yes
	}
}


#################################
# FAILURE OUTCOMES 4000 - 4999
#################################
##################
# Distant Relation
##################
claim_throne_outcome.4001 = {
	type = character_event
	window = scheme_failed_event
	title = claim_throne_outcome.1001.t
	desc = {
		desc = claim_throne_outcome.4001.opening
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:scheme_discovered
				}
				desc = claim_throne_outcome.4001.owner_discovered
			}
			desc = claim_throne_outcome.4001.owner_secret
		}
	}
	theme = claim_throne_scheme
	left_portrait = {
		character = scope:target
		triggered_animation = {
			trigger = { exists = scope:scheme_discovered }
			animation = anger
		}
		triggered_animation = {
			trigger = { always = yes }
			animation = idle
		}
	}
	widget = {
		gui = "event_window_widget_scheme"
		container = "custom_widgets_container"
	}
	
	trigger = {
		scope:claim_throne_method = flag:distant_relation
		scope:target = { is_landed = yes } # You never know what might happen...
	}

	immediate = {
		claim_throne_check_target_title_effect = yes # No claims will be set, but loc relies on having the title available
	}

	option = { # Noooo
		name = claim_throne_outcome.4001.a
		trigger = {
			exists = scope:scheme_discovered
		}
		claim_throne_failure_effect = yes
		scope:scheme = {
			end_scheme = yes
		}
	}

	option = { # Try again
		name = claim_throne_outcome.4001.b
		trigger = {
			NOT = { exists = scope:scheme_discovered }
		}
		scope:scheme = {
			add_scheme_progress = {
				value = scheme_progress_gain
				multiply = -5
			}
		}
		stress_impact = { # Stress from almost being discovered
			base = medium_stress_impact_gain
			stubborn = minor_stress_impact_loss
		}
		ai_chance = {
			base = 100
		}
	}

	option = { # Give up
		name = claim_throne_outcome.4001.c
		trigger = {
			NOT = { exists = scope:scheme_discovered }
		}
		scope:scheme = {
			end_scheme = yes
		}
		ai_chance = {
			base = 25
		}
	}
}
##################
# Mythical Founder
##################
claim_throne_outcome.4002 = {
	type = character_event
	window = scheme_failed_event
	title = claim_throne_outcome.1001.t
	desc = {
		desc = claim_throne_outcome.4001.opening
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:scheme_discovered
				}
				desc = claim_throne_outcome.4002.owner_discovered
			}
			desc = claim_throne_outcome.4002.owner_secret
		}
	}
	theme = claim_throne_scheme
	left_portrait = {
		character = scope:target
		triggered_animation = {
			trigger = { exists = scope:scheme_discovered }
			animation = anger
		}
		triggered_animation = {
			trigger = { always = yes }
			animation = idle
		}
	}
	widget = {
		gui = "event_window_widget_scheme"
		container = "custom_widgets_container"
	}
	
	trigger = {
		scope:claim_throne_method = flag:mythical_founder
		scope:target = { is_landed = yes } # You never know what might happen...
	}

	immediate = {
		claim_throne_check_target_title_effect = yes # No claims will be set, but loc relies on having the title available
	}

	option = { # Noooo
		name = claim_throne_outcome.4002.a
		trigger = {
			exists = scope:scheme_discovered
		}
		claim_throne_failure_effect = yes
		scope:scheme = {
			end_scheme = yes
		}
	}

	option = { # Try again
		name = claim_throne_outcome.4001.b
		trigger = {
			NOT = { exists = scope:scheme_discovered }
		}
		scope:scheme = {
			add_scheme_progress = {
				value = scheme_progress_gain
				multiply = -5
			}
		}
		stress_impact = { # Stress from almost being discovered
			base = medium_stress_impact_gain
			stubborn = minor_stress_impact_loss
		}
		ai_chance = {
			base = 100
		}
	}

	option = { # Give up
		name = claim_throne_outcome.4001.c
		trigger = {
			NOT = { exists = scope:scheme_discovered }
		}
		scope:scheme = {
			end_scheme = yes
		}
		ai_chance = {
			base = 25
		}
	}

	after = {
		hidden_effect = {
			if = {
				limit = { has_variable = mythical_founder }
				trigger_event = { # Variable cleanup
					id = claim_throne_outcome.9998
					days = 20
				}
			}
		}
	}
}
##################
# Previous Holder Promise
##################
claim_throne_outcome.4003 = {
	type = character_event
	window = scheme_failed_event
	title = claim_throne_outcome.1001.t
	desc = {
		desc = claim_throne_outcome.4001.opening
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:scheme_discovered
				}
				desc = claim_throne_outcome.4003.owner_discovered
			}
			desc = claim_throne_outcome.4003.owner_secret
		}
	}
	theme = claim_throne_scheme
	orphan = yes
	left_portrait = {
		character = scope:target
		triggered_animation = {
			trigger = { exists = scope:scheme_discovered }
			animation = anger
		}
		triggered_animation = {
			trigger = { always = yes }
			animation = idle
		}
	}
	widget = {
		gui = "event_window_widget_scheme"
		container = "custom_widgets_container"
	}
	
	trigger = {
		scope:claim_throne_method = flag:previous_holder_promise
		scope:target = { is_landed = yes } # You never know what might happen...
	}

	immediate = {
		claim_throne_check_target_title_effect = yes # No claims will be set, but loc relies on having the title available
	}

	option = { # Noooo
		name = claim_throne_outcome.4003.a
		trigger = {
			exists = scope:scheme_discovered
		}
		claim_throne_failure_effect = yes
		scope:scheme = {
			end_scheme = yes
		}
	}

	option = { # Try again
		name = claim_throne_outcome.4001.b
		trigger = {
			NOT = { exists = scope:scheme_discovered }
		}
		scope:scheme = {
			add_scheme_progress = {
				value = scheme_progress_gain
				multiply = -5
			}
		}
		stress_impact = { # Stress from almost being discovered
			base = medium_stress_impact_gain
			stubborn = minor_stress_impact_loss
		}
		ai_chance = {
			base = 100
		}
	}

	option = { # Give up
		name = claim_throne_outcome.4001.c
		trigger = {
			NOT = { exists = scope:scheme_discovered }
		}
		scope:scheme = {
			end_scheme = yes
		}
		ai_chance = {
			base = 25
		}
	}
}


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

#A Vassal has a claim on my Primary Title
claim_throne_outcome.5001 = {
	type = character_event
	window = scheme_target_event
	title = claim_throne_outcome.1001.t
	desc = {
		desc = claim_throne_outcome.5001.opening
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:claim_throne_method = flag:distant_relation
				}
				desc = claim_throne_outcome.5001.distant_relation
			}
			triggered_desc = {
				trigger = {
					scope:claim_throne_method = flag:mythical_founder
				}
				desc = claim_throne_outcome.5001.mythical_founder
			}
			triggered_desc = {
				trigger = {
					scope:claim_throne_method = flag:previous_holder_promise
				}
				desc = claim_throne_outcome.5001.previous_holder_promise
			}
			desc = claim_throne_outcome.5001.fallback
		}
	}
	theme = claim_throne_scheme
	left_portrait = {
		character = scope:owner
		animation = personality_bold
	}

	trigger = {
		exists = scope:target_title
	}

	option = {
		name = claim_throne_outcome.5001.a
		show_as_tooltip = {
			scope:owner = {
				add_pressed_claim = scope:target_title
			}
		}
		if = {
			limit = {
				exists = scope:set_rivalry
			}
			set_relation_rival = {
				target = scope:owner
				reason = rival_claimed_my_title
			}
		}
		add_opinion = {
			target = scope:owner
			modifier = claim_my_throne_success_undiscovered_opinion
			years = 10
		}
	}
}

#A Vassal has an illegitimate claim on my Primary Title
claim_throne_outcome.5002 = {
	type = character_event
	window = scheme_target_event
	title = claim_throne_outcome.1001.t
	desc = {
		desc = claim_throne_outcome.5001.opening
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:claim_throne_method = flag:distant_relation
				}
				desc = claim_throne_outcome.5001.distant_relation
			}
			triggered_desc = {
				trigger = {
					scope:claim_throne_method = flag:mythical_founder
				}
				desc = claim_throne_outcome.5001.mythical_founder
			}
			triggered_desc = {
				trigger = {
					scope:claim_throne_method = flag:previous_holder_promise
				}
				desc = claim_throne_outcome.5001.previous_holder_promise
			}
		}
		desc = claim_throne_outcome.5001.discovered
	}
	theme = claim_throne_scheme
	left_portrait = {
		character = scope:owner
		animation = personality_bold
	}

	trigger = {
		exists = scope:target_title
	}

	option = {
		name = claim_throne_outcome.5002.a
		show_as_tooltip = {
			scope:owner = {
				add_pressed_claim = scope:target_title
			}
			add_prestige = claim_throne_discovered_prestige_loss
		}
		if = {
			limit = {
				exists = scope:set_rivalry
			}
			set_relation_rival = {
				target = scope:owner
				reason = rival_claimed_my_title
			}
		}
		add_opinion = {
			target = scope:owner
			modifier = claim_my_throne_success_discovered_opinion
		}
	}
}

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

#Someone tried to claim my throne - Only fires if Scheme was discovered
claim_throne_outcome.5003 = {
	type = character_event
	window = scheme_target_event
	title = claim_throne_outcome.1001.t
	desc = {
		desc = claim_throne_outcome.5003.opening
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:claim_throne_method = flag:distant_relation
				}
				desc = claim_throne_outcome.5001.distant_relation
			}
			triggered_desc = {
				trigger = {
					scope:claim_throne_method = flag:mythical_founder
				}
				desc = claim_throne_outcome.5001.mythical_founder
			}
			triggered_desc = {
				trigger = {
					scope:claim_throne_method = flag:previous_holder_promise
				}
				desc = claim_throne_outcome.5001.previous_holder_promise
			}
		}
		desc = claim_throne_outcome.5003.owner_known
	}
	theme = claim_throne_scheme
	left_portrait = {
		character = scope:revealed_owner
		animation = worry
	}

	immediate = {
		scope:owner = {
			save_scope_as = revealed_owner
		}
	}

	option = {
		name = claim_throne_outcome.5003.a
		if = {
			limit = {
				exists = scope:set_rivalry
			}
			set_relation_rival = {
				target = scope:owner
				reason = rival_claimed_my_title
			}
		}
		add_opinion = {
			target = scope:owner
			modifier = claim_my_throne_failure_opinion
			years = 10
		}
		show_as_tooltip = {
			scope:owner = {
				add_prestige = claim_throne_discovered_failure_prestige_loss
			}
		}
	}
}

###################
# Cleanup
###################
claim_throne_outcome.9998 = {
	hidden = yes

	trigger = {
		has_variable = mythical_founder
	}

	immediate = {
		remove_variable = mythical_founder
	}
}

####################
# Invalidation Messages
####################

claim_throne_outcome.9999 = {
	hidden = yes

	trigger = {
		NOR = {
			exists = scope:target_title
			AND = {
				exists = scope:target_title
				NOT = { has_claim_on = scope:target_title }
			}
			has_character_flag = is_executing_claim_throne
		}
	}
	
	immediate = {
		if = { # Target has died
			limit = {
				scope:target = { is_alive = no }
			}
			send_interface_toast = {
				title = claim_throne_invalidated
				type = event_toast_effect_neutral
				left_icon = scope:target
				custom_tooltip = claim_throne_target_died_tt
			}
		}
		else_if = { # Target is no longer landed
			limit = {
				OR = {
					NOT = { exists = scope:target_title }
					scope:target = { is_landed = no }
				}
			}
			send_interface_toast = {
				title = claim_throne_invalidated
				type = event_toast_effect_neutral
				left_icon = scope:target
				custom_tooltip = claim_throne_target_lost_titles_tt
			}
		}
		else_if = { # Target is no longer my Liege
			limit = {
				liege != scope:target
			}
			send_interface_toast = {
				title = claim_throne_invalidated
				type = event_toast_effect_neutral
				left_icon = scope:target
				custom_tooltip = claim_throne_target_no_longer_liege_tt
			}
		}
		else = { # Fallback
			send_interface_toast = {
				title = claim_throne_invalidated
				type = event_toast_effect_neutral
				left_icon = scope:target
				custom_tooltip = claim_throne_invalidate_fallback_tt
			}
		}
	}
}
