﻿@unlock_scheme_opt_out_value = 1

namespace = scheme_critical_moments

##################################################
# #Base System
# 0001 - 0010	Standard Critical Moment
#
# #Ordinary Schemes
# 1001 - 1010	Murder
# 1011 - 1020	Seduce
# 1021 - 1030	Sway
# 1031 - 1040	Befriend
# 1041 - 1050	Court
# 1051 - 1060	Elope
# 1061 - 1070	Abduct
# 1071 - 1080	Fabricate Claim
# 1081 - 1090	Learn Language
# 1091 - 1100	Abduct Regent
# 1101 - 1110	Claim Throne
# 1111 - 1120	Steal Back Artefact
# 1121 - 1130	Convert to Witchcraft
# 1131 - 1140   Slander
# 1141 - 1150   Promote
# 1151 - 1160	Generate Claim
# 1161 - 1170   Steal Herd
# 1171 - 1180   Challenge Status
# 1181 - 1190	Expand Power Base
# 1191 - 1200	Depose Results
# 1201 - 1210	Siphon Treasury Results
# 1211 - 1220	Disbelieve Mandala Results
# 1221 - 1230	Coerce Tributary Results
#
#
#
#
#
# #Contract Schemes (Diplo)
# 2001 - 2010	Regale court with stories
# 2011 - 2020	Improve ruler's reputation
# 2021 - 2030	Hobnob with local ruler
# 2031 - 2040	Paid Mediator
# 2041 - 2050	Confidence trickster
#
# #Contract Schemes (Martial)
# 2201 - 2210	Hunt criminals
# 2211 - 2220	Act as hired muscle
# 2221 - 2230	Help train local MaA
# 2231 - 2240	Garrison service
# 2241 - 2250	Ambush travellers
#
# #Contract Schemes (Stewardship)
# 2401 - 2410	Collect taxes for a third party
# 2411 - 2420	Perform a census
# 2421 - 2430	Help construct a building
# 2431 - 2440	Settle an administrative boundary dispute
# 2441 - 2450	Collect fake taxes
#
# #Contract Schemes (Intrigue)
# 2601 - 2610	Provide intelligence from your trips
# 2611 - 2620	Murder a character's rival
# 2621 - 2630	Abduct a character's rival
# 2631 - 2640	Attack the property of a character's rival
# 2641 - 2650	Heist from a ruler's treasury
#
# #Contract Schemes (Learning)
# 2801 - 2810	Copy texts for a learned ruler
# 2811 - 2820	Help settle a local theological argument
# 2821 - 2830	Create a work of learning for a ruler
# 2831 - 2840	Solicit Charity
# 2841 - 2850	Sell bogus relics
#
# #Contract Schemes (Prowess)
# 3001 - 3010	Hunt in the wilds
# 3011 - 3020	Guard merchant properties
# 3021 - 3030	Guard a local ruler at a minor event
# 3031 - 3040	Go rustling
# 3041 - 3050	Go poaching
#
##################################################










##################################################
# GENERAL SCRIPTED TRIGGERS & EFFECTS

# Simple effect for rolling if a scheme with no secrecy succeeded or failed. No thrills, no frills.
scripted_effect roll_scheme_success_or_failure_effect = {
	random = {
		chance = scope:scheme.scheme_success_chance
		save_scope_value_as = {
			name = scheme_successful
			value = yes
		}
	}
	scope:owner = {
		if = {
			limit = { exists = scope:scheme_successful }
			mandala_trickster_increment_successful_schemes_effect = yes
			trigger_event = $SUCCESS_EVENT$
		}
		else = { trigger_event = $FAILURE_EVENT$ }
	}
}











##################################################
# BASE SYSTEM

##################################################
# Standard Critical Moment
# by Ewan Cowhig Croft
# 0001 - 0010
##################################################

scripted_trigger scheme_critical_moments_0001_can_add_agents_trigger = {
	scope:scheme = {
		custom_tooltip = {
			text = scheme_critical_moments.0001.option.need_opportunities
			scheme_agent_charges >= 1
		}
		custom_tooltip = {
			text = scheme_critical_moments.0001.option.max_slots
			any_scheme_agent_slot = { count < character_max_scheme_agents_value }
		}
	}
}

scripted_effect scheme_critical_moments_0001_configure_portraits_effect = {
	# Let's configure some portraits!
	## But only for the player, the AI doesn't care.
	if = {
		limit = { is_ai = no }
		# If there's no target character, root goes in the centre.
		if = {
			limit = {
				NOT = { exists = scope:scheme.scheme_target_character}
			}
			save_scope_as = centre_portrait
		}
		# Else, root goes on the left & scope:target on the right.
		else = {
			save_scope_as = left_portrait
			if = {
				limit = {
					scope:target = {
						this != root
					}
				}
				scope:target = { save_scope_as = right_portrait }
			}
		}
	}
	# Do we need to show murder interception tooltips?
	## Save this as a scope so that we don't have to faff with multiple scopes getting read into a script value.
	if = {
		limit = {
			# No need to process the stuff below for robots.
			is_ai = no
			# Are we actually a murder?
			scope:scheme = { is_savable_murder_scheme_trigger = yes }
		}
		scope:scheme = {
			set_variable = {
				name = target_intercept_repeatable_chance
				value = scope:target.scheme_intercept_repeatable_chance_total_value
			}
		}
	}
}

scripted_effect scheme_critical_moments_0001_execute_scheme_default_flow_effect = {
	# If this is a murder scheme, warn about intercepts.
	if = {
		limit = {
			scope:scheme = { has_variable = target_intercept_repeatable_chance }
		}
		# Show the repeatable intercepter if relevant.
		if = {
			limit = { scope:scheme.var:target_intercept_repeatable_chance >= 1 }
			# Aaaaand throw out our warning.
			custom_tooltip = scheme_critical_moments.0001.a.tt.murders_may_be_intercepted.repeatable
			custom_tooltip = scheme_critical_moments.0001.a.tt.murders_may_be_intercepted.repeatable_and_unique
		}
		# Otherwise just show the unique intercepter.
		else = { custom_tooltip = scheme_critical_moments.0001.a.tt.murders_may_be_intercepted.unique }
	}
	scope:scheme = {
		change_opportunities = {
			value = $COST$
			multiply = -1
		}
	}
	trigger_event = { saved_event_id = scope:follow_up_event }
}

#	Scheme Type A: choose between finalising your scheme, picking new agents, or starting the round again from the top.
scheme_critical_moments.0001 = {
	type = character_event
	window = scheme_preparations_event
	title = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:scheme = { is_scheme_category = contract }
				}
				desc = scheme_critical_moments.0001.t.task_contract
			}
			desc = scheme_critical_moments.0001.t.scheme
		}
	}
	desc = scheme_critical_moments.0001.desc
	theme = intrigue
	left_portrait = {
		character = scope:left_portrait
		scripted_animation = scheme_prep_pick_best_stance
	}
	center_portrait = {
		character = scope:centre_portrait
		scripted_animation = scheme_prep_pick_best_stance
	}
	right_portrait = {
		character = scope:right_portrait
		scripted_animation = scheme_prep_pick_best_stance
	}
	# Background overrides.
	## Tabbed one degree further for easy folding.
		## Romantic schemes.
		override_background = {
			trigger = {
				scope:scheme = { should_use_amorous_scheme_animation_trigger = yes }
			}
			reference = bedchamber
		}
		## Diplo schemes.
		override_background = {
			trigger = {
				scope:scheme = { scheme_skill = diplomacy }
			}
			reference = council_chamber
		}
		## Martial or prowess schemes.
		override_background = {
			trigger = {
				scope:scheme = {
					scheme_skill = martial
					scheme_skill = prowess
				}
			}
			reference = armory
		}
		## Stewardship schemes.
		override_background = {
			trigger = {
				scope:scheme = { scheme_skill = stewardship }
			}
			reference = study
		}
		## Intrigue schemes.
		override_background = {
			trigger = {
				scope:scheme = { scheme_skill = intrigue }
			}
			reference = corridor_night
		}
		## Learning schemes.
		override_background = {
			trigger = {
				scope:scheme = { scheme_skill = learning }
			}
			reference = physicians_study
		}
	# Icon overrides.
	## Tabbed one degree further for easy folding.
		## Diplo schemes.
		override_icon = {
			trigger = {
				scope:scheme = { scheme_skill = diplomacy }
			}
			reference = "gfx/interface/icons/event_types/type_diplomacy.dds"
		}
		## Martial or prowess schemes.
		override_icon = {
			trigger = {
				scope:scheme = {
					scheme_skill = martial
					scheme_skill = prowess
				}
			}
			reference = "gfx/interface/icons/event_types/type_martial.dds"
		}
		## Stewardship schemes.
		override_icon = {
			trigger = {
				scope:scheme = { scheme_skill = stewardship }
			}
			reference = "gfx/interface/icons/event_types/type_stewardship.dds"
		}
		## Intrigue schemes.
		override_icon = {
			trigger = {
				scope:scheme = { scheme_skill = intrigue }
			}
			reference = "gfx/interface/icons/event_types/type_intrigue.dds"
		}
		## Learning schemes.
		override_icon = {
			trigger = {
				scope:scheme = { scheme_skill = learning }
			}
			reference = "gfx/interface/icons/event_types/type_learning.dds"
		}

	# Scheme Preparations status bar
	widget = {
		gui = "event_window_widget_scheme_preparations"
		container = "custom_widgets_container"
	}

	trigger = {
		NOT = { has_character_flag = currently_in_scheme_preparations }
	}

	immediate = {
		# Flag that we're in the event, so no doubles pls.
		add_character_flag = currently_in_scheme_preparations
		# Sort some aesthetic stuff for the player.
		scheme_critical_moments_0001_configure_portraits_effect = yes
	}

	# Attempt to complete the scheme.
	option = {
		name = scheme_critical_moments.0001.a
		show_as_unavailable = { always = yes }
		trigger = {
			custom_tooltip = {
				text = scheme_critical_moments.0001.a.tt.stymied.insufficient_opportunities
				scope:scheme = { scheme_agent_charges >= scheme_charge_to_advance_threshold_value }
			}
			# Tell the AI not to bother unless their chance are at least 50:50.
			trigger_if = {
				limit = { is_ai = yes }
				scope:scheme = {
					OR = {
						# Either you've got a good shot.
						scheme_success_chance >= 50
						# You're landless and have a so-so shot.
						AND = {
							is_ruler = no
							scope:scheme.scheme_success_chance >= 20
						}
						# Or you've run out of potential.
						AND = {
							scheme_number_of_filled_agent_slots >= character_max_scheme_agents_value
							scope:scheme.scheme_success_chance >= scope:scheme.max_scheme_success_chance
						}
					}
				}
			}
		}

		# Scheme gon' try to conclude.
		custom_tooltip = scheme_critical_moments.0001.a.tt.progress
		scheme_critical_moments_0001_execute_scheme_default_flow_effect = { COST = scheme_charge_to_advance_threshold_value }

		ai_chance = { scheme_prep_ai_should_execute_scheme_modifier = yes }
	}

	# Choose first agent type.
	option = {
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = { exists = scope:scheme.var:choice_a }
						desc = scheme_critical_moments.0001.b
					}
					desc = scheme_critical_moments.0001.b.fallback
				}
			}
		}
		show_as_unavailable = { always = yes }
		trigger = { scheme_critical_moments_0001_can_add_agents_trigger = yes }

		# Check for the variable so that, if we've run out of slots and not generated one, we don't error spam.
		if = {
			limit = { exists = scope:scheme.var:choice_a }
			select_critical_moment_agents_effect = { CHOICE = scope:scheme.var:choice_a }
		}
		scope:scheme = { change_opportunities = -2 }

		ai_chance = {
			modifier = {
				add = 25
				scope:scheme = {
					any_scheme_agent_slot = { count >= character_max_scheme_agents_value }
				}
			}
		}
	}

	# Choose second agent type.
	option = {
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = { exists = scope:scheme.var:choice_b }
						desc = scheme_critical_moments.0001.c
					}
					desc = scheme_critical_moments.0001.c.fallback
				}
			}
		}
		show_as_unavailable = { always = yes }
		trigger = { scheme_critical_moments_0001_can_add_agents_trigger = yes }

		# Check for the variable so that, if we've run out of slots and not generated one, we don't error spam.
		if = {
			limit = { exists = scope:scheme.var:choice_b }
			select_critical_moment_agents_effect = { CHOICE = scope:scheme.var:choice_b }
		}
		scope:scheme = { change_opportunities = -2 }

		ai_chance = {
			modifier = {
				add = 25
				scope:scheme = {
					any_scheme_agent_slot = { count >= character_max_scheme_agents_value }
				}
			}
		}
	}

	# Void both and take another go around.
	option = {
		name = scheme_critical_moments.0001.d
		show_as_unavailable = { always = yes }
		trigger = { scheme_critical_moments_0001_can_add_agents_trigger = yes }

		scope:scheme = {
			# Deduct the cost.
			change_opportunities = -2
			# Plus remember to clear our choices.
			remove_variable = choice_a
			remove_variable = choice_b
			# Let's go again.
			## Hack fix for murder.
			if = {
				limit = { scheme_type = seduce }
				remove_character_flag = currently_in_scheme_preparations
				roll_critical_moment_options_06_agent_types_effect = {
					# Success results event.
					OUTPUT_EVENT = scheme_critical_moments.1001
					# Assassin
					AGENT_TYPE_01 = agent_assassin
					AGENT_TYPE_01_WEIGHT = critical_moment_agent_weight_high_value
					# Lookout
					AGENT_TYPE_02 = agent_lookout
					AGENT_TYPE_02_WEIGHT = critical_moment_agent_weight_high_value
					# Infiltrator
					AGENT_TYPE_03 = agent_infiltrator
					AGENT_TYPE_03_WEIGHT = critical_moment_agent_weight_medium_value
					# Footpad
					AGENT_TYPE_04 = agent_footpad
					AGENT_TYPE_04_WEIGHT = critical_moment_agent_weight_medium_value
					# Alibi
					AGENT_TYPE_05 = agent_alibi
					AGENT_TYPE_05_WEIGHT = critical_moment_agent_weight_high_value
					# Poisoner
					AGENT_TYPE_06 = agent_poisoner
					AGENT_TYPE_06_WEIGHT = critical_moment_agent_weight_high_value
				}
			}
			## Hack fix for seduction.
			if = {
				limit = { scheme_type = seduce }
				remove_character_flag = currently_in_scheme_preparations
				roll_critical_moment_options_07_agent_types_effect = {
					# Success results event.
					OUTPUT_EVENT = scheme_critical_moments.1011
					# Lookout
					AGENT_TYPE_01 = agent_lookout
					AGENT_TYPE_01_WEIGHT = critical_moment_agent_weight_high_value
					# Infiltrator
					AGENT_TYPE_02 = agent_infiltrator
					AGENT_TYPE_02_WEIGHT = critical_moment_agent_weight_high_value
					# Comrade_in_arms
					AGENT_TYPE_03 = agent_comrade_in_arms
					AGENT_TYPE_03_WEIGHT = critical_moment_agent_weight_high_value
					# Socialite
					AGENT_TYPE_04 = agent_socialite
					AGENT_TYPE_04_WEIGHT = critical_moment_agent_weight_medium_value
					# Musician
					AGENT_TYPE_05 = agent_musician
					AGENT_TYPE_05_WEIGHT = critical_moment_agent_weight_low_value
					# Tumbler
					AGENT_TYPE_06 = agent_tumbler
					AGENT_TYPE_06_WEIGHT = critical_moment_agent_weight_low_value
					# Poet
					AGENT_TYPE_07 = agent_poet
					AGENT_TYPE_07_WEIGHT = critical_moment_agent_weight_low_value
				}
			}
		}
		custom_tooltip = scheme_critical_moments.0001.d.tt

		# The AI selects its agent slots randomly, so it should never re-roll them.
		ai_chance = { base = -1000 }
	}

	# Come back later.
	option = {
		name = scheme_critical_moments.0001.h

		if = {
			limit = {
				scope:scheme = { scheme_agent_charges >= 1 }
			}
			custom_tooltip = scheme_critical_moments.0001.h.tt.some_opportunities
		}
		else = { custom_tooltip = scheme_critical_moments.0001.h.tt.zero_opportunities }

		ai_chance = {
			first_valid = {
				modifier = {
					add = -100
					scope:scheme.scheme_success_chance >= scope:scheme.max_scheme_success_chance
				}
				modifier = {
					add = 50
					always = yes
				}
			}
		}
	}

	after = {
		remove_character_flag = currently_in_scheme_preparations
		scope:scheme = { remove_variable = target_intercept_repeatable_chance }
	}
}

#	Scheme Type B: choose how many opportunities to spend on different ending types.
scheme_critical_moments.0002 = {
	type = character_event
	window = scheme_preparations_event
	title = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:scheme = { is_scheme_category = contract }
				}
				desc = scheme_critical_moments.0001.t.task_contract
			}
			desc = scheme_critical_moments.0001.t.scheme
		}
	}
	desc = scheme_critical_moments.0002.desc
	theme = intrigue
	left_portrait = {
		character = scope:left_portrait
		scripted_animation = scheme_prep_pick_best_stance
	}
	center_portrait = {
		character = scope:centre_portrait
		scripted_animation = scheme_prep_pick_best_stance
	}
	right_portrait = {
		character = scope:right_portrait
		scripted_animation = scheme_prep_pick_best_stance
	}
	# Background overrides.
	## Tabbed one degree further for easy folding.
		## Leverage Contribution
		override_background = {
			trigger = {
				scope:scheme = { scheme_type = leverage_contribution }
			}
			reference = throne_room
		}
		## Raid Estate Scheme.
		override_background = {
			trigger = {
				scope:scheme = { scheme_type = raid_estate }
			}
			reference = estate
		}
		## Romantic schemes.
		override_background = {
			trigger = {
				scope:scheme = { should_use_amorous_scheme_animation_trigger = yes }
			}
			reference = bedchamber
		}
		## Diplo schemes.
		override_background = {
			trigger = {
				scope:scheme = { scheme_skill = diplomacy }
			}
			reference = council_chamber
		}
		## Martial or prowess schemes.
		override_background = {
			trigger = {
				scope:scheme = {
					scheme_skill = martial
					scheme_skill = prowess
				}
			}
			reference = armory
		}
		## Stewardship schemes.
		override_background = {
			trigger = {
				scope:scheme = { scheme_skill = stewardship }
			}
			reference = study
		}
		## Intrigue schemes.
		override_background = {
			trigger = {
				scope:scheme = { scheme_skill = intrigue }
			}
			reference = corridor_night
		}
		## Learning schemes.
		override_background = {
			trigger = {
				scope:scheme = { scheme_skill = learning }
			}
			reference = physicians_study
		}
	# Icon overrides.
	## Tabbed one degree further for easy folding.
		## Diplo schemes.
		override_icon = {
			trigger = {
				scope:scheme = { scheme_skill = diplomacy }
			}
			reference = "gfx/interface/icons/event_types/type_diplomacy.dds"
		}
		## Martial or prowess schemes.
		override_icon = {
			trigger = {
				scope:scheme = {
					scheme_skill = martial
					scheme_skill = prowess
				}
			}
			reference = "gfx/interface/icons/event_types/type_martial.dds"
		}
		## Stewardship schemes.
		override_icon = {
			trigger = {
				scope:scheme = { scheme_skill = stewardship }
			}
			reference = "gfx/interface/icons/event_types/type_stewardship.dds"
		}
		## Intrigue schemes.
		override_icon = {
			trigger = {
				scope:scheme = { scheme_skill = intrigue }
			}
			reference = "gfx/interface/icons/event_types/type_intrigue.dds"
		}
		## Learning schemes.
		override_icon = {
			trigger = {
				scope:scheme = { scheme_skill = learning }
			}
			reference = "gfx/interface/icons/event_types/type_learning.dds"
		}

	# Scheme Preparations status bar
	widget = {
		gui = "event_window_widget_scheme_preparations"
		container = "custom_widgets_container"
	}

	trigger = {
		NOR = {
			has_character_flag = currently_in_scheme_preparations
			has_character_flag = currently_in_scheme_reminder
		}
	}

	immediate = {
		# Flag that we're in the event, so no doubles pls.
		add_character_flag = currently_in_scheme_preparations
		# Sort some aesthetic stuff for the player.
		scheme_critical_moments_0001_configure_portraits_effect = yes
	}

	# Standard completion: no buffs.
	option = {
		name = scheme_critical_moments.0002.a
		show_as_unavailable = { always = yes }
		trigger = {
			custom_tooltip = {
				text = scheme_critical_moments.0002.a.tt.stymied.insufficient_opportunities
				scope:scheme = { scheme_agent_charges >= multi_ending_scheme_charge_to_advance_threshold_t1_value }
			}
			# Tell the AI not to bother unless their chance are at least 50:50.
			trigger_if = {
				limit = {
					is_ai = yes
					# Make sure the AI can get out of long schemes eventually.
					scope:scheme.scheme_duration_days < 3650
				}
				# Must have a good shot.
				OR = {
					scope:scheme.scheme_success_chance >= 50
					AND = {
						is_ruler = no
						scope:scheme.scheme_success_chance >= 20
					}
				}
				# Only consider the best possible option.
				scope:scheme.scheme_agent_charges < multi_ending_scheme_charge_to_advance_threshold_t2_value
			}
		}

		# Scheme gon' try to conclude.
		custom_tooltip = scheme_critical_moments.0001.a.tt.progress
		scheme_critical_moments_0001_execute_scheme_default_flow_effect = { COST = multi_ending_scheme_charge_to_advance_threshold_t1_value }

		ai_chance = { scheme_prep_ai_should_execute_scheme_modifier = yes }

		# SAS Change
		scope:owner = { sas_count_hostile_scheme_and_add_renown = yes }
		# SAS Change End
	}

	# Pricier completion: minor success chance gains.
	option = {
		name = scheme_critical_moments.0002.b
		show_as_unavailable = { always = yes }
		trigger = {
			custom_tooltip = {
				text = scheme_critical_moments.0002.b.tt.stymied.insufficient_opportunities
				scope:scheme = { scheme_agent_charges >= multi_ending_scheme_charge_to_advance_threshold_t2_value }
			}
			# Tell the AI not to bother unless their chance are at least 50:50.
			trigger_if = {
				limit = {
					is_ai = yes
					# Make sure the AI can get out of long schemes eventually.
					scope:scheme.scheme_duration_days < 3650
				}
				# Must have a good shot.
				OR = {
					scope:scheme.scheme_success_chance >= 50
					AND = {
						is_ruler = no
						scope:scheme.scheme_success_chance >= 20
					}
				}
				# Only consider the best possible option.
				scope:scheme.scheme_agent_charges < multi_ending_scheme_charge_to_advance_threshold_t3_value
			}
		}

		# Scheme gon' try to conclude.
		custom_tooltip = scheme_critical_moments.0002.b.tt.progress
		scope:scheme = {
			custom_tooltip = {
				text = scheme_critical_moments.0002.b.tt.clarify_buff
				add_scheme_modifier = { type = scheme_end_buff_t2_modifier }
			}
		}
		scheme_critical_moments_0001_execute_scheme_default_flow_effect = { COST = multi_ending_scheme_charge_to_advance_threshold_t2_value }

		ai_chance = { scheme_prep_ai_should_execute_scheme_modifier = yes }

		# SAS Change
		scope:owner = { sas_count_hostile_scheme_and_add_renown = yes }
		# SAS Change End
	}

	# Very pricey completion: moderate success chance gains.
	option = {
		name = scheme_critical_moments.0002.c
		show_as_unavailable = { always = yes }
		trigger = {
			custom_tooltip = {
				text = scheme_critical_moments.0002.c.tt.stymied.insufficient_opportunities
				scope:scheme = { scheme_agent_charges >= multi_ending_scheme_charge_to_advance_threshold_t3_value }
			}
			# Tell the AI not to bother unless their chance are at least 50:50.
			trigger_if = {
				limit = {
					is_ai = yes
					# Make sure the AI can get out of long schemes eventually.
					scope:scheme.scheme_duration_days < 3650
				}
				# Must have a good shot.
				OR = {
					scope:scheme.scheme_success_chance >= 50
					AND = {
						is_ruler = no
						scope:scheme.scheme_success_chance >= 20
					}
				}
				# Only consider the best possible option.
				scope:scheme.scheme_agent_charges < multi_ending_scheme_charge_to_advance_threshold_t4_value
			}
		}

		# Scheme gon' try to conclude.
		custom_tooltip = scheme_critical_moments.0002.c.tt.progress
		scope:scheme = {
			custom_tooltip = {
				text = scheme_critical_moments.0002.c.tt.clarify_buff
				add_scheme_modifier = { type = scheme_end_buff_t3_modifier }
			}
		}
		scheme_critical_moments_0001_execute_scheme_default_flow_effect = { COST = multi_ending_scheme_charge_to_advance_threshold_t3_value }

		ai_chance = { scheme_prep_ai_should_execute_scheme_modifier = yes }

		# SAS Change
		scope:owner = { sas_count_hostile_scheme_and_add_renown = yes }
		# SAS Change End
	}

	# Max pricey completion: excellent success chance gains.
	option = {
		name = scheme_critical_moments.0002.d
		show_as_unavailable = { always = yes }
		trigger = {
			custom_tooltip = {
				text = scheme_critical_moments.0002.d.tt.stymied.insufficient_opportunities
				scope:scheme = { scheme_agent_charges >= multi_ending_scheme_charge_to_advance_threshold_t4_value }
			}
			# Tell the AI not to bother unless their chance are at least 50:50.
			trigger_if = {
				limit = {
					is_ai = yes
					# Make sure the AI can get out of long schemes eventually.
					scope:scheme.scheme_duration_days < 3650
				}
				scope:scheme = {
					OR = {
						scheme_success_chance >= 50
						AND = {
							scheme_owner = { is_ruler = no }
							scope:scheme.scheme_success_chance >= 20
						}
						AND = {
							scheme_success_chance >= max_scheme_success_chance
							scheme_agent_charges >= multi_ending_scheme_charge_to_advance_threshold_t4_value
						}
					}
				}
			}
		}

		# Scheme gon' try to conclude.
		custom_tooltip = scheme_critical_moments.0002.d.tt.progress
		scope:scheme = {
			custom_tooltip = {
				text = scheme_critical_moments.0002.d.tt.clarify_buff
				add_scheme_modifier = { type = scheme_end_buff_t4_modifier }
			}
		}
		scheme_critical_moments_0001_execute_scheme_default_flow_effect = { COST = multi_ending_scheme_charge_to_advance_threshold_t4_value }

		ai_chance = { scheme_prep_ai_should_execute_scheme_modifier = yes }

		# SAS Change
		scope:owner = { sas_count_hostile_scheme_and_add_renown = yes }
		# SAS Change End
	}

	# Come back later.
	option = {
		name = scheme_critical_moments.0002.e

		if = {
			limit = {
				scope:scheme = { scheme_agent_charges >= 1 }
			}
			custom_tooltip = scheme_critical_moments.0002.e.tt.some_opportunities
		}
		else = { custom_tooltip = scheme_critical_moments.0002.e.tt.zero_opportunities }

		ai_chance = {
			first_valid = {
				modifier = {
					add = -100
					scope:scheme.scheme_success_chance >= scope:scheme.max_scheme_success_chance
				}
				modifier = {
					add = 50
					always = yes
				}
			}
			# If this scheme has been going on for a long time, execute it regardless.
			first_valid = {
				modifier = {
					factor = 0
					scope:scheme = {
						is_scheme_category = contract
						scheme_duration_days >= 1825
					}
				}
				modifier = {
					factor = 0
					has_trait = impatient
					scope:scheme.scheme_duration_days >= 1825
				}
				modifier = {
					factor = 0
					has_trait = patient
					scope:scheme.scheme_duration_days >= 5475
				}
				modifier = {
					factor = 0
					scope:scheme.scheme_duration_days >= 3650
				}
			}
		}
	}

	after = {
		remove_character_flag = currently_in_scheme_preparations
		scope:scheme = { remove_variable = target_intercept_repeatable_chance }
	}
}

#	Error suppression.
scheme_critical_moments.0010 = {
	hidden = yes
	orphan = yes

	immediate = {
		trigger_event = scheme_critical_moments.0001
		trigger_event = scheme_critical_moments.0002
		trigger_event = scheme_critical_moments.1001
		trigger_event = scheme_critical_moments.1011
		save_scope_as = scheme_starter_personal_secrecy
	}
}

##################################################
# Reminders
# by Ewan Cowhig Croft
# 0011 - 0020
##################################################

#	Reminder event that you've hit the opportunities cap.
scheme_critical_moments.0011 = {
	type = character_event
	title = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:scheme = { is_scheme_category = contract }
				}
				desc = scheme_critical_moments.0011.t.task_contract
			}
			desc = scheme_critical_moments.0011.t.scheme
		}
	}
	desc = {
		desc = scheme_critical_moments.0011.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:scheme.scheme_target_character }
				desc = scheme_critical_moments.0011.desc.middle.character
			}
			triggered_desc = {
				trigger = { exists = scope:scheme.scheme_target_title }
				desc = scheme_critical_moments.0011.desc.middle.title
			}
			# If we meet neither of these, we don't use a fallback and just leave the thing empty.
		}
		desc = scheme_critical_moments.0011.desc.outro
	}
	theme = intrigue
	left_portrait = {
		character = root
		scripted_animation = scheme_prep_pick_best_stance
	}
	right_portrait = {
		character = scope:right_portrait
		scripted_animation = scheme_prep_pick_best_stance
	}
	widget = {
		gui = "event_window_widget_scheme"
		container = "custom_widgets_container"
	}

	cooldown = { years = 1 }

	immediate = {
		# Portraits first.
		scope:scheme = {
			if = {
				limit = { is_scheme_target_type = character }
				scheme_target_character = {
					if = {
						limit = {
							this != root
						}
						save_scope_as = right_portrait
					}
				}
			}
			else_if = {
				limit = { is_scheme_target_type = title }
				scheme_target_title.holder ?= {
					if = {
						limit = {
							this != root
						}
						save_scope_as = right_portrait
					}
				}
			}
			else_if = {
				limit = { is_scheme_target_type = faith }
				scheme_target_faith.religious_head ?= {
					if = {
						limit = {
							this != root
						}
						save_scope_as = right_portrait
					}
				}
			}
			else_if = {
				limit = { is_scheme_target_type = culture }
				scheme_target_culture.culture_head ?= {
					if = {
						limit = {
							this != root
						}
						save_scope_as = right_portrait
					}
				}
			}
		}
		# Plus clarify exactly what's happening.
		custom_tooltip = scheme_critical_moments.0011.immediate.tt
	}

	# Max pricey completion: excellent success chance gains.
	option = {
		name = scheme_critical_moments.0011.c
		trigger = {
			custom_tooltip = {
				text = scheme_critical_moments.0002.d.tt.stymied.insufficient_opportunities
				scope:scheme = { scheme_agent_charges >= multi_ending_scheme_charge_to_advance_threshold_t4_value }
			}
			# Only fire this if we've actually got a follow-up event configured.
			exists = scope:follow_up_event
			# Tell the AI not to bother unless their chance are at least 50:50.
			trigger_if = {
				limit = { is_ai = yes }
				scope:scheme = {
					OR = {
						scheme_success_chance >= 50
						AND = {
							scheme_success_chance >= max_scheme_success_chance
							scheme_agent_charges >= multi_ending_scheme_charge_to_advance_threshold_t4_value
						}
					}
				}
			}
		}

		# Scheme gon' try to conclude.
		custom_tooltip = scheme_critical_moments.0002.d.tt.progress
		scope:scheme = {
			custom_tooltip = {
				text = scheme_critical_moments.0002.d.tt.clarify_buff
				add_scheme_modifier = { type = scheme_end_buff_t4_modifier }
			}
		}
		scheme_critical_moments_0001_execute_scheme_default_flow_effect = { COST = multi_ending_scheme_charge_to_advance_threshold_t4_value }

		ai_chance = { scheme_prep_ai_should_execute_scheme_modifier = yes }
	}

	# Noted, and don't remind me again.
	option = {
		name = scheme_critical_moments.0011.a

		custom_tooltip = scheme_critical_moments.0011.a.tt
		set_variable = {
			name = opportunities_reminder
			value = yes
		}
	}

	# Noted.
	option = {
		name = scheme_critical_moments.0011.b

		custom_tooltip = scheme_critical_moments.0011.b.tt
	}

	after = {
		remove_character_flag = currently_in_scheme_reminder
		scope:scheme = { remove_variable = target_intercept_repeatable_chance }
	}
}













##################################################
# CORE SCHEMES

##################################################
# Murder Results
# (shifted here) by Ewan Cowhig Croft
# 1001 - 1010
##################################################

#	Results event for the Murder scheme.
scheme_critical_moments.1001 = {
	hidden = yes

	immediate = {
		scope:scheme = {
			generic_scheme_process_ending_effect = {
				RESULTS_TOOLTIP = murder_successful_roll_tt
				SUCCESS_EVENT_TYPE = on_action
				SUCCESS_EVENT_ID = murder_success_pre_filter_on_action
				FAILURE_EVENT_TYPE = on_action
				FAILURE_EVENT_ID = murder_failure_pre_filter_on_action
			}
		}
	}
}

##################################################
# Seduce Results
# (shifted here) by Ewan Cowhig Croft
# 1011 - 1020
##################################################

#	Results event for the Seduce scheme.
scheme_critical_moments.1011 = {
	hidden = yes

	immediate = {
		# Set up a block for the inappropriate cheating error?
		save_scope_value_as = {
			name = ignore_cheating_error_check
			value = yes
		}
		# Proceed to rolls.
		scope:scheme.scheme_owner = {
			#Do I want to proceed to a roll?
			if = {
				limit = {
					is_ai = no
					use_seduce_secrecy_trigger = {
						TARGET = scope:target
						OWNER = scope:owner
					}
				}
				trigger_event = seduce_outcome.0001
			}
			#Jump straight to roll
			else = {
				trigger_event = seduce_outcome.0002
			}
		}
	}
}

##################################################
# Sway Results
# (shifted here) by Ewan Cowhig Croft
# 1021 - 1030
##################################################

#	Results event for the Sway scheme.
scheme_critical_moments.1021 = {
	hidden = yes

	immediate = {
		random = {
			chance = scope:scheme.scheme_success_chance

			save_scope_value_as = {
				name = scheme_successful
				value = yes
			}
		}
		scope:owner = {
			if = {
				limit = {
					exists = scope:scheme_successful
				}
				mandala_trickster_increment_successful_schemes_effect = yes
				trigger_event = {
					on_action = sway_success
				}
			}
			else = {
				trigger_event = {
					on_action = sway_failure
				}
			}
		}
	}
}

##################################################
# Befriend Results
# (shifted here) by Ewan Cowhig Croft
# 1031 - 1040
##################################################

#	Results event for the Befriend scheme.
scheme_critical_moments.1031 = {
	hidden = yes

	immediate = {
		#Outcome system by Mathilda Bjarnehed
		scope:scheme.scheme_owner = {
			trigger_event = befriend_outcome.0001 #Hidden event rolling success/failure, discover/no discovery and sending on_actions or player choice event
		}
	}
}

##################################################
# Court Results
# (shifted here) by Ewan Cowhig Croft
# 1041 - 1050
##################################################

#	Results event for the Court scheme.
scheme_critical_moments.1041 = {
	hidden = yes

	immediate = {
		scope:scheme = {
			# Set up a block for the inappropriate cheating error?
			save_scope_value_as = {
				name = ignore_cheating_error_check
				value = yes
			}
			# Proceed to rolls.
			scheme_owner = {
				#DISCOVERY ROLL
				save_scope_value_as = {
					name = discovery_chance
					value = {
						value = 100
						subtract = scope:scheme.scheme_secrecy
					}
				}
				random = {
					chance = scope:discovery_chance
					save_scope_value_as = {
						name = scheme_discovered
						value = yes
					}
				}

				#SUCCESS ROLL
				random = {
					chance = scope:scheme.scheme_success_chance

					save_scope_value_as = {
						name = scheme_successful
						value = yes
					}
					mandala_trickster_increment_successful_schemes_effect = yes
				}

				#CONTINUE WITH OUTCOME ON_ACTION FOR AI TARGETS
				if = {
					limit = { scope:target = { is_ai = yes } }

					trigger_event = {
						on_action = court_outcome
					}
				}
				#FOR PLAYER CHARACTER, SEND CHOICE EVENT
				else = {
					scope:target = {
						trigger_event = {
							id = court_outcome.0003
						}
					}
				}
			}
		}
	}
}

##################################################
# Elope Results
# (shifted here) by Ewan Cowhig Croft
# 1051 - 1060
##################################################

#	Results event for the Elope scheme.
scheme_critical_moments.1051 = {
	hidden = yes

	immediate = {
		scope:scheme.scheme_owner = {
			#Do I want to proceed to a roll?
			if = {
				limit = {
					is_ai = no
				}
				trigger_event = elope.0001
			}
			#Jump straight to roll
			else = {
				trigger_event = elope.0002
			}
		}
	}
}

##################################################
# Abduct Results
# (shifted here) by Ewan Cowhig Croft
# 1061 - 1070
##################################################

#	Results event for the Abduct scheme.
scheme_critical_moments.1061 = {
	hidden = yes

	immediate = {
		scope:scheme.scheme_owner = {
			if = {
				limit = {
					has_character_flag = is_in_event_abduct_outcome_0001
				}
				trigger_event = {
					id = abduct_outcome.0001
					days = 1
				}
			}
			else = {
				trigger_event = abduct_outcome.0001
			}
		}
	}
}

##################################################
# Fabricate Claim Results
# (shifted here) by Ewan Cowhig Croft
# 1071 - 1080
##################################################

#	Results event for the Fabricate Claim scheme.
scheme_critical_moments.1071 = {
	hidden = yes

	immediate = {
		scope:scheme = {
			# Do the Success Roll
			random = {
				chance = scheme_success_chance
				save_scope_value_as = {
					name = scheme_succeeded
					value = yes
				}
			}
			# Do the Secrecy Roll
			save_scope_value_as = {
				name = discovery_chance
				value = {
					value = 100
					subtract = scheme_secrecy
				}
			}
			random = {
				chance = scope:discovery_chance
				save_scope_value_as = {
					name = scheme_discovered
					value = yes
				}
			}

			# On Success: Check for viable Secret
			if = {
				limit = { exists = scope:scheme_succeeded }
				scheme_target_character = {
					if = {
						limit = { is_ruler = yes }
						# Check for secrets that can be revealed
						if = {
							limit = {
								any_secret = {
									NOT = { is_known_by = scope:owner }
								}
							}
							random_secret = {
								limit = {
									NOT = { is_known_by = scope:owner }
								}
								weight = {
									base = 1
									modifier = { # It's more fun to Discover a Criminal Secret
										add = 5
										is_criminal_for = scope:target
									}
								}
								save_scope_as = secret_to_reveal
							}
						}
						else_if = { # Others require Criminal Secrets
							limit = {
								any_secret = {
									NOT = { is_known_by = scope:owner }
									is_criminal_for = scope:target
								}
							}
							random = {
								chance = 20
								random_secret = {
									limit = {
										NOT = { is_known_by = scope:owner }
										is_criminal_for = scope:target
									}
									save_scope_as = secret_to_reveal
								}
							}
						}
					}
					else = {
						if = {
							limit = {
								any_secret = {
									NOT = { is_known_by = scope:owner }
									is_criminal_for = scope:target
								}
							}
							random_secret = {
								limit = {
									NOT = { is_known_by = scope:owner }
									is_criminal_for = scope:target
								}
								save_scope_as = secret_to_reveal
							}
						}
					}
				}
				scheme_owner = { mandala_trickster_increment_successful_schemes_effect = yes }

				if = {
					limit = { exists = scope:secret_to_reveal }
					scheme_owner = {
						trigger_event = fabricate_hook_outcome.0001 # Secret discovery handling
					}
				}
				else = {
					if = {
						limit = { scope:target = { is_ruler = yes } }
						# Strong Hook against Ruler roll
						random = {
							# SAS Change
							# chance = 20
							chance = 25
							modifier = {
								add = {
									value = 10
									multiply = scope:owner.court_position:femme_fatale_court_position.aptitude:femme_fatale_court_position
									add = 10
								}
								scope:owner = {
									employs_court_position = femme_fatale_court_position
								}
							}
							# SAS Change End
							save_scope_value_as = {
								name = strong_hook_against_ruler
								value = yes
							}
						}
					}
					scheme_owner = {
						trigger_event = {
							on_action = fabricate_hook_method_success_outcome
						}
					}
				}
			}

			else = {
				if = {
					limit = { exists = scope:scheme_discovered }
					scheme_owner = {
						trigger_event = fabricate_hook_outcome.3001
					}
				}
				else = {
					scheme_owner = {
						send_interface_message = {
							type = fabricate_hook_bad_message
							title = fabricate_hook_failed_reset_message
							scope:scheme = {
								reset_failed_scheme_effect = yes
							}
						}
					}
				}
			}
		}
	}
}

##################################################
# Learn Language Results
# (shifted here) by Ewan Cowhig Croft
# 1081 - 1090
##################################################

#	Results event for the Learn Language scheme.
scheme_critical_moments.1081 = {
	hidden = yes

	immediate = {
		scope:scheme = {
			random = {
				chance = scope:scheme.scheme_success_chance

				save_scope_value_as = {
					name = scheme_successful
					value = yes
				}
			}
			scope:owner = {
				if = {
					limit = {
						exists = scope:scheme_successful
					}
					mandala_trickster_increment_successful_schemes_effect = yes
					trigger_event = {
						on_action = learn_language_success
					}
				}
				else = {
					trigger_event = {
						on_action = learn_language_failure
					}
				}
			}
		}
	}
}

##################################################
# Abduct Regent Results
# (shifted here) by Ewan Cowhig Croft
# 1091 - 1100
##################################################

#	Results event for the Abduct Regent scheme.
scheme_critical_moments.1091 = {
	hidden = yes

	immediate = {
		scope:scheme.scheme_owner = {
			if = {
				limit = {
					has_character_flag = is_in_event_diarchy_0501
				}
				trigger_event = {
					id = diarchy.0501
					days = 1
				}
			}
			else = { trigger_event = diarchy.0501 }
		}
	}
}

##################################################
# Claim Throne Results
# (shifted here) by Ewan Cowhig Croft
# 1101 - 1110
##################################################

#	Results event for the Claim Throne scheme.
scheme_critical_moments.1101 = {
	hidden = yes

	immediate = {
		scope:scheme = {
			scheme_target_character.primary_title = { save_scope_as = target_title }
			scheme_owner = {
				if = {
					limit = {
						has_character_flag = is_executing_claim_throne
					}
					trigger_event = {
						on_action = claim_throne_setup
						days = 1
					}
				}
				else = {
					trigger_event = {
						on_action = claim_throne_setup
					}
				}
			}
		}
	}
}

##################################################
# Steal Back Artefact Results
# (shifted here) by Ewan Cowhig Croft
# 1111 - 1120
##################################################

#	Results event for the Steal Back Artefact scheme.
scheme_critical_moments.1111 = {
	hidden = yes

	immediate = {
		scope:scheme = {
			random = {
				chance = scope:scheme.scheme_success_chance

				save_scope_value_as = {
					name = scheme_successful
					value = yes
				}
			}
			scope:owner = {
				if = {
					limit = {
						exists = scope:scheme_successful
					}
					mandala_trickster_increment_successful_schemes_effect = yes
					trigger_event = {
						on_action = steal_back_artifact_success
					}
				}
				else = {
					trigger_event = {
						on_action = steal_back_artifact_failure
					}
				}
			}
		}
	}
}

##################################################
# Convert to Witchcraft Results
# (shifted here) by Ewan Cowhig Croft
# 1121 - 1130
##################################################

#	Results event for the Convert to Witchcraft scheme.
scheme_critical_moments.1121 = {
	hidden = yes

	immediate = {
		scope:scheme = {
			scheme_owner = {
				#DISCOVERY ROLL
				save_scope_value_as = {
					name = discovery_chance
					value = {
						value = 100
						subtract = scope:scheme.scheme_secrecy
					}
				}
				random = {
					chance = scope:discovery_chance
					save_scope_value_as = {
						name = scheme_discovered
						value = yes
					}
				}

				#SUCCESS ROLL
				random = {
					chance = scope:scheme.scheme_success_chance

					save_scope_value_as = {
						name = scheme_successful
						value = yes
					}
					mandala_trickster_increment_successful_schemes_effect = yes
				}

				#SECRECY: DO I WANT TO PROCEED?
				if = {
					limit = {
						use_convert_to_witchcraft_secrecy_trigger = { OWNER = scope:scheme.scheme_owner }
					}
					trigger_event = witch.2001
				}
				#CONTINUE WITH OUTCOME ON_ACTION FOR AI TARGETS
				else_if = {
					limit = { scope:target = { is_ai = yes } }

					if = {
						limit = { exists = scope:scheme_successful }
						trigger_event = witch.2003 #Success event
					}
					else = {
						trigger_event = {
							on_action = convert_to_witchcraft_failure_outcome
						}
					}
				}
				#FOR PLAYER CHARACTER, SEND CHOICE EVENT
				else = {
					scope:target = {
						trigger_event = witch.2002
					}
				}
			}
		}
	}
}

##################################################
# Slander Results
# Claudia Baldassi
# 1131 - 1140
##################################################

#	Results event for the Slander scheme.
scheme_critical_moments.1131 = {
	hidden = yes

	immediate = {
		scope:scheme = {
			scheme_target_character = { save_scope_as = target }
			scheme_owner = {
				save_scope_as = owner
				#DISCOVERY ROLL
				save_scope_value_as = {
					name = discovery_chance
					value = {
						value = 100
						subtract = scope:scheme.scheme_secrecy
					}
				}
				random = {
					chance = scope:discovery_chance
					save_scope_value_as = {
						name = scheme_discovered
						value = yes
					}
				}

				#SUCCESS ROLL
				random = {
					chance = scope:scheme.scheme_success_chance

					save_scope_value_as = {
						name = scheme_successful
						value = yes
					}
					mandala_trickster_increment_successful_schemes_effect = yes
				}

				if = {
					limit = {
						exists = scope:scheme_successful
					}
					trigger_event = {
						id = scheme_critical_moments.1132
						days = 1
					}
				}
				else = {
					trigger_event = {
						id = scheme_critical_moments.1133
						days = 1
					}
				}
			}
		}
	}
}

#Success
scheme_critical_moments.1132 = {
	type = character_event
	title = scheme_critical_moments.1132.t
	desc = {
		desc = scheme_critical_moments.1132.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:scheme_discovered
				}
				desc = scheme_critical_moments.1132.desc_discovered
			}
			desc = scheme_critical_moments.1132.desc_secret
		}
	}
	theme = diplomacy
	left_portrait = {
		character = root
		animation = scheme
	}
	lower_right_portrait = scope:target

	immediate = {
		# Trigger the response event for the target
		show_as_tooltip = {	# Effects on target (applied in the response events)
			scope:target = {
				change_influence = major_influence_loss
				custom_tooltip = scheme_slandered_candidacy_appointment_tt
				custom_tooltip = scheme_slandered_candidacy_acclamation_tt
				add_character_modifier = {
					modifier = scheme_slandered_modifier
					years = 10
					desc = scheme_slandered_candidacy_desc
				}
			}
		}
		if = {
			limit = {
				exists = scope:scheme_discovered
			}
			show_as_tooltip = { # Effects on target if discovered (applied in the response events)
				scope:target = {
					add_opinion = {
						target = scope:owner
						modifier = slandered_me_opinion
					}
				}
			}
		}
		# Trigger a catalyst if target has a lot of power
		if = {
			limit = {
				exists = scope:target.var:movement_power
				scope:target.var:movement_power >= medium_movement_power_value
			}
			tgp_activate_catalyst_against_hegemon_effect = {
				HEGEMON = scope:target.top_liege
				CATALYST = catalyst_governor_slander
			}
		}
	}

	option = {
		name = scheme_critical_moments.1132.a
		scope:scheme = {
			end_scheme = yes
		}
		random_list = {
			10 = {
				send_interface_toast = {
					title = slander_nickname_given_tt
					left_icon = scope:target
					custom_tooltip = receive_slanderous_nickname_tt
				}
				scope:target = {
					add_character_flag = {
						flag = slander_nickname_flag
						years = 1
					}
				}
			}
			40 = {
				# you find nothing else
			}
		}
	}
	after = {
		scope:target = {
			trigger_event = scheme_critical_moments.1134
		}
	}
}

#Failure
scheme_critical_moments.1133 = {
	type = character_event
	title = scheme_critical_moments.1133.t
	desc = {
		desc = scheme_critical_moments.1133.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:scheme_discovered
				}
				desc = scheme_critical_moments.1133.desc_discovered
			}
			desc = scheme_critical_moments.1133.desc_secret
		}
	}
	theme = diplomacy
	left_portrait = {
		character = root
		animation = disappointed
	}
	lower_right_portrait = scope:target

	immediate = {
		hidden_effect = {
			if = {
				limit = {
					exists = scope:scheme_discovered
				}
				scope:target = {
					send_interface_message = {
						type = event_scheme_bad
						title = scheme_critical_moments.1133.tt
						custom_tooltip = scheme_critical_moments.1133.tt.failed
					}
				}
			}
		}
		stress_impact = {
			base = minor_stress_impact_gain
			ambitious = minor_stress_impact_gain
			deceitful = minor_stress_impact_gain
		}
	}

	#Option A: Too bad
	option = {
		name = scheme_critical_moments.1133.a
		scope:scheme = {
			end_scheme = yes
		}
	}
}

# Target reaction
scheme_critical_moments.1134 = {
	type = character_event
	title = scheme_critical_moments.1134.t
	desc = {
		desc = scheme_critical_moments.1134.desc
		triggered_desc = {
			trigger = {
				has_character_flag = slander_nickname_flag
			}
			desc = scheme_critical_moments.1134.desc_given_nickname
		}
		triggered_desc = {
			trigger = {
				exists = scope:scheme_discovered
			}
			desc = scheme_critical_moments.1134.desc_discovered
		}
	}
	theme = diplomacy
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = {
				exists = scope:scheme_discovered
			}
			animation = disbelief
		}
		animation = paranoia
	}
	lower_right_portrait = scope:owner

	immediate = {
		change_influence = major_influence_loss
		custom_tooltip = scheme_slandered_candidacy_appointment_tt
		custom_tooltip = scheme_slandered_candidacy_acclamation_tt
		add_character_modifier = {
			modifier = scheme_slandered_modifier
			years = 10
			desc = scheme_slandered_candidacy_desc
		}
		if = {
			limit = {
				exists = scope:scheme_discovered
				is_ai = yes
			}
			add_opinion = {
				target = scope:owner
				modifier = slandered_me_opinion
			}
		}
		if = {
			limit = {
				has_character_flag = slander_nickname_flag
			}
			set_random_negative_nickname_effect = yes
		}
	}

	option = {
		name = scheme_critical_moments.1134.a
	}
	after = {
		if = {
			limit = {
				has_character_flag = slander_nickname_flag
			}
			remove_character_flag = slander_nickname_flag
		}
	}
}

##################################################
# Promote Results
# Claudia Baldassi
# 1141 - 1150
##################################################

#	Results event for the Promote scheme.
scheme_critical_moments.1141 = {
	hidden = yes

	immediate = {
		scope:scheme = {
			scheme_target_character = { save_scope_as = target }
			scheme_owner = {
				save_scope_as = owner

				#SUCCESS ROLL
				random = {
					chance = scope:scheme.scheme_success_chance

					save_scope_value_as = {
						name = scheme_successful
						value = yes
					}
					mandala_trickster_increment_successful_schemes_effect = yes
				}

				if = {
					limit = {
						exists = scope:scheme_successful
					}
					trigger_event = {
						id = scheme_critical_moments.1142
						days = 1
					}
				}
				else = {
					trigger_event = {
						id = scheme_critical_moments.1143
						days = 1
					}
				}
			}
		}
	}
}

#Success
scheme_critical_moments.1142 = {
	type = character_event
	title = scheme_critical_moments.1142.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:target = scope:owner
				}
				desc = scheme_critical_moments.1142.desc_self
			}
			desc = scheme_critical_moments.1142.desc_other
		}
	}
	theme = diplomacy
	left_portrait = {
		character = root
		animation = personality_content
	}
	lower_right_portrait = {
		trigger = {
			scope:target != scope:owner
		}
		character = scope:target
	}

	immediate = {
		scope:target = {
			add_character_modifier = {
				modifier = scheme_promoted_modifier
				years = 10
			}
			if = {
				limit = {
					is_ai = yes
					this != scope:owner
				}
				add_opinion = {
					target = scope:owner
					modifier = promoted_me_opinion
				}
			}
		}
		hidden_effect = {
			if = {
				limit = {
					scope:owner != scope:target
				}
				scope:target = {
					send_interface_message = {
						type = msg_promoted_scheme
						title = scheme_critical_moments.1142.tt
						desc = promote_toast_scheme_desc
						left_icon = scope:owner
						show_as_tooltip = {
							add_character_modifier = {
								modifier = scheme_promoted_modifier
								years = 10
							}
						}
					}
				}
			}
		}
	}

	option = {
		name = scheme_critical_moments.1142.a
		scope:scheme = {
			end_scheme = yes
		}
	}
}

#Failure
scheme_critical_moments.1143 = {
	type = character_event
	title = scheme_critical_moments.1143.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:target = scope:owner
				}
				desc = scheme_critical_moments.1143.desc_self
			}
			desc = scheme_critical_moments.1143.desc_other
		}
	}
	theme = diplomacy
	left_portrait = {
		character = root
		animation = disapproval
	}
	lower_right_portrait = {
		trigger = {
			scope:target != scope:owner
		}
		character = scope:target
	}

	option = {
		name = scheme_critical_moments.1143.a
		scope:scheme = {
			end_scheme = yes
		}
	}
}

##################################################
# Generate Claim Results
# Claudia Baldassi
# 1151 - 1160
##################################################

#	Results event for the Generate Claim scheme.
scheme_critical_moments.1151 = {
	hidden = yes

	immediate = {
		scope:scheme = {
			scheme_target_title = { save_scope_as = target }
			scheme_owner = {
				save_scope_as = owner

				#DISCOVERY ROLL
				save_scope_value_as = {
					name = discovery_chance
					value = {
						value = 100
						subtract = scope:scheme.scheme_secrecy
					}
				}
				random = {
					chance = scope:discovery_chance
					save_scope_value_as = {
						name = scheme_discovered
						value = yes
					}
				}

				#SUCCESS ROLL
				random = {
					chance = scope:scheme.scheme_success_chance

					save_scope_value_as = {
						name = scheme_successful
						value = yes
					}
					mandala_trickster_increment_successful_schemes_effect = yes
				}

				if = {
					limit = {
						exists = scope:scheme_successful
					}
					trigger_event = {
						id = scheme_critical_moments.1152
						days = 1
					}
				}
				else = {
					trigger_event = {
						id = scheme_critical_moments.1153
						days = 1
					}
				}
			}
		}
	}
}

#Success
scheme_critical_moments.1152 = {
	type = character_event
	title = scheme_critical_moments.1152.t
	desc = {
		desc = scheme_critical_moments.1152.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:scheme_discovered
				}
				desc = scheme_critical_moments.1152.desc_discovered
			}
			desc = scheme_critical_moments.1152.desc_secret
		}
	}
	theme = learning
	left_portrait = {
		character = root
		animation = scheme
	}
	lower_right_portrait = scope:title_holder

	immediate = {
		# It needs to be pressed to unlock Contest Appointment.
		add_pressed_claim = scope:target
		if = {
			limit = {
				scope:target = {
					holder ?= { is_ai = yes }
				}
				exists = scope:scheme_discovered
			}
			scope:target.holder = {
				save_scope_as = title_holder
				add_opinion = {
					target = scope:owner
					modifier = claimed_my_title_opinion
					opinion = -30
				}
			}
		}
	}

	option = {
		name = scheme_critical_moments.1152.a
		if = {
			limit = {
				has_government = landless_adventurer_government
			}
			trigger_event = laamp_extra_contract_schemes.0030
		}
		else = {
			scope:scheme = {
				end_scheme = yes
			}
		}
	}
}

#Failure
scheme_critical_moments.1153 = {
	type = character_event
	title = scheme_critical_moments.1153.t
	desc = {
		desc = scheme_critical_moments.1153.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:scheme_discovered
				}
				desc = scheme_critical_moments.1153.desc_discovered
			}
			desc = scheme_critical_moments.1153.desc_secret
		}
	}
	theme = learning
	left_portrait = {
		character = root
		animation = disapproval
	}
	lower_right_portrait = scope:title_holder

	immediate = {
		if = {
			limit = {
				scope:target = {
					holder ?= { is_ai = yes }
				}
				exists = scope:scheme_discovered
			}
			scope:target.holder = {
				save_scope_as = title_holder
				add_opinion = {
					target = scope:owner
					modifier = claimed_my_title_opinion
					opinion = -30
				}
			}
		}
	}

	option = {
		name = scheme_critical_moments.1153.a
		if = {
			limit = {
				has_government = landless_adventurer_government
			}
			scope:scheme.task_contract = {
				complete_task_contract = failure_standard
			}
		}
		scope:scheme = {
			end_scheme = yes
		}
	}
}

##################################################
# Steal Herd
# Ariana Tranumn
# 1161 - 1170
##################################################

#	Results event for the Steal Herd scheme.
scheme_critical_moments.1161 = {
	hidden = yes

	immediate = {
		scope:scheme = {
			random = {
				chance = scope:scheme.scheme_success_chance

				save_scope_value_as = {
					name = scheme_successful
					value = yes
				}
			}
			scope:owner = {
				mandala_trickster_increment_successful_schemes_effect = yes
				if = {
					limit = {
						exists = scope:scheme_successful
					}
					trigger_event = {
						on_action = steal_herd_success
					}
				}
				else = {
					trigger_event = {
						on_action = steal_herd_failure
					}
				}
			}
		}
	}
}

##################################################
# Challenge Status Results
# Claudia Baldassi
# 1171 - 1180
##################################################

#	Results event for the Challenge Status scheme.
scheme_critical_moments.1171 = {
	hidden = yes

	immediate = {
		scope:scheme = {
			scheme_target_character = {
				save_scope_as = target
				save_scope_as = recipient
			}
			scheme_owner = {
				save_scope_as = owner

				#SUCCESS ROLL
				random = {
					chance = scope:scheme.scheme_success_chance

					save_scope_value_as = {
						name = scheme_successful
						value = yes
					}
					mandala_trickster_increment_successful_schemes_effect = yes
				}

				if = {
					limit = {
						exists = scope:scheme_successful
					}
					trigger_event = {
						id = scheme_critical_moments.1172
						days = 1
					}
				}
				else = {
					trigger_event = {
						id = scheme_critical_moments.1173
						days = 1
					}
				}
			}
		}
	}
}

#Success
scheme_critical_moments.1172 = {
	type = character_event
	title = scheme_critical_moments.1172.t
	desc = scheme_critical_moments.1172.desc
	theme = learning
	left_portrait = {
		character = root
		animation = happy_teacher
	}
	right_portrait = {
		character = scope:target
		animation = stress
	}

	immediate = {
		scope:target = {
			save_scope_as = recipient # To fix loc
			set_variable = {
				name = challenge_status_influence_loss
				value = {
					value = 50
					add = scope:scheme.scheme_success_chance
				}
			}
		}
		tgp_activate_catalyst_against_hegemon_effect = {
			HEGEMON = scope:target.top_liege
			CATALYST = catalyst_governor_challenged_status
		}
	}

	option = {
		name = scheme_critical_moments.1172.a
		show_as_tooltip = {
			scope:target = {
				change_influence = {
					value = scope:target.var:challenge_status_influence_loss
					multiply = -1
				}
			}
			custom_tooltip = status_challenged_success_tt
			scope:owner = {
				change_influence = {
					value = scope:target.var:challenge_status_influence_loss
				}
			}
		}
		scope:scheme = {
			end_scheme = yes
		}
	}

	after = {
		scope:target = {
			trigger_event = scheme_critical_moments.1174
		}
	}
}

#Failure
scheme_critical_moments.1173 = {
	type = character_event
	title = scheme_critical_moments.1173.t
	desc = scheme_critical_moments.1173.desc
	theme = learning
	left_portrait = {
		character = root
		animation = stressed_teacher
	}
	lower_right_portrait = scope:target

	option = {
		name = scheme_critical_moments.1173.a
		scope:scheme = {
			end_scheme = yes
		}
	}
}

#Target notification
scheme_critical_moments.1174 = {
	type = character_event
	title = scheme_critical_moments.1174.t
	desc = scheme_critical_moments.1174.desc
	theme = learning
	left_portrait = {
		character = root
		animation = stress
	}
	right_portrait = {
		character = scope:owner
		animation = laugh
	}

	immediate = {
		scope:target = { save_scope_as = recipient } # To fix loc
		change_influence = {
			value = scope:target.var:challenge_status_influence_loss
			multiply = -1
		}
		custom_tooltip = {
			text = status_challenged_success_tt
			house = {
				if = {

				}
				add_to_variable_list = {
					name = status_challenged_by
					target = scope:owner
					years = 10
				}
			}
		}
		scope:owner = {
			change_influence = {
				value = scope:target.var:challenge_status_influence_loss
			}
		}
	}

	option = {
		name = scheme_critical_moments.1174.a
	}

	after = {
		remove_variable = challenge_status_influence_loss
	}
}

##################################################
# Expand Power Base Results
# Claudia Baldassi
# 1181 - 1190
##################################################

#	Results event for the Expand Power Base scheme.
scheme_critical_moments.1181 = {
	hidden = yes

	immediate = {
		scope:scheme = {
			scheme_owner = {
				save_scope_as = owner

				#SUCCESS ROLL
				random = {
					chance = scope:scheme.scheme_success_chance

					save_scope_value_as = {
						name = scheme_successful
						value = yes
					}
					mandala_trickster_increment_successful_schemes_effect = yes
				}

				if = {
					limit = {
						exists = scope:scheme_successful
					}
					trigger_event = {
						id = scheme_critical_moments.1182
						days = 1
					}
				}
				else = {
					trigger_event = {
						id = scheme_critical_moments.1183
						days = 1
					}
				}
			}
		}
	}
}

#Success
scheme_critical_moments.1182 = {
	type = character_event
	title = scheme_critical_moments.1182.t
	desc = scheme_critical_moments.1182.desc
	theme = stewardship
	left_portrait = {
		character = root
		animation = schadenfreude
	}

	immediate = {
		duel = {
			skills = { stewardship intrigue }
			value = medium_skill_rating
			60 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
				}
				add_character_modifier = {
					modifier = ep3_expanded_power_base_minor_modifier
					years = 10
				}
			}
			30 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
				}
				add_character_modifier = {
					modifier = ep3_expanded_power_base_medium_modifier
					years = 10
				}
			}
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
				}
				add_character_modifier = {
					modifier = ep3_expanded_power_base_major_modifier
					years = 10
				}
			}
		}
	}

	option = {
		name = scheme_critical_moments.1182.a
		scope:scheme = {
			end_scheme = yes
		}
	}
}

#Failure
scheme_critical_moments.1183 = {
	type = character_event
	title = scheme_critical_moments.1183.t
	desc = scheme_critical_moments.1183.desc
	theme = stewardship
	left_portrait = {
		character = root
		animation = disapproval
	}

	option = {
		name = scheme_critical_moments.1183.a
		scope:scheme = {
			end_scheme = yes
		}
	}
}

##################################################
# Depose Results
# Chad Uhl
# 1191 - 1200
##################################################

#	Results event for the Depose scheme.
scheme_critical_moments.1191 = {
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = grand_ambitions.0200
			FAILURE_EVENT = grand_ambitions.0250
		}
	}
}

##################################################
# Siphon Treasury Results
# Arkadiusz Majewski
# 1201 - 1210
##################################################

#	Results event for the Siphon Treasury scheme.
scheme_critical_moments.1201 = {
	hidden = yes

	immediate = {
		scope:scheme = {
			scheme_target_title = {
				save_scope_as = target
			}
			scheme_owner = {
				save_scope_as = owner
				#DISCOVERY ROLL
				save_scope_value_as = {
					name = discovery_chance
					value = {
						value = 100
						subtract = scope:scheme.scheme_secrecy
						if = {
							limit = {
								scope:owner = scope:target.holder
							}
							multiply = 0
						}
					}
				}
				random = {
					chance = scope:discovery_chance
					save_scope_value_as = {
						name = scheme_discovered
						value = yes
					}
				}
			}
		}
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = scheme_critical_moments.1202
			FAILURE_EVENT = scheme_critical_moments.1203
		}
	}
}

#Success
scheme_critical_moments.1202 = {
	type = character_event
	title = scheme_critical_moments.1202.t
	desc = {
		desc = scheme_critical_moments.1202.desc
		triggered_desc = {
			trigger = { exists = scope:scheme_discovered }
			desc = scheme_critical_moments.1202.desc_discovered
		}
	}
	theme = stewardship
	left_portrait = {
		character = root
		animation = personality_greedy
	}
	right_portrait = {
		trigger = { exists = scope:scheme_discovered }
		character = scope:target.holder
		animation = rage
	}

	option = {
		name = scheme_critical_moments.1202.a
		trigger = { NOT = { exists = scope:scheme_discovered } }
		scope:scheme = {
			change_variable = {
				name = embezzlement_stake
				add = var:embezzlement_stake_initial
			}
		}
		if = {
			limit = {
				scope:scheme.var:siphon_destination ?= flag:treasury
				has_treasury = yes
			}
			add_treasury = scope:scheme.var:embezzlement_stake_initial
		}
		else = {
			add_gold = scope:scheme.var:embezzlement_stake_initial
		}
		scope:target.holder = {
			remove_treasury = scope:scheme.var:embezzlement_stake_initial
		}
	}

	option = {
		name = scheme_critical_moments.1202.b
	}

	after = {
		custom_tooltip = celestial_siphon_treasury_interaction.total_value
		if = {
			limit = {
				NOT = { exists = scope:scheme_discovered }
			}
			add_secret = {
				type = secret_siphoned_treasury
				target = scope:target.holder
			}
			random_secret = {
				limit = {
					secret_type = secret_siphoned_treasury
					secret_target = scope:target.holder
				}
				set_variable = {
					name = embezzlement_stake
					value = scope:scheme.var:embezzlement_stake
				}
			}
		}
		else_if = {
			limit = {
				scope:target.holder != scope:owner
			}
			scope:target.holder = {
				add_opinion = {
					target = scope:owner
					modifier = siphoned_treasury_crime
				}
			}
		}
		scope:scheme = {
			end_scheme = yes
		}
	}
}

#Failure
scheme_critical_moments.1203 = {
	type = character_event
	title = scheme_critical_moments.1203.t
	desc = {
		triggered_desc = {
			trigger = { NOT = { exists = scope:scheme_discovered } }
			desc = scheme_critical_moments.1203.desc_secret
		}
		triggered_desc = {
			trigger = { exists = scope:scheme_discovered }
			desc = scheme_critical_moments.1203.desc_discovered
		}
	}
	theme = stewardship
	left_portrait = {
		character = root
		animation = anger
	}

	immediate = {
		if = {
			limit = {
				scope:target.holder = {
					has_title = title:h_china
				}
			}
			tgp_activate_catalyst_against_hegemon_effect = {
				HEGEMON = scope:target.holder
				CATALYST = catalyst_governor_embezzlement
			}
		}
		else_if = {
			limit = {
				has_title = title:h_china
			}
			add_legitimacy_effect = { LEGITIMACY = medium_legitimacy_loss }
		}
		if = {
			limit = {
				exists = scope:scheme_discovered
			}
			scope:target.holder = {
				add_opinion = {
					target = scope:owner
					modifier = siphoned_treasury_crime
				}
			}
		}
		else = {
			add_secret = {
				type = secret_siphoned_treasury
				target = scope:target.holder
			}
			random_secret = {
				limit = {
					secret_type = secret_siphoned_treasury
					secret_target = scope:target.holder
				}
				set_variable = {
					name = embezzlement_stake
					value = scope:scheme.var:embezzlement_stake
				}
			}
		}
	}

	option = {
		name = scheme_critical_moments.1203.a
		scope:scheme = {
			end_scheme = yes
		}
	}
}

##################################################
# Disbelieve Mandala Results
# 1211 - 1220
##################################################

#Results event for the Disbelieve Mandala scheme
scheme_critical_moments.1211 = {
	hidden = yes

	immediate = {
		scope:scheme = {
			scheme_target_character = { save_scope_as = target }
			scheme_owner = {
				save_scope_as = owner
				#DISCOVERY ROLL
				save_scope_value_as = {
					name = discovery_chance
					value = {
						value = 100
						subtract = scope:scheme.scheme_secrecy
					}
				}
				random = {
					chance = scope:discovery_chance
					save_scope_value_as = {
						name = scheme_discovered
						value = yes
					}
				}

				#SUCCESS ROLL
				random = {
					chance = scope:scheme.scheme_success_chance

					save_scope_value_as = {
						name = scheme_successful
						value = yes
					}
					mandala_trickster_increment_successful_schemes_effect = yes
				}

				if = {
					limit = {
						exists = scope:scheme_successful
					}
					trigger_event = {
						id = scheme_critical_moments.1212
						days = 1
					}
				}
				else = {
					trigger_event = {
						id = scheme_critical_moments.1213
						days = 1
					}
				}
			}
		}
	}
}

scripted_effect result_success_disbelieve_mandala_effect = {
	add_character_modifier = {
		modifier = disbelieved_mandala_modifier
		years = 10
	}
	add_piety = {
		value = {
			value = medium_piety_value
			multiply = scope:target.piety_level
			multiply = -1
		}
	}
	add_legitimacy = medium_legitimacy_loss
}

scripted_effect result_discovered_disbelieve_mandala_effect = {
	if = {
		limit = {
			has_relation_rival = scope:owner
			can_set_relation_nemesis_trigger = { CHARACTER = scope:owner }
		}
		set_relation_nemesis = {
			target = scope:owner
			reason = rival_disbelieved
		}
	}
	else_if = {
		limit = {
			can_set_relation_rival_trigger = { CHARACTER = scope:owner }
		}
		set_relation_rival = {
			target = scope:owner
			reason = rival_disbelieved
		}
	}
	else = { #We shouldn't end up here, hopefully
		if = {
			limit = { is_ai = yes }
			progress_towards_rival_effect = {
				REASON = rival_disbelieved
				CHARACTER = scope:owner
				OPINION = -50
			}
		}
		else = {
			progress_towards_rival_effect = {
				REASON = rival_disbelieved
				CHARACTER = scope:owner
				OPINION = 0
			}
		}
	}
}

#Success
scheme_critical_moments.1212 = {
	type = character_event
	window = scheme_successful_event
	title = scheme_critical_moments.1212.t
	desc = {
		desc = scheme_critical_moments.1212.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:scheme_discovered
				}
				desc = scheme_critical_moments.1212.desc_discovered
			}
			desc = scheme_critical_moments.1212.desc_secret
		}
	}
	theme = mandala
	left_portrait = {
		character = root
		animation = scheme
	}
	lower_right_portrait = scope:target

	immediate = {
		scope:target = {
			# Effects on target (applied in the response events)
			show_as_tooltip = {
				# Effects on target if discovered (applied in the response events)
				if = {
					limit = { exists = scope:scheme_discovered }
					result_discovered_disbelieve_mandala_effect = yes
				}
				#The standard outcome
				result_success_disbelieve_mandala_effect = yes
			}
		}
	}

	option = {
		name = scheme_critical_moments.1212.a
		scope:scheme = {
			end_scheme = yes
		}
	}
	after = {
		# Trigger the response event for the target
		scope:target = {
			trigger_event = scheme_critical_moments.1214
		}
	}
}

scripted_effect result_discovered_attempted_disbelieve_mandala_effect = {
	scope:target = {
		if = {
			limit = { is_ai = yes }
			progress_towards_rival_effect = {
				REASON = rival_attempted_disbelieve
				CHARACTER = scope:owner
				OPINION = -50
			}
		}
		else = {
			progress_towards_rival_effect = {
				REASON = rival_attempted_disbelieve
				CHARACTER = scope:owner
				OPINION = 0
			}
		}
	}
}

#Failure
scheme_critical_moments.1213 = {
	type = character_event
	window = scheme_failed_event
	title = scheme_critical_moments.1213.t
	desc = {
		desc = scheme_critical_moments.1213.desc
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:scheme_discovered }
				desc = scheme_critical_moments.1213.desc_discovered
			}
			desc = scheme_critical_moments.1213.desc_secret
		}
	}
	theme = mandala
	left_portrait = {
		character = root
		animation = disappointed
	}
	lower_right_portrait = scope:target

	immediate = {
		# Effects on target if discovered (applied in the response events)
		if = {
			limit = { exists = scope:scheme_discovered }
			show_as_tooltip = { result_discovered_attempted_disbelieve_mandala_effect = yes }
		}
		stress_impact = {
			base = minor_stress_impact_gain
			ambitious = minor_stress_impact_gain
			deceitful = minor_stress_impact_gain
		}
	}

	#Option A: Too bad
	option = {
		name = scheme_critical_moments.1213.a
		scope:scheme = {
			end_scheme = yes
		}
	}
	after = {
		scope:target = {
			trigger_event = scheme_critical_moments.1215
		}
	}
}

# Target reaction to Success
scheme_critical_moments.1214 = {
	type = character_event
	window = scheme_conclusion_event_no_header
	title = scheme_critical_moments.1214.t
	desc = {
		desc = scheme_critical_moments.1214.desc
		triggered_desc = {
			trigger = {
				exists = scope:scheme_discovered
			}
			desc = scheme_critical_moments.1214.desc_discovered
		}
	}
	theme = mandala
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = {
				exists = scope:scheme_discovered
			}
			animation = disbelief
		}
		animation = paranoia
	}
	lower_right_portrait = scope:display_owner

	immediate = {
		# Effects on target if discovered (applied in the response events)
		if = {
			limit = { exists = scope:scheme_discovered }
			result_discovered_disbelieve_mandala_effect = yes
			scope:owner = { save_scope_as = display_owner }
			create_character_memory = {
				type = became_disbelieved_known_memory
				participants = { disbeliever = scope:owner }
			}
		}
		else = {
			create_character_memory = { type = became_disbelieved_memory }
		}
		#The standard outcome
		result_success_disbelieve_mandala_effect = yes
	}

	option = {
		name = scheme_critical_moments.1214.a
	}
}

# Target reaction to Failure
scheme_critical_moments.1215 = {
	type = character_event
	window = scheme_conclusion_event_no_header
	title = scheme_critical_moments.1215.t
	desc = {
		desc = scheme_critical_moments.1215.desc
		triggered_desc = {
			trigger = { exists = scope:scheme_discovered }
			desc = scheme_critical_moments.1215.desc_discovered
		}
	}
	theme = mandala
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = {
				exists = scope:scheme_discovered
			}
			animation = disbelief
		}
		animation = paranoia
	}
	lower_right_portrait = scope:display_owner

	option = {
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = { exists = scope:scheme_discovered }
						desc = scheme_critical_moments.1215.a_discovered
					}
					desc = scheme_critical_moments.1215.a
				}
			}
		}
		if = {
			limit = { exists = scope:scheme_discovered }
			result_discovered_attempted_disbelieve_mandala_effect = yes
		}
		add_piety = minor_piety_gain
	}
}

##################################################
# Coerce Tributary Results
# 1221 - 1230
##################################################

#Results event for the Coerce Tributary scheme
scheme_critical_moments.1221 = {
	hidden = yes

	immediate = {
		scope:scheme = {
			scheme_target_character = { save_scope_as = target }
			scheme_owner = {
				save_scope_as = owner
				#SUCCESS ROLL
				random = {
					chance = scope:scheme.scheme_success_chance
					save_scope_value_as = {
						name = scheme_successful
						value = yes
					}
					mandala_trickster_increment_successful_schemes_effect = yes
				}
				if = {
					limit = { exists = scope:scheme_successful }
					#Uh-oh, a Suzerain to consider?
					if = {
						limit = {
							scope:target = { is_tributary = yes }
						}
						trigger_event = {
							id = scheme_critical_moments.1224
							days = 1
						}
					}
					else = {
						trigger_event = {
							id = scheme_critical_moments.1222
							days = 1
						}
					}
				}
				else = {
					trigger_event = {
						id = scheme_critical_moments.1223
						days = 1
					}
				}
			}
		}
	}
}

#Success!
scheme_critical_moments.1222 = {
	type = character_event
	window = scheme_successful_event
	title = scheme_critical_moments.1222.t
	desc = scheme_critical_moments.1222.desc
	theme = mandala
	left_portrait = {
		character = root
		animation = flirtation
	}
	right_portrait = {
		character = scope:target
		animation = nervous
	}
	immediate = {
		scope:target = { save_scope_as = new_tributary }
	}
	option = {
		name = scheme_critical_moments.1222.a
		scope:scheme = {
			end_scheme = yes
		}
		#Start the tributary!
		scope:target = {
			if = {
				limit = { is_ai = yes }
				add_opinion = {
					modifier = coerced_tributary_opinion
					opinion = 30
					target = root
				}
			}
		}
		start_tributary_interaction_effect = {
			TRIBUTARY = scope:new_tributary
			SUZERAIN = root
		}
	}
}

#Failure!
scheme_critical_moments.1223 = {
	type = character_event
	window = scheme_failed_event
	title = scheme_critical_moments.1223.t
	desc = {
		desc = scheme_critical_moments.1223.intro
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:target = { is_tributary = yes }
				}
				desc = scheme_critical_moments.1223.desc_suzerain
			}
			desc = scheme_critical_moments.1223.desc
		}
	}
	theme = mandala
	left_portrait = {
		character = root
		animation = disappointed
	}
	lower_right_portrait = scope:target
	immediate = {
		stress_impact = {
			base = minor_stress_impact_gain
			ambitious = minor_stress_impact_gain
			deceitful = minor_stress_impact_gain
		}
	}
	#Option A: Too bad
	option = {
		name = scheme_critical_moments.1223.a
		scope:scheme = {
			end_scheme = yes
		}
	}
}

scripted_effect coerced_tributary_opinion_loss_effect = {
	if = {
		limit = { is_ai = yes }
		add_opinion = {
			modifier = coerced_my_tributary_opinion
			opinion = -40
			target = scope:owner
		}
	}
}

#Inform Schemer that Target needs to consider their Suzerain
scheme_critical_moments.1224 = {
	type = character_event
	window = scheme_conclusion_event_no_header
	title = scheme_critical_moments.1224.t
	desc = scheme_critical_moments.1224.desc
	theme = mandala
	left_portrait = {
		character = root
		animation = scheme
	}
	lower_center_portrait = scope:target
	lower_right_portrait = scope:target.suzerain
	#Let's roll
	option = {
		name = scheme_critical_moments.1224.a
	}
	after = {
		scope:target.suzerain = {
			show_as_tooltip = { coerced_tributary_opinion_loss_effect = yes }
			trigger_event = {
				id = scheme_critical_moments.1225
				days = 1
			}
		}
	}
}

scripted_effect coerced_tributary_spent_resources_effect = {
	add_piety = major_piety_loss
	pay_short_term_gold = {
		target = scope:target
		gold = medium_gold_value
	}
}

#Suzerain gets notified of impending Tributary departure
scheme_critical_moments.1225 = {
	type = character_event
	window = scheme_conclusion_event_no_header
	title = scheme_critical_moments.1225.t
	desc = scheme_critical_moments.1225.desc
	theme = mandala
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = {
				OR = {
					has_trait = wrathful
					has_trait = irritable
				}
			}
			animation = rage
		}
		animation = stress
	}
	center_portrait = {
		character = scope:target
		animation = prayer
		camera = camera_event_very_left
	}
	right_portrait = {
		character = scope:owner
		animation = wedding_priest
		camera = camera_event_scheme_far_right
	}
	immediate = {
		coerced_tributary_opinion_loss_effect = yes
		add_character_flag = allowed_war_declaration_sans_truce_penalties
	}
	#Spend some resources
	option = {
		name = scheme_critical_moments.1225.a
		save_scope_as = incentivizing_suzerain
		#Pay some resources to make them stay
		coerced_tributary_spent_resources_effect = yes
		#They're a bit irked
		progress_towards_rival_effect = {
			REASON = rival_coerced_tributary
			CHARACTER = scope:owner
			OPINION = 0
		}
		ai_chance = {
			base = 100
			modifier = {
				short_term_gold <= medium_gold_value
				factor = 0
			}
		}
	}
	#Start a war against the Tributary
	option = {
		name = scheme_critical_moments.1225.b
		save_scope_as = warring_suzerain
		reason = alert
		add_internal_flag = special
		# To war!
		if = {
			limit = { has_truce = scope:target }
			cancel_truce_one_way = scope:target
		}
		start_war = {
			casus_belli = make_tributary_cb
			target = scope:target
		}
		custom_description_no_bullet = {
			text = scheme_potential_suzerain_might_join_war_tt
			subject = scope:target
			object = scope:owner
		}
		ai_chance = {
			base = 100
			modifier = {
				house = { has_house_aspiration_parameter = aspect_of_serenity }
				factor = 0.5
			}
			modifier = {
				is_at_war = yes
				factor = 0
			}
			modifier = {
				military_power <= scope:target.military_power
				factor = 0
			}
		}

	}
	#_This is fine_
	option = {
		name = scheme_critical_moments.1225.c
		save_scope_as = folding_suzerain
		#No more tributary, huh
		scope:target = {
			end_tributary = yes
		}
		#Wa-waw
		add_prestige = minor_prestige_loss
		add_legitimacy_effect = { LEGITIMACY = minor_legitimacy_loss }
		#They're a bit irked
		progress_towards_rival_effect = {
			REASON = rival_coerced_tributary
			CHARACTER = scope:owner
			OPINION = 0
		}
		ai_chance = {
			base = 100
		}
	}
	after = {
		#Let the Schemer know
		scope:owner = {
			trigger_event = {
				id = scheme_critical_moments.1226
				days = 1
			}
		}
		remove_character_flag = allowed_war_declaration_sans_truce_penalties
	}
}

#Scheme owner gets notified of outcome
scheme_critical_moments.1226 = {
	type = character_event
	window = scheme_conclusion_event_no_header
	title = {
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:incentivizing_suzerain }
				desc = scheme_critical_moments.1226.t_incentivizing
			}
			triggered_desc = {
				trigger = { exists = scope:warring_suzerain }
				desc = scheme_critical_moments.1226.t_warring
			}
			desc = scheme_critical_moments.1226.t
		}
	}
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:incentivizing_suzerain }
				desc = scheme_critical_moments.1226.desc_incentivizing
			}
			triggered_desc = {
				trigger = { exists = scope:warring_suzerain }
				desc = scheme_critical_moments.1226.desc_warring
			}
			desc = scheme_critical_moments.1226.desc
		}
	}
	theme = mandala
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = { exists = scope:warring_suzerain }
			animation = disbelief
		}
		triggered_animation = {
			trigger = { exists = scope:incentivizing_suzerain }
			animation = disapproval
		}
		animation = scheme
	}
	lower_center_portrait = scope:target
	lower_right_portrait = scope:target.suzerain
	immediate = {
		#Suzerain went warring
		if = {
			limit = { exists = scope:warring_suzerain }
			scope:target = {
				random_character_war = {
					limit = {
						using_cb = make_tributary_cb
						any_war_attacker = { this = scope:warring_suzerain }
					}
					save_scope_as = war
				}
			}
			random_dummy_gender_soldier_effect = { SCOPE_NAME = dummy_envoy }
		}
		#Suzerain incentivized the tributary to stay
		if = {
			limit = { exists = scope:incentivizing_suzerain }
			show_as_tooltip = {
				scope:incentivizing_suzerain = { coerced_tributary_spent_resources_effect = yes }
			}
		}
	}
	#Suzerain went warring, let's assist our new Tributary!
	option = {
		name = scheme_critical_moments.1226.a
		trigger = { exists = scope:warring_suzerain }
		#Start the tributary!
		scope:target = {
			if = {
				limit = { is_ai = yes }
				add_opinion = {
					modifier = coerced_tributary_opinion
					opinion = 50
					target = root
				}
			}
		}
		start_tributary_interaction_effect = {
			TRIBUTARY = scope:target
			SUZERAIN = root
		}
		#... and the war
		scope:war = {
			add_defender = scope:owner
		}
	}
	#Suzerain folded // Suzerain went warring, betray the tributary
	option = {
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = { exists = scope:warring_suzerain }
						desc = scheme_critical_moments.1226.b_warring
					}
					triggered_desc = {
						trigger = { exists = scope:incentivizing_suzerain }
						desc = scheme_critical_moments.1226.b_incentivizing
					}
					desc = scheme_critical_moments.1226.b
				}
			}
		}
		#Suzerain went warring, betray the tributary
		if = {
			limit = { exists = scope:warring_suzerain }
			#You betray them ruefully
			add_character_modifier = {
				modifier = betrayed_tributary_modifier
				years = 10
			}
			scope:target = {
				if = {
					limit = {
						can_set_relation_rival_trigger = { CHARACTER = scope:owner }
					}
					set_relation_rival = {
						target = scope:owner
						reason = rival_betrayed_tributary
					}
				}
				else = {
					if = {
						limit = { is_ai = yes }
						progress_towards_rival_effect = {
							REASON = rival_betrayed_tributary
							CHARACTER = scope:owner
							OPINION = -70
						}
					}
					else = {
						progress_towards_rival_effect = {
							REASON = rival_betrayed_tributary
							CHARACTER = scope:owner
							OPINION = 0
						}
					}
				}
				#You ain't coercing them ever again
				set_variable = {
					name = was_betrayed_after_being_coerced
					value = scope:owner
				}
			}
			stress_impact = {
				honest = medium_stress_impact_gain
				just = minor_stress_impact_gain
			}
		}
		#Suzerain incentivized the tributary to stay
		else_if = {
			limit = { exists = scope:incentivizing_suzerain }
			#Have a bone, for your troubles
			add_prestige = major_prestige_gain
			add_focused_lifestyle_xp_effect = { AMOUNT = major }
		}
		#Suzerain folded, have a new tributary
		else = {
			#Start the tributary!
			scope:target = {
				if = {
					limit = { is_ai = yes }
					add_opinion = {
						modifier = coerced_tributary_opinion
						opinion = 30
						target = root
					}
				}
			}
			start_tributary_interaction_effect = {
				TRIBUTARY = scope:target
				SUZERAIN = root
			}
		}
	}
	after = {
		scope:scheme = {
			end_scheme = yes
		}
	}
}

##################################################
# Movement Power Results
# Arkadiusz Majewski
# 1231 - 1240
##################################################

# Results event for the Movement Power Promote scheme.
scheme_critical_moments.1231 = {
	hidden = yes

	immediate = {
		scope:scheme = {
			scheme_target_character = {
				save_scope_as = target
			}
			scheme_owner = {
				save_scope_as = owner
			}
			var:targets_movement ?= {
				save_scope_as = targets_movement
			}
		}
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = scheme_critical_moments.1232
			FAILURE_EVENT = scheme_critical_moments.1233
		}
	}
}

# Success
scheme_critical_moments.1232 = {
	type = character_event
	title = scheme_critical_moments.1232.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { root = scope:target }
				desc = scheme_critical_moments.1232.desc.myself
			}
			desc = scheme_critical_moments.1232.desc
		}
	}
	theme = diplomacy
	left_portrait = {
		character = root
		animation = happy_teacher
	}
	right_portrait = {
		trigger = { root != scope:target }
		character = scope:target
		animation = happiness
	}

	immediate = {
		top_participant_group:dynastic_cycle ?= { save_scope_as = actors_movement }
	}

	option = {
		name = scheme_critical_moments.1232.a
		change_influence = minor_influence_loss
		scope:targets_movement = {
			scheme_change_movement_power_effect = {
				VALUE = root.merit_level
			}
		}
	}

	option = {
		name = {
			trigger = { root != scope:target }
			text = scheme_critical_moments.1232.b
		}
		name = {
			trigger = { root = scope:target }
			text = scheme_critical_moments.1232.b.myself
		}
		scope:target = {
			scheme_change_movement_power_effect = {
				VALUE = root.merit_level
			}
		}
	}

	after = {
		scope:scheme = {
			end_scheme = yes
		}
	}
}

# Failure
scheme_critical_moments.1233 = {
	type = character_event
	title = scheme_critical_moments.1233.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { root = scope:target }
				desc = scheme_critical_moments.1233.desc.myself
			}
			desc = scheme_critical_moments.1233.desc
		}
	}
	theme = stewardship
	left_portrait = {
		character = root
		animation = disappointed
	}
	right_portrait = {
		trigger = { root != scope:target }
		character = scope:target
		animation = shame
	}

	immediate = {
	}

	option = {
		name = scheme_critical_moments.1233.a
		scope:scheme = {
			end_scheme = yes
		}
	}
}
# Results event for the Movement Power Slander scheme.
scheme_critical_moments.1234 = {
	hidden = yes

	immediate = {
		scope:scheme = {
			scheme_target_character = {
				save_scope_as = target
			}
			scheme_owner = {
				save_scope_as = owner
			}
			var:targets_movement ?= {
				save_scope_as = targets_movement
			}
		}
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = scheme_critical_moments.1235
			FAILURE_EVENT = scheme_critical_moments.1236
		}
	}
}

# Success
scheme_critical_moments.1235 = {
	type = character_event
	title = scheme_critical_moments.1235.t
	desc = scheme_critical_moments.1235.desc
	theme = diplomacy
	left_portrait = {
		character = root
		animation = schadenfreude
	}
	right_portrait = {
		character = scope:target
		animation = rage
	}
	immediate = {
        save_scope_value_as = {
            name = decrease_value
            value = {
                value = root.merit_level
                multiply = -1
            }
        }
	}
	option = {
		name = scheme_critical_moments.1235.a
		change_influence = minor_influence_loss
		scope:targets_movement = {
			scheme_change_movement_power_effect = {
				VALUE = scope:decrease_value
			}
		}
	}

	option = {
		name = scheme_critical_moments.1235.b
		scope:target = {
			scheme_change_movement_power_effect = {
				VALUE = scope:decrease_value
			}
		}
	}

	after = {
		scope:scheme = {
			end_scheme = yes
		}
	}
}

# Failure
scheme_critical_moments.1236 = {
	type = character_event
	title = scheme_critical_moments.1236.t
	desc = scheme_critical_moments.1236.desc
	theme = stewardship
	left_portrait = {
		character = root
		animation = anger
	}
	right_portrait = {
		character = scope:target
		animation = schadenfreude
	}

	immediate = {
	}

	option = {
		name = scheme_critical_moments.1236.a
		scope:scheme = {
			end_scheme = yes
		}
	}
}

##################################################
# Coerce Contribution Results
# 1241 - 1250
##################################################

#Results event for the Coerce Contribution scheme
scheme_critical_moments.1241 = {
	hidden = yes

	immediate = {
		scope:scheme = {
			scheme_target_title = {
				holder = {
					if = {
						limit = { this != scope:scheme.scheme_owner }
						save_scope_as = title_holder
					}
				}
				save_scope_as = target_title
				#Set the cooldown
				set_variable = {
					name = coerce_contribution_cooldown
					years = 10
				}
			}
			scheme_owner = {
				save_scope_as = owner
				#SUCCESS ROLL
				random = {
					chance = scope:scheme.scheme_success_chance
					save_scope_value_as = {
						name = scheme_successful
						value = yes
					}
					mandala_trickster_increment_successful_schemes_effect = yes
				}
				if = {
					limit = { exists = scope:scheme_successful }
					trigger_event = {
						id = scheme_critical_moments.1242
						days = 1
					}
				}
				else = {
					trigger_event = {
						id = scheme_critical_moments.1243
						days = 1
					}
				}
			}
		}
	}
}

#Success!
scheme_critical_moments.1242 = {
	type = character_event
	window = scheme_successful_event
	title = scheme_critical_moments.1242.t
	desc = scheme_critical_moments.1242.desc
	theme = mandala
	left_portrait = {
		character = root
		animation = scheme
	}
	right_portrait = {
		trigger = { exists = scope:title_holder }
		character = scope:title_holder
		animation = disapproval
	}
	lower_right_portrait = scope:target_title
	immediate = {
		show_as_tooltip = {
			scope:title_holder ?= {
				if = {
					limit = { is_ai = yes }
					add_opinion = {
						target = root
						modifier = attempted_to_coerce_contribution_from_my_realm_opinion
						opinion = -10
					}
				}
			}
		}
	}
	option = {
		name = scheme_critical_moments.1242.a
		scope:scheme = {
			end_scheme = yes
		}
		random_great_project = {
			limit = {
				great_project_owner = root
				OR = {
					great_project_type = mandala_capital_01
					great_project_type = mandala_capital_02
					great_project_type = mandala_capital_03
					great_project_type = mandala_capital_04
					great_project_type = mandala_capital_05
				}
			}
			#Check for Mandatory first
			random_contribution = {
				limit = {
					is_owner_only_contribution_trigger = no
					contribution_is_funded = no
					contribution_is_required = yes
				}
				alternative_limit = {
					is_owner_only_contribution_trigger = no
					contribution_is_funded = no
				}
				save_scope_as = contribution_to_fund
			}
		}
		#The holder of the title 'officially' contributes
		if = {
			limit = {
				exists = scope:title_holder
				scope:title_holder.primary_title.tier > tier_barony
			}
			fund_great_project_contribution = {
				contribution = scope:contribution_to_fund
				cost = no
				check_can_contribute = no
			}
		}
		#Otherwise root does
		else = {
			fund_great_project_contribution = {
				contribution = scope:contribution_to_fund
				cost = no
				check_can_contribute = no
			}
		}
	}
}

#Failure!
scheme_critical_moments.1243 = {
	type = character_event
	window = scheme_failed_event
	title = scheme_critical_moments.1243.t
	desc = scheme_critical_moments.1243.desc
	theme = mandala
	left_portrait = {
		character = root
		animation = disappointed
	}
	lower_right_portrait = scope:target_title
	immediate = {
		show_as_tooltip = {
			scope:title_holder ?= {
				if = {
					limit = { is_ai = yes }
					add_opinion = {
						target = root
						modifier = attempted_to_coerce_contribution_from_my_realm_opinion
						opinion = -10
					}
				}
			}
		}
		stress_impact = {
			base = minor_stress_impact_gain
			ambitious = minor_stress_impact_gain
			deceitful = minor_stress_impact_gain
		}
	}
	option = {
		name = scheme_critical_moments.1243.a
		scope:scheme = {
			end_scheme = yes
		}
		scope:target_title.county = {
			add_county_modifier = {
				modifier = insusceptible_to_coerce_contribution_modifier
				years = 5
			}
		}
	}
}

##################################################
# Leverage Contribution Results
# 1251 - 1260
##################################################

#Results event for the Coerce Contribution scheme
scheme_critical_moments.1251 = {
	hidden = yes

	immediate = {
		scope:scheme = {
			scheme_target_character = { save_scope_as = target }
			scheme_owner = {
				save_scope_as = owner
				#SUCCESS ROLL
				random = {
					chance = scope:scheme.scheme_success_chance
					save_scope_value_as = {
						name = scheme_successful
						value = yes
					}
					mandala_trickster_increment_successful_schemes_effect = yes
				}
				if = {
					limit = { exists = scope:scheme_successful }
					trigger_event = {
						id = scheme_critical_moments.1252
						days = 1
					}
				}
				else = {
					trigger_event = {
						id = scheme_critical_moments.1253
						days = 1
					}
				}
			}
		}
	}
}

#Success!
scheme_critical_moments.1252 = {
	type = character_event
	window = scheme_successful_event
	title = scheme_critical_moments.1252.t
	desc = scheme_critical_moments.1252.desc
	theme = mandala
	left_portrait = {
		character = root
		animation = scheme
	}
	right_portrait = {
		character = scope:target
		camera = camera_event_scheme_vs_center_look_left
		animation = interested_left
	}
	immediate = {
		random_great_project = {
			limit = {
				great_project_owner = root
				OR = {
					great_project_type = mandala_capital_01
					great_project_type = mandala_capital_02
					great_project_type = mandala_capital_03
					great_project_type = mandala_capital_04
					great_project_type = mandala_capital_05
				}
			}
			#Check for Mandatory first
			random_contribution = {
				limit = {
					is_owner_only_contribution_trigger = no
					contribution_is_funded = no
					contribution_is_required = yes
				}
				alternative_limit = {
					is_owner_only_contribution_trigger = no
					contribution_is_funded = no
				}
				save_scope_as = contribution_to_fund
			}
		}
	}
	option = {
		name = scheme_critical_moments.1252.a
		scope:scheme = {
			end_scheme = yes
		}
		progress_towards_friend_effect = {
			REASON = friend_contributed_to_temple_complex
			CHARACTER = scope:target
			OPINION = default_friend_opinion
		}
		#The holder of the title 'officially' contributes
		if = {
			limit = { scope:target.primary_title.tier > tier_barony }
			scope:target = {
				fund_great_project_contribution = {
					contribution = scope:contribution_to_fund
					cost = yes
					check_can_contribute = no
				}
			}
		}
		#Otherwise root does
		else = {
			fund_great_project_contribution = {
				contribution = scope:contribution_to_fund
				cost = no
				check_can_contribute = no
			}
		}
	}
}

#Failure!
scheme_critical_moments.1253 = {
	type = character_event
	window = scheme_failed_event
	title = scheme_critical_moments.1253.t
	desc = scheme_critical_moments.1253.desc
	theme = mandala
	left_portrait = {
		character = root
		animation = disappointed
	}
	immediate = {
		stress_impact = {
			base = minor_stress_impact_gain
			ambitious = minor_stress_impact_gain
			deceitful = minor_stress_impact_gain
		}
	}
	option = {
		name = scheme_critical_moments.1253.a
		scope:scheme = {
			end_scheme = yes
		}
		scope:target = {
			add_character_modifier = {
				modifier = insusceptible_to_leverage_contribution_modifier
				years = 10
			}
		}
	}
}


##################################################
# CONTRACT SCHEMES (DIPLO)

##################################################
# Regale court with stories Results
# by Ewan Cowhig Croft
# 2001 - 2010
##################################################

#	Results event.
scheme_critical_moments.2001 = {
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = laamp_base_contract_schemes.0002
			FAILURE_EVENT = laamp_base_contract_schemes.0003
		}
	}
}

##################################################
# Improve ruler's reputation Results
# by Ewan Cowhig Croft
# 2011 - 2020
##################################################

#	Results event.
scheme_critical_moments.2011 = {
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = laamp_base_contract_schemes.0012
			FAILURE_EVENT = laamp_base_contract_schemes.0013
		}
	}
}

##################################################
# Hobnob with local ruler Results
# by Ewan Cowhig Croft
# 2021 - 2030
##################################################

#	Results event.
scheme_critical_moments.2021 = {
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = laamp_base_contract_schemes.0022
			FAILURE_EVENT = laamp_base_contract_schemes.0023
		}
	}
}

##################################################
# Paid Mediator Results
# by Ewan Cowhig Croft
# 2031 - 2040
##################################################

#	Results event.
scheme_critical_moments.2031 = {
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = laamp_base_contract_schemes.0032
			FAILURE_EVENT = laamp_base_contract_schemes.0033
		}
	}
}

##################################################
# Confidence trickster Results
# by Ewan Cowhig Croft
# 2041 - 2050
##################################################

#	Results event.
scheme_critical_moments.2041 = {
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = laamp_base_contract_schemes.0042
			FAILURE_EVENT = laamp_base_contract_schemes.0043
		}
	}
}












##################################################
# CONTRACT SCHEMES (MARTIAL)

##################################################
# Hunt criminals
# by Ewan Cowhig Croft
# 2201 - 2210
##################################################

#	Results event.
scheme_critical_moments.2201 = {
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = laamp_base_contract_schemes.1002
			FAILURE_EVENT = laamp_base_contract_schemes.1003
		}
	}
}

##################################################
# Act as hired muscle
# by Ewan Cowhig Croft
# 2211 - 2220
##################################################

#	Results event.
scheme_critical_moments.2211 = {
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = laamp_base_contract_schemes.1012
			FAILURE_EVENT = laamp_base_contract_schemes.1013
		}
	}
}

##################################################
# Help train local MaA
# by Ewan Cowhig Croft
# 2221 - 2230
##################################################

#	Results event.
scheme_critical_moments.2221 = {
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = laamp_base_contract_schemes.1022
			FAILURE_EVENT = laamp_base_contract_schemes.1023
		}
	}
}

##################################################
# Garrison service
# by Ewan Cowhig Croft
# 2231 - 2240
##################################################

#	Results event.
scheme_critical_moments.2231 = {
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = laamp_base_contract_schemes.1032
			FAILURE_EVENT = laamp_base_contract_schemes.1033
		}
	}
}

##################################################
# Ambush travellers
# by Ewan Cowhig Croft
# 2241 - 2250
##################################################

#	Results event.
scheme_critical_moments.2241 = {
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = laamp_base_contract_schemes.1042
			FAILURE_EVENT = laamp_base_contract_schemes.1043
		}
	}
}












##################################################
# CONTRACT SCHEMES (STEWARDSHIP)

##################################################
# Hunt criminals
# by Ewan Cowhig Croft
# 2401 - 2410
##################################################

#	Results event.
scheme_critical_moments.2401 = {
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = laamp_base_contract_schemes.2002
			FAILURE_EVENT = laamp_base_contract_schemes.2003
		}
	}
}

##################################################
# Act as hired muscle
# by Ewan Cowhig Croft
# 2411 - 2420
##################################################

#	Results event.
scheme_critical_moments.2411 = {
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = laamp_base_contract_schemes.2012
			FAILURE_EVENT = laamp_base_contract_schemes.2013
		}
	}
}

##################################################
# Help train local MaA
# by Ewan Cowhig Croft
# 2421 - 2430
##################################################

#	Results event.
scheme_critical_moments.2421 = {
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = laamp_base_contract_schemes.2022
			FAILURE_EVENT = laamp_base_contract_schemes.2023
		}
	}
}

##################################################
# Garrison service
# by Ewan Cowhig Croft
# 2431 - 2440
##################################################

#	Results event.
scheme_critical_moments.2431 = {
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = laamp_base_contract_schemes.2032
			FAILURE_EVENT = laamp_base_contract_schemes.2033
		}
	}
}

##################################################
# Ambush travellers
# by Ewan Cowhig Croft
# 2441 - 2450
##################################################

#	Results event.
scheme_critical_moments.2441 = {
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = laamp_base_contract_schemes.2042
			FAILURE_EVENT = laamp_base_contract_schemes.2043
		}
	}
}












##################################################
# CONTRACT SCHEMES (INTRIGUE)

##################################################
# Provide intelligence from your trips
# by Ewan Cowhig Croft
# 2601 - 2610
##################################################

#	Results event.
scheme_critical_moments.2601 = {
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = laamp_base_contract_schemes.3002
			FAILURE_EVENT = laamp_base_contract_schemes.3003
		}
	}
}

##################################################
# Murder a character's rival
# by Ewan Cowhig Croft
# 2611 - 2620
##################################################

#	Results event.
scheme_critical_moments.2611 = {
	hidden = yes

	immediate = {
		save_scope_value_as = {
			name = contract_end_success
			value = event_id:laamp_base_contract_schemes.3012
		}
		save_scope_value_as = {
			name = contract_end_failure
			value = event_id:laamp_base_contract_schemes.3013
		}
		save_scope_value_as = {
			name = suppress_reroll_option
			value = yes
		}
		laamp_base_contract_schemes_set_up_outcome_immediate_effect = yes
		scope:task_contract.var:target = { save_scope_as = target }
		scope:scheme = {
			generic_scheme_process_ending_effect = {
				RESULTS_TOOLTIP = murder_successful_roll_tt
				SUCCESS_EVENT_TYPE = on_action
				SUCCESS_EVENT_ID = murder_success_pre_filter_on_action
				FAILURE_EVENT_TYPE = on_action
				FAILURE_EVENT_ID = murder_failure_pre_filter_on_action
			}
		}
	}
}

##################################################
# Abduct a character's rival
# by Ewan Cowhig Croft
# 2621 - 2630
##################################################

#	Results event.
scheme_critical_moments.2621 = {
	hidden = yes

	immediate = {
		save_scope_value_as = {
			name = contract_end_success
			value = event_id:laamp_base_contract_schemes.3022
		}
		save_scope_value_as = {
			name = contract_end_failure
			value = event_id:laamp_base_contract_schemes.3023
		}
		save_scope_value_as = {
			name = suppress_reroll_option
			value = yes
		}
		laamp_base_contract_schemes_set_up_outcome_immediate_effect = yes
		scope:task_contract.var:target = { save_scope_as = target }
		random_list = {
			100 = {
				save_scope_value_as = {
					name = abduct_method
					value = flag:seized_roadside
				}
			}
			100 = {
				save_scope_value_as = {
					name = abduct_method
					value = flag:on_the_way
				}
			}
			100 = {
				save_scope_value_as = {
					name = abduct_method
					value = flag:unwelcome_guests
				}
			}
		}
		scope:scheme = {
			generic_scheme_process_ending_effect = {
				RESULTS_TOOLTIP = abduct_successful_roll_tt
				SUCCESS_EVENT_TYPE = id
				SUCCESS_EVENT_ID = scheme_critical_moments.2622
				FAILURE_EVENT_TYPE = id
				FAILURE_EVENT_ID = scheme_critical_moments.2623
			}
		}
	}
}

scheme_critical_moments.2622 = {
	hidden = yes
	scope = scheme
	immediate = {
		scheme_owner = {
			trigger_event = { on_action = abduct_succeeded }
		}
	}
}

scheme_critical_moments.2623 = {
	hidden = yes
	scope = scheme
	immediate = {
		scheme_owner = {
			trigger_event = { on_action = abduct_failed }
		}
	}
}

##################################################
# Attack the property of a character's rival
# by Ewan Cowhig Croft
# 2631 - 2640
##################################################

#	Results event.
scheme_critical_moments.2631 = {
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = laamp_base_contract_schemes.3032
			FAILURE_EVENT = laamp_base_contract_schemes.3033
		}
	}
}

##################################################
# Heist from a ruler's treasury
# by Ewan Cowhig Croft
# 2641 - 2650
##################################################

#	Results event.
scheme_critical_moments.2641 = {
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = laamp_base_contract_schemes.3042
			FAILURE_EVENT = laamp_base_contract_schemes.3043
		}
	}
}












##################################################
# CONTRACT SCHEMES (LEARNING)


##################################################
# Copy texts for a learned ruler
# by Ewan Cowhig Croft
# 2801 - 2810
##################################################

#	Results event.
scheme_critical_moments.2801 = {
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = laamp_base_contract_schemes.4002
			FAILURE_EVENT = laamp_base_contract_schemes.4003
		}
	}
}

##################################################
# Help settle a local theological argument
# by Ewan Cowhig Croft
# 2811 - 2820
##################################################

#	Results event.
scheme_critical_moments.2811 = {
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = laamp_base_contract_schemes.4012
			FAILURE_EVENT = laamp_base_contract_schemes.4013
		}
	}
}

##################################################
# Create a work of learning for a ruler
# by Ewan Cowhig Croft
# 2821 - 2830
##################################################

#	Results event.
scheme_critical_moments.2821 = {
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = laamp_base_contract_schemes.4022
			FAILURE_EVENT = laamp_base_contract_schemes.4023
		}
	}
}

##################################################
# Solicit Charity
# by Ewan Cowhig Croft
# 2831 - 2840
##################################################

#	Results event.
scheme_critical_moments.2831 = {
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = laamp_base_contract_schemes.4032
			FAILURE_EVENT = laamp_base_contract_schemes.4033
		}
	}
}

##################################################
# Sell bogus relics
# by Ewan Cowhig Croft
# 2841 - 2850
##################################################

#	Results event.
scheme_critical_moments.2841 = {
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = laamp_base_contract_schemes.4042
			FAILURE_EVENT = laamp_base_contract_schemes.4043
		}
	}
}

##################################################
# Seize Realm
# by Joe Parkin
# 2901 - 2910
##################################################

# Realistically, not every government type below would be valid for the scheme, but all government types have been included for completeness and mod support
scripted_effect save_target_government_as_variable_effect = {
	switch = {
		trigger = has_government
		feudal_government = {
			scope:scheme.scheme_owner = {
				save_scope_value_as = {
					name = old_government_type
					value = flag:feudal
				}
			}
		}
		republic_government = {
			scope:scheme.scheme_owner = {
				save_scope_value_as = {
					name = old_government_type
					value = flag:republic
				}
			}
		}
		theocracy_government = {
			scope:scheme.scheme_owner = {
				save_scope_value_as = {
					name = old_government_type
					value = flag:theocracy
				}
			}
		}
		clan_government = {
			scope:scheme.scheme_owner = {
				save_scope_value_as = {
					name = old_government_type
					value = flag:clan
				}
			}
		}
		tribal_government = {
			scope:scheme.scheme_owner = {
				save_scope_value_as = {
					name = old_government_type
					value = flag:tribal
				}
			}
		}
		wanua_government = {
			scope:scheme.scheme_owner = {
				save_scope_value_as = {
					name = old_government_type
					value = flag:wanua
				}
			}
		}
		holy_order_government = {
			scope:scheme.scheme_owner = {
				save_scope_value_as = {
					name = old_government_type
					value = flag:holy_order
				}
			}
		}
		administrative_government = {
			scope:scheme.scheme_owner = {
				save_scope_value_as = {
					name = old_government_type
					value = flag:administrative
				}
			}
		}
		nomad_government = {
			scope:scheme.scheme_owner = {
				save_scope_value_as = {
					name = old_government_type
					value = flag:nomad
				}
			}
		}
		herder_government = {
			scope:scheme.scheme_owner = {
				save_scope_value_as = {
					name = old_government_type
					value = flag:herder
				}
			}
		}
		celestial_government = {
			scope:scheme.scheme_owner = {
				save_scope_value_as = {
					name = old_government_type
					value = flag:celestial
				}
			}
		}
		mandala_government = {
			scope:scheme.scheme_owner = {
				save_scope_value_as = {
					name = old_government_type
					value = flag:mandala
				}
			}
		}
		steppe_admin_government = {
			scope:scheme.scheme_owner = {
				save_scope_value_as = {
					name = old_government_type
					value = flag:steppe_admin
				}
			}
		}
		meritocratic_government = {
			scope:scheme.scheme_owner = {
				save_scope_value_as = {
					name = old_government_type
					value = flag:meritocratic
				}
			}
		}
		japan_feudal_government = {
			scope:scheme.scheme_owner = {
				save_scope_value_as = {
					name = old_government_type
					value = flag:japan_feudal
				}
			}
		}
		japan_administrative_government = {
			scope:scheme.scheme_owner = {
				save_scope_value_as = {
					name = old_government_type
					value = flag:japan_administrative
				}
			}
		}
	}
}

#	Results event.
scheme_critical_moments.2901 = {
	hidden = yes

	immediate = {
		scope:scheme = {
			# Set up a block for the inappropriate cheating error?
			save_scope_value_as = {
				name = ignore_cheating_error_check
				value = yes
			}
			# Proceed to rolls.
			scheme_owner = {
				#DISCOVERY ROLL
				save_scope_value_as = {
					name = discovery_chance
					value = {
						value = 100
						subtract = scope:scheme.scheme_secrecy
					}
				}
				random = {
					chance = scope:discovery_chance
					save_scope_value_as = {
						name = scheme_discovered
						value = yes
					}
				}
				#SUCCESS ROLL
				random = {
					chance = scope:scheme.scheme_success_chance
					custom_tooltip = seize_realm_successful_roll_tt
					save_scope_value_as = {
						name = scheme_successful
						value = yes
					}
					mandala_trickster_increment_successful_schemes_effect = yes
				}
				# FATE ROLL
				random_list = {
					10 = {
						trigger = {
							trigger_if = {
								limit = { exists = scope:scheme_successful }
								scope:scheme.scheme_target_character = { is_ai = yes }
							}
							trigger_else = {
								scope:scheme.scheme_owner = { is_ai = yes }
							}
						}
						save_scope_as = death
					}
					10 = {
						modifier = {
							NOT = { exists = scope:scheme_successful }
							exists = scope:scheme_discovered
							factor = 2
						}
						save_scope_as = imprison
					}
					20 = {}
				}
				# FIRE EVENTS
				if = {
					limit = { exists = scope:scheme_successful }
					scope:scheme.scheme_target_character = {
						save_target_government_as_variable_effect = yes # we need this here to build the "Has Happened" tooltip in the following event properly
					}
					trigger_event = ep3_laamps.0401
				}
				else = { trigger_event = ep3_laamps.0402 }
			}
		}
	}
}



##################################################
# Coup Ceremonial Liege
# by Joe Parkin
# 2921 - 2930
##################################################

#	Results event.
scheme_critical_moments.2921 = {
	hidden = yes

	immediate = {
		scope:scheme = {
			# Set up a block for the inappropriate cheating error?
			save_scope_value_as = {
				name = ignore_cheating_error_check
				value = yes
			}
			# Proceed to rolls.
			scheme_owner = {
				#DISCOVERY ROLL
				save_scope_value_as = {
					name = discovery_chance
					value = {
						value = 100
						subtract = scope:scheme.scheme_secrecy
					}
				}
				random = {
					chance = scope:discovery_chance
					save_scope_value_as = {
						name = scheme_discovered
						value = yes
					}
				}
				#SUCCESS ROLL
				random = {
					chance = scope:scheme.scheme_success_chance
					custom_tooltip = coup_ceremonial_liege_successful_roll_tt
					save_scope_value_as = {
						name = scheme_successful
						value = yes
					}
					mandala_trickster_increment_successful_schemes_effect = yes
				}
				# FIRE EVENTS
				if = {
					limit = { exists = scope:scheme_successful }
					trigger_event = scheme_critical_moments.2922
				}
				else = { trigger_event = scheme_critical_moments.2923 }
			}
		}
	}
}

### SUCCESS
scheme_critical_moments.2922 = {
	type = character_event
	title = scheme_critical_moments.2922.t
	desc = {
		desc = ep3_laamps.0401.desc
		desc = ep3_laamps.0401.imprison
	}
	theme = claim_throne_scheme
	override_background = { reference = throne_room_scope }
	left_portrait = {
		character = root
		animation = holding_hu
	}
	right_portrait = {
		character = scope:target
		animation = prisonhouse
		override_imprisonment_visuals = yes
	}

	trigger = { exists = scope:scheme_successful }

	immediate = {
		scope:target = { trigger_event = scheme_critical_moments.2924 }
		coup_ceremonial_liege_scheme_success_effect = yes
	}

	option = {
		name = scheme_critical_moments.2922.a
	}

	after = {

	}
}

### FAILURE
scheme_critical_moments.2923 = {
	type = character_event
	title = scheme_critical_moments.2923.t
	desc = {
		desc = ep3_laamps.0402.desc
		desc = ep3_laamps.0402.imprison
	}
	theme = claim_throne_scheme
	override_background = { reference = dungeon_scope }
	left_portrait = {
		character = root
		animation = prisonhouse
		override_imprisonment_visuals = yes
		outfit_tags = { prison }
	}
	right_portrait = {
		character = scope:target
		animation = war_over_win
	}

	trigger = {
		NOT = { exists = scope:scheme_successful }
	}

	immediate = {
		scope:target = { trigger_event = scheme_critical_moments.2925 }
		coup_ceremonial_liege_scheme_failure_effect = yes
	}

	option = {
		name = ep3_laamps.0402.a
		stress_impact = {
			base = medium_stress_impact_gain
			ambitious = medium_stress_impact_gain
			arrogant = minor_stress_impact_gain
			diligent = minor_stress_impact_gain
			impatient = minor_stress_impact_gain
			stubborn = minor_stress_impact_gain
			lazy = minor_stress_impact_loss
			craven = minor_stress_impact_loss
			honest = minor_stress_impact_loss
		}
	}
}

### SUCCESS - TARGET
scheme_critical_moments.2924 = {
	type = character_event
	title = scheme_critical_moments.2924.t
	desc = {
		desc = ep3_laamps.0410.desc
		desc = ep3_laamps.0410.imprison
	}
	theme = claim_throne_scheme
	override_background = { reference = dungeon_scope }

	left_portrait = {
		character = scope:owner
		animation = war_over_win
	}
	right_portrait = {
		character = scope:target
		animation = fear
		override_imprisonment_visuals = yes
		trigger = {
			OR = {
				exists = scope:imprison
				exists = scope:death
			}
		}
	}

	immediate = {
		show_as_tooltip = { coup_ceremonial_liege_scheme_success_effect = yes }
	}

	option = {
		name = ep3_laamps.0410.a
	}
}

### FAILURE - TARGET
scheme_critical_moments.2925 = {
	type = character_event
	title = scheme_critical_moments.2925.t
	desc = {
		desc = ep3_laamps.0411.desc
		desc = ep3_laamps.0411.imprison
	}
	theme = claim_throne_scheme
	override_background = { reference = dungeon_scope }
	left_portrait = {
		character = scope:target
		animation = war_over_win
	}
	right_portrait = {
		character = scope:owner
		animation = fear
		override_imprisonment_visuals = yes
	}

	immediate = {
		show_as_tooltip = { coup_ceremonial_liege_scheme_failure_effect = yes }
	}

	option = {
		name = ep3_laamps.0411.a
	}
}










##################################################
# CONTRACT SCHEMES (PROWESS)

##################################################
# Hunt in the wilds
# by Ewan Cowhig Croft
# 3001 - 3010
##################################################

#	Results event.
scheme_critical_moments.3001 = {
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = laamp_base_contract_schemes.5002
			FAILURE_EVENT = laamp_base_contract_schemes.5003
		}
	}
}

##################################################
# Guard merchant properties
# by Ewan Cowhig Croft
# 3011 - 3020
##################################################

#	Results event.
scheme_critical_moments.3011 = {
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = laamp_base_contract_schemes.5012
			FAILURE_EVENT = laamp_base_contract_schemes.5013
		}
	}
}

##################################################
# Guard a local ruler at a minor event
# by Ewan Cowhig Croft
# 3021 - 3030
##################################################

#	Results event.
scheme_critical_moments.3021 = {
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = laamp_base_contract_schemes.5022
			FAILURE_EVENT = laamp_base_contract_schemes.5023
		}
	}
}

##################################################
# Go rustling
# by Ewan Cowhig Croft
# 3031 - 3040
##################################################

#	Results event.
scheme_critical_moments.3031 = {
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = laamp_base_contract_schemes.5032
			FAILURE_EVENT = laamp_base_contract_schemes.5033
		}
	}
}

##################################################
# Go poaching
# by Ewan Cowhig Croft
# 3041 - 3050
##################################################

#	Results event.
scheme_critical_moments.3041 = {
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = laamp_base_contract_schemes.5042
			FAILURE_EVENT = laamp_base_contract_schemes.5043
		}
	}
}

##################################################
# Muggings
# by Ewan Cowhig Croft
# 3051 - 3060
##################################################

#	Results event.
scheme_critical_moments.3051 = {
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = laamp_base_contract_schemes.5052
			FAILURE_EVENT = laamp_base_contract_schemes.5053
		}
	}
}

##################################################
# Protect Minority Vassal Faith/Culture
# by Arkadiusz Majewski
# 3201 - 3210
##################################################

#	Results event.
scheme_critical_moments.3201 = {
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = laamp_extra_contract_schemes.0002
			FAILURE_EVENT = laamp_extra_contract_schemes.0003
		}
	}
}

##################################################
# Prison Break
# by Arkadiusz Majewski
# 3211 - 3220
##################################################

#	Results event.
scheme_critical_moments.3211 = {
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = laamp_extra_contract_schemes.0012
			FAILURE_EVENT = laamp_extra_contract_schemes.0013
		}
	}
}

##################################################
# Laamp helps find secrets
# 3221 - 3230
##################################################

#	Results event.
scheme_critical_moments.3221 = {
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = laamp_extra_contract_schemes.0023
			FAILURE_EVENT = laamp_extra_contract_schemes.0024
		}
	}
}

##################################################
# Foster Legitimacy Results
# Veronica Pazos
# 4000 - 4009
##################################################

# Roll the die to see if you succeed/fail
scheme_critical_moments.4000 = {
	hidden = yes

	immediate = {
		scope:scheme = {
			scheme_target_character = { save_scope_as = target }
			scheme_owner = {
				save_scope_as = owner

				#SUCCESS ROLL
				random = {
					chance = scope:scheme.scheme_success_chance

					save_scope_value_as = {
						name = scheme_successful
						value = yes
					}
					mandala_trickster_increment_successful_schemes_effect = yes
				}

				if = {
					limit = {
						exists = scope:scheme_successful
					}
					trigger_event = {
						id = scheme_critical_moments.4001
						days = 1
					}
				}
				else = {
					trigger_event = {
						id = scheme_critical_moments.4002
						days = 1
					}
				}
			}
		}
	}
}

#Success
scheme_critical_moments.4001 = {
	type = character_event
	title = scheme_critical_moments.4001.t
	desc = {
		desc = scheme_critical_moments.4001.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:target = { has_title = title:e_byzantium }
				}
				desc = scheme_critical_moments.4001.desc.byzantium
			}
			desc = scheme_critical_moments.4001.desc.other
		}
		desc = scheme_critical_moments.4001.desc.outro
	}
	theme = diplomacy
	left_portrait = {
		character = root
		animation = toast_goblet
	}
	lower_right_portrait = scope:target

	immediate = {
		scope:target = {
			send_interface_message = {
				type = msg_legitimacy_fostered_scheme
				title = scheme_critical_moments.4001.tt
				desc = foster_legitimacy_scheme_toast_desc
				left_icon = scope:owner
				add_legitimacy = medium_legitimacy_gain
			}
		}
	}

	option = {
		name = scheme_critical_moments.4001.a
		scope:target = {
			add_opinion = {
				modifier = fostered_legitimacy_opinion
				target = root
			}
		}
		if = {
			limit = {
				scope:scheme.scheme_success_chance >= 90
				can_add_hook = {
					target = scope:target
					type = strong_favor_hook
				}
			}
			random = {
				chance = 50
				add_hook = {
					type = strong_favor_hook
					target = scope:target
				}
			}
		}
		else_if = {
			limit = {
				scope:scheme.scheme_success_chance >= 75
				can_add_hook = {
					target = scope:target
					type = favor_hook
				}
			}
			random = {
				chance = 50
				add_hook = {
					type = favor_hook
					target = scope:target
				}
			}
		}
		scope:scheme = {
			end_scheme = yes
		}
	}
}

#Failure
scheme_critical_moments.4002 = {
	type = character_event
	title = scheme_critical_moments.4002.t
	desc = scheme_critical_moments.4002.desc
	theme = diplomacy
	left_portrait = {
		character = root
		animation = disapproval
	}
	override_background = { reference = council_chamber }
	lower_right_portrait = scope:target

	option = {
		name = scheme_critical_moments.4002.a
		add_prestige = medium_prestige_loss
		scope:scheme = {
			end_scheme = yes
		}
	}
}

##################################################
# Damage Legitimacy Results
# Veronica Pazos
# 4010 - 4019
##################################################

# Roll the die to see if you succeed/fail
scheme_critical_moments.4010 = {
	hidden = yes

	immediate = {
		scope:scheme = {
			scheme_target_character = { save_scope_as = target }
			scheme_owner = {
				save_scope_as = owner

				#SUCCESS ROLL
				random = {
					chance = scope:scheme.scheme_success_chance

					save_scope_value_as = {
						name = scheme_successful
						value = yes
					}
					mandala_trickster_increment_successful_schemes_effect = yes
				}

				if = {
					limit = {
						exists = scope:scheme_successful
					}
					trigger_event = {
						id = scheme_critical_moments.4011
						days = 1
					}
				}
				else = {
					trigger_event = {
						id = scheme_critical_moments.4012
						days = 1
					}
				}
			}
		}
	}
}

#Success
scheme_critical_moments.4011 = {
	type = character_event
	title = scheme_critical_moments.4011.t
	desc = scheme_critical_moments.4011.desc
	theme = intrigue
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = {
				NOT = {
					has_trait = calm
					has_trait = callous
				}
			}
			animation = manic
		}
		animation = manic
	}
	lower_right_portrait = scope:target
	override_background = { reference = council_chamber }

	immediate = {
		scope:target = {
			send_interface_message = {
				type = msg_legitimacy_damaged_scheme
				title = scheme_critical_moments.4011.tt
				desc = damage_legitimacy_scheme_toast_desc
				left_icon = scope:owner
				add_legitimacy = minor_legitimacy_loss
				add_opinion = {
					target = root
					modifier = damaged_legitimacy_opinion
				}
			}
		}
	}

	option = {
		name = scheme_critical_moments.4011.a
		scope:scheme = {
			end_scheme = yes
		}
	}
}

#Failure
scheme_critical_moments.4012 = {
	type = character_event
	title = scheme_critical_moments.4012.t
	desc = {
		desc = scheme_critical_moments.4012.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:target = { has_title = title:e_byzantium }
				}
				desc = scheme_critical_moments.4012.desc.byzantium
			}
			desc = scheme_critical_moments.4012.desc.other
		}
		desc = scheme_critical_moments.4012.desc.outro
	}
	theme = intrigue
	left_portrait = {
		character = root
		animation = disapproval
	}
	lower_right_portrait = scope:target

	option = {
		name = scheme_critical_moments.4012.a
		change_influence = medium_influence_loss
		scope:scheme = {
			end_scheme = yes
		}
	}
}

##################################################
# Protect the Innocent
# 6001 - 6003
##################################################

#	Results event.
scheme_critical_moments.6001 = {
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = laamp_base_contract_schemes.6002
			FAILURE_EVENT = laamp_base_contract_schemes.6003
		}
	}
}

##################################################
# Rescue a Fair Non-Combatant Gender
# 6011 - 6013
##################################################

#	Results event.
scheme_critical_moments.6011 = {
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = laamp_base_contract_schemes.6012
			FAILURE_EVENT = laamp_base_contract_schemes.6013
		}
	}
}

##################################################
# Participate in a Chivalry Play
# 6021 - 6023
##################################################

#	Results event.
scheme_critical_moments.6021 = {
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = laamp_base_contract_schemes.6022
			FAILURE_EVENT = laamp_base_contract_schemes.6023
		}
	}
}

##################################################
# Do a Pas d'Armes
# 6021 - 6023
##################################################

#	Results event.
scheme_critical_moments.6031 = {
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = laamp_base_contract_schemes.6032
			FAILURE_EVENT = laamp_base_contract_schemes.6033
		}
	}
}

##################################################
# Dispute Borders
# Joe Parkin
# 8001 - 8004
##################################################

#	Results event for the Dispute Borders scheme.
scheme_critical_moments.8001 = {
	hidden = yes

	immediate = {
		scope:scheme = {
			scheme_target_title.holder = { save_scope_as = target }
			scheme_owner = {
				save_scope_as = owner
				#SUCCESS ROLL
				random = {
					chance = scope:scheme.scheme_success_chance
					save_scope_value_as = {
						name = scheme_successful
						value = yes
					}
					mandala_trickster_increment_successful_schemes_effect = yes
				}
				if = {
					limit = { exists = scope:scheme_successful }
					trigger_event = {
						id = scheme_critical_moments.8002
						days = 1
					}
				}
				else = {
					trigger_event = {
						id = scheme_critical_moments.8003
						days = 1
					}
				}
			}
		}
	}
}

scripted_effect dispute_border_success_effect = {
	if = {
		limit = {
			scope:target = {
				highest_held_title_tier >= tier_duchy
			}
		}
		create_title_and_vassal_change = {
			type = usurped
			save_scope_as = title_change
			add_claim_on_loss = no
		}
		scope:target_title = {
			change_title_holder = {
				holder = scope:owner
				change = scope:title_change
			}
		}
		resolve_title_and_vassal_change = scope:title_change
	}
	else = {
		create_title_and_vassal_change = {
			type = usurped
			save_scope_as = change
			add_claim_on_loss = no
		}
		scope:target = {
			change_liege = {
				liege = scope:owner
				change = scope:change
			}
		}
		resolve_title_and_vassal_change = scope:change
	}
}

#Success
scheme_critical_moments.8002 = {
	type = character_event
	title = scheme_critical_moments.8002.t
	desc = scheme_critical_moments.8002.desc
	theme = administrative
	left_portrait = {
		character = root
		animation = scheme
	}
	right_portrait = {
		character = scope:target
		animation = anger
	}
	lower_left_portrait = scope:owner.top_liege

	immediate = {
		# Trigger the response event for the target
		scope:target = { trigger_event = scheme_critical_moments.8004 }
		every_player = {
			limit = {
				top_liege ?= scope:owner.top_liege
				NOR = {
					this = scope:owner
					this = scope:target
				}
			}
			if = {
				limit = {
					house ?= scope:target.house
					scope:owner.house != scope:target.house
				}
				send_interface_message = {
					type = msg_admin_border_change_bad_with_text
					title = scheme_critical_moments.8004.t
					left_icon = scope:owner
					right_icon = scope:target
					desc = dispute_border_toast_desc
					show_as_tooltip = { dispute_border_success_effect = yes }
				}
			}
			else_if = {
				limit = {
					house ?= scope:owner.house
					scope:owner.house != scope:target.house
				}
				send_interface_message = {
					type = msg_admin_border_change_good_with_text
					title = scheme_critical_moments.8004.t
					left_icon = scope:owner
					right_icon = scope:target
					desc = dispute_border_toast_desc
					show_as_tooltip = { dispute_border_success_effect = yes }
				}
			}
			else = {
				send_interface_message = {
					type = msg_admin_border_change_neutral_with_text
					title = scheme_critical_moments.8004.t
					left_icon = scope:owner
					right_icon = scope:target
					desc = dispute_border_toast_desc
					show_as_tooltip = { dispute_border_success_effect = yes }
				}
			}
		}
		dispute_border_success_effect = yes
		show_as_tooltip = { # Effects on target (applied in the response events)
			scope:target = {
				add_scheme_cooldown = {
					target = scope:owner
					type = dispute_border
					years = 5
				}
				if = {
					limit = {
						is_ai = yes
						highest_held_title_tier >= tier_duchy
					}
					add_opinion = {
						target = scope:owner
						modifier = attempted_dispute_border_opinion
					}
				}
				else_if = {
					limit = {
						is_ai = yes
					}
					add_opinion = {
						target = scope:owner
						modifier = attempted_dispute_border_opinion
						opinion = -40
					}
				}
			}
		}
	}

	option = {
		name = scheme_critical_moments.8002.a
		hidden_effect = {
			scope:scheme = { end_scheme = yes }
		}
	}
}

#Failure
scheme_critical_moments.8003 = {
	type = character_event
	title = scheme_critical_moments.8003.t
	desc = scheme_critical_moments.8003.desc
	theme = administrative
	left_portrait = {
		character = root
		animation = disappointed
	}
	lower_right_portrait = scope:target
	lower_left_portrait = scope:owner.top_liege

	immediate = {
		scope:target = {
			send_interface_message = {
				type = event_scheme_bad
				title = scheme_critical_moments.8003.t
				left_icon = scope:owner
				right_icon = scope:target.primary_title
				custom_tooltip = scheme_critical_moments.8003.tt.failed
			}
		}
		stress_impact = {
			base = minor_stress_impact_gain
			ambitious = minor_stress_impact_gain
			deceitful = minor_stress_impact_gain
		}
	}

	#Option A: Too bad
	option = {
		name = scheme_critical_moments.8003.a
		scope:scheme = { end_scheme = yes }
	}
}

# Target reaction
scheme_critical_moments.8004 = {
	type = character_event
	title = scheme_critical_moments.8004.t
	desc = scheme_critical_moments.8004.desc
	theme = administrative
	left_portrait = {
		character = root
		animation = anger
	}
	lower_right_portrait = scope:owner
	lower_left_portrait = scope:owner.top_liege

	immediate = {
		show_as_tooltip = { dispute_border_success_effect = yes }
		add_scheme_cooldown = {
			target = scope:owner
			type = dispute_border
			years = 5
		}
		if = {
			limit = { is_ai = yes }
			hidden_effect = {
				remove_opinion = {
					modifier = attempted_dispute_border_opinion
					target = scope:owner
				}
			}
			add_opinion = {
				target = scope:owner
				modifier = dispute_border_opinion
			}
		}
	}

	option = {
		name = scheme_critical_moments.8004.a
	}
}

##################################################
# Subsume Province
# Joe Parkin
# 8011 - 8015
##################################################

#	Results event for the Subsume Province scheme.
scheme_critical_moments.8011 = {
	hidden = yes

	immediate = {
		scope:scheme = {
			scheme_target_title.holder = { save_scope_as = target }
			scheme_owner = {
				save_scope_as = owner
				#SUCCESS ROLL
				random = {
					chance = scope:scheme.scheme_success_chance
					save_scope_value_as = {
						name = scheme_successful
						value = yes
					}
					mandala_trickster_increment_successful_schemes_effect = yes
				}
				if = {
					limit = { exists = scope:scheme_successful }
					trigger_event = {
						id = scheme_critical_moments.8012
						days = 1
					}
				}
				else = {
					trigger_event = {
						id = scheme_critical_moments.8013
						days = 1
					}
				}
			}
		}
	}
}

scripted_effect subsume_province_success_effect = {
	create_title_and_vassal_change = {
		type = appointment
		save_scope_as = title_change
		add_claim_on_loss = no
	}
	scope:target_title = {
		every_de_jure_county = {
			limit = {
				county_held_or_vassal_to_target_trigger = { TARGET = scope:target }
			}
			add_to_list = transferred_counties
			change_title_holder = {
				holder = scope:owner
				change = scope:title_change
			}
		}
		change_title_holder = {
			holder = scope:owner
			change = scope:title_change
		}
		resolve_title_and_vassal_change = scope:title_change
	}
}

#Success
scheme_critical_moments.8012 = {
	type = character_event
	title = scheme_critical_moments.8012.t
	desc = scheme_critical_moments.8012.desc
	theme = administrative
	left_portrait = {
		character = root
		animation = schadenfreude
		camera = camera_event_right
	}
	lower_right_portrait = scope:target
	lower_left_portrait = scope:owner.top_liege

	immediate = {
		# Trigger the response event for the target
		scope:target = { trigger_event = scheme_critical_moments.8014 }
		every_player = {
			limit = {
				this != scope:owner
				top_liege = scope:owner.top_liege
			}
			trigger_event = scheme_critical_moments.8015
		}
		subsume_province_success_effect = yes
		show_as_tooltip = { # Effects on target (applied in the response events)
			add_scheme_cooldown = {
				target = scope:owner
				type = subsume_province
				years = 5
			}
			scope:target = {
				progress_towards_rival_effect = {
					REASON = rival_subsumed_province
					CHARACTER = scope:owner
					OPINION = -50
				}
			}
		}
	}

	option = {
		name = scheme_critical_moments.8012.a
		scope:scheme = { end_scheme = yes }
	}
}

#Failure
scheme_critical_moments.8013 = {
	type = character_event
	title = scheme_critical_moments.8013.t
	desc = scheme_critical_moments.8013.desc
	theme = administrative
	left_portrait = {
		character = root
		animation = disappointed
	}
	lower_right_portrait = scope:target
	lower_left_portrait = scope:owner.top_liege

	immediate = {
		hidden_effect = {
			scope:target = {
				send_interface_message = {
					type = event_scheme_bad
					title = scheme_critical_moments.8013.t
					left_icon = scope:owner
					right_icon = scope:target.primary_title
					custom_tooltip = scheme_critical_moments.8013.tt.failed
				}
			}
		}
		stress_impact = {
			base = minor_stress_impact_gain
			ambitious = minor_stress_impact_gain
			deceitful = minor_stress_impact_gain
		}
	}

	#Option A: Too bad
	option = {
		name = scheme_critical_moments.8013.a
		scope:scheme = { end_scheme = yes }
	}
}

# Target reaction
scheme_critical_moments.8014 = {
	type = character_event
	title = scheme_critical_moments.8014.t
	desc = scheme_critical_moments.8014.desc
	theme = administrative
	left_portrait = {
		character = root
		animation = anger
	}
	lower_right_portrait = scope:owner
	lower_left_portrait = scope:owner.top_liege

	immediate = {
		show_as_tooltip = { subsume_province_success_effect = yes }
		add_scheme_cooldown = {
			target = scope:owner
			type = subsume_province
			years = 5
		}
		if = {
			limit = { is_ai = yes }
			hidden_effect = {
				remove_opinion = {
					modifier = attempted_subsume_province_opinion
					target = scope:owner
				}
			}
			progress_towards_rival_effect = {
				REASON = rival_subsumed_province
				CHARACTER = scope:owner
				OPINION = -50
			}
		}
	}

	option = {
		name = scheme_critical_moments.8014.a
	}
}

# Notifaction event
scheme_critical_moments.8015 = {
	type = character_event
	title = scheme_critical_moments.8015.t
	desc = {
		desc = scheme_critical_moments.8015.desc
		first_valid = {
			triggered_desc = {
				trigger = { this = scope:owner.top_liege }
				desc = scheme_critical_moments.8015.liege
			}
			desc = {
				desc = scheme_critical_moments.8015.vassal
				first_valid = {
					triggered_desc = {
						trigger = {
							house = scope:target.house
							scope:target.house = scope:owner.house
						}
						desc = scheme_critical_moments.8015.same_house
					}
					triggered_desc = {
						trigger = { house = scope:target.house }
						desc = scheme_critical_moments.8015.target_house
					}
					desc = scheme_critical_moments.8015.fallback
				}
			}
		}
	}
	theme = administrative
	override_background = { reference = throne_room_scope }
	left_portrait = {
		character = scope:owner
		animation = schadenfreude
	}
	right_portrait = {
		character = scope:target
		animation = anger
	}

	trigger = {
		NOR = {
			this = scope:owner
			this = scope:target
		}
	}

	immediate = {
		scope:owner = { save_scope_as = background_throne_room_scope }
		show_as_tooltip = { subsume_province_success_effect = yes }
	}

	option = {
		name = scheme_critical_moments.8015.a
	}
}

##################################################
# Found Despotate
# Joe Parkin
# 8021 - 8024
##################################################

#	Results event for the Found Despotate scheme.
scheme_critical_moments.8021 = {
	hidden = yes

	immediate = {
		scope:scheme = {
			scheme_target_title.holder = {
				if = {
					limit = { is_governor = yes }
					save_scope_as = target
				}
				else = {
					liege = { save_scope_as = target }
				}
			}
			scheme_owner = {
				save_scope_as = owner
				#SUCCESS ROLL
				random = {
					chance = scope:scheme.scheme_success_chance
					save_scope_value_as = {
						name = scheme_successful
						value = yes
					}
					mandala_trickster_increment_successful_schemes_effect = yes
				}
				primary_title = { save_scope_as = old_primary }
				if = {
					limit = { exists = scope:scheme_successful }
					trigger_event = {
						id = scheme_critical_moments.8022
						days = 1
					}
				}
				else = {
					trigger_event = {
						id = scheme_critical_moments.8023
						days = 1
					}
				}
			}
		}
	}
}

scripted_effect found_despotate_success_effect = {
	# Save the duchy where your capital is located for use in Change 2
	capital_county.duchy = {
		save_scope_as = old_primary_title
		save_scope_as = destroyed_title
	}

	# Change 1: Give scheme owner new kingdom title and its de jure vassals
	create_title_and_vassal_change = {
		type = created
		save_scope_as = title_change
		add_claim_on_loss = no
	}
	scope:owner = {
		add_character_flag = {
			flag = successful_governorship_elevation
			days = 5
		}
		liege = { save_scope_as = liege }
	}
	scope:target_title = {
		change_title_holder = {
			holder = scope:owner
			change = scope:title_change
		}
	}
	scope:owner = {
		# Send non de jure counties back to the emperor
		every_held_title = {
			title_tier = county
			limit = {
				NOT = { target_is_de_jure_liege_or_above = scope:target_title }
			}
			change_title_holder = {
				holder = scope:owner.top_liege
				change = scope:title_change
			}
		}
		top_liege = {
			every_vassal = {
				limit = {
					this != scope:owner
					highest_held_title_tier >= tier_county
					highest_held_title_tier <= tier_duchy
					primary_title.kingdom = scope:target_title
				}
				add_to_list = transferred_vassals
				change_liege = {
					liege = scope:owner
					change = scope:title_change
				}
				if = {
					limit = {
						is_ai = yes
						highest_held_title_tier >= tier_duchy
						house != scope:owner.house
					}
					add_opinion = {
						target = scope:owner
						modifier = found_despotate_vassalized_opinion
					}
				}
			}
		}
		if = {
			limit = { liege != scope:liege }
			change_liege = {
				liege = scope:liege
				change = scope:title_change
			}
		}
	}
	resolve_title_and_vassal_change = scope:title_change

	# Change 2: trigger succession on all but the primary governorship held by the scheme owner
	create_title_and_vassal_change = {
		type = stepped_down
		save_scope_as = title_change2
		add_claim_on_loss = no
	}
	scope:owner = {
		every_held_title = {
			title_tier = duchy
			limit = {
				is_landless_type_title = no
				is_noble_family_title = no
				save_temporary_scope_as = current_duchy
				this != scope:old_primary_title
			}
			current_heir = { save_scope_as = next_holder }
			# Trigger succession for those governorships
			change_title_holder_include_vassals = {
				holder = scope:next_holder
				change = scope:title_change2
				take_baronies = no
			}
		}
	}
	resolve_title_and_vassal_change = scope:title_change2

	# Change 3: Send non de jure vassals back to the top liege
	create_title_and_vassal_change = {
		type = stepped_down
		save_scope_as = title_change3
		add_claim_on_loss = no
	}
	scope:owner = {
		every_vassal = {
			limit = {
				primary_title ={
					tier >= tier_county
					NOT = { target_is_de_jure_liege_or_above = scope:owner.primary_title }
				}
			}
			change_liege = {
				liege = scope:owner.top_liege
				change = scope:title_change3
			}
		}
	}
	resolve_title_and_vassal_change = scope:title_change3
}

# Success
scheme_critical_moments.8022 = {
	type = character_event
	title = scheme_critical_moments.8022.t
	desc = scheme_critical_moments.8022.desc
	theme = administrative
	left_portrait = {
		character = root
		animation = war_over_tie
	}
	lower_left_portrait = scope:owner.top_liege

	immediate = {
		every_player = {
			limit = {
				top_liege ?= scope:owner.top_liege
				this != scope:owner
			}
			trigger_event = scheme_critical_moments.8024
		}
		found_despotate_success_effect = yes
	}

	option = {
		name = scheme_critical_moments.8022.a
		scope:scheme = { end_scheme = yes }
	}
}

# Failure
scheme_critical_moments.8023 = {
	type = character_event
	title = scheme_critical_moments.8023.t
	desc = scheme_critical_moments.8023.desc
	theme = administrative
	left_portrait = {
		character = root
		animation = disappointed
	}
	lower_right_portrait = scope:owner.top_liege

	immediate = {
		stress_impact = {
			base = minor_stress_impact_gain
			ambitious = minor_stress_impact_gain
			deceitful = minor_stress_impact_gain
		}
	}

	#Option A: Too bad
	option = {
		name = scheme_critical_moments.8023.a
		scope:scheme = { end_scheme = yes }
	}
}

# Realm ping
scheme_critical_moments.8024 = {
	type = character_event
	title = scheme_critical_moments.8024.t
	desc = {
		desc = scheme_critical_moments.8024.desc
		first_valid = {
			triggered_desc = {
				trigger = { this = scope:owner.top_liege }
				desc = scheme_critical_moments.8024.liege
			}
			desc = {
				first_valid = {
					triggered_desc = {
						trigger = { is_in_list = transferred_vassals }
						desc = scheme_critical_moments.8024.vassalised
					}
					desc = scheme_critical_moments.8024.other
				}
				desc = scheme_critical_moments.8024.fallback
			}
		}
	}
	theme = administrative
	left_portrait = {
		character = root
		animation = war_over_tie
	}
	lower_right_portrait = scope:owner.top_liege

	immediate = {
		scope:owner = { save_scope_as = background_throne_room_scope }
		show_as_tooltip = { subsume_province_success_effect = yes }
	}

	option = {
		name = scheme_critical_moments.8024.a
	}
}

##################################################
# Raid Estate
# Joe Parkin
# 8031 - 8033
##################################################

scripted_effect raid_maiming_assignment_effect = {
	scope:scheme_maim = {
		every_in_list = {
			list = target_victims
			random_list = {
				10 = {
					trigger = {
						NOT = { has_trait = blind }
					}
					add_character_flag = raid_maiming_blind
				}
				10 = {
					trigger = {
						NOT = { has_trait = disfigured }
					}
					add_character_flag = raid_maiming_disfigured
				}
				10 = {
					trigger = {
						is_male = yes
						NOT = { has_trait = eunuch }
					}
					add_character_flag = raid_maiming_eunuch
				}
			}
		}
	}
}

#	Results event for the Raid Estate scheme.
scheme_critical_moments.8031 = {
	hidden = yes

	immediate = {
		scope:scheme = {
			scheme_target_character = {
				save_scope_as = target
				domicile ?= { save_scope_as = target_domicile }
			}
			scheme_owner = {
				save_scope_as = owner
				if = {
					limit = { var:raid_estate_permission ?= scope:target.house }
					save_scope_as = scheme_permission
				}
				#DISCOVERY ROLL
				random = {
					chance = scope:scheme.scheme_secrecy
					save_scope_value_as = {
						name = scheme_discovered
						value = yes
					}
				}
				#SUCCESS ROLL
				random = {
					chance = scope:scheme.scheme_success_chance
					save_scope_value_as = {
						name = scheme_successful
						value = yes
					}
					mandala_trickster_increment_successful_schemes_effect = yes
				}
				if = {
					limit = { exists = scope:scheme_successful }
					save_scope_value_as = {
						name = gold
						value = {
							value = scope:target.tiny_gold_value
							multiply = scope:target_domicile.num_domicile_buildings
							add = scope:target.tiny_gold_value
						}
					}
					if = { # Successful imprisonment always exposes involvement
						limit = { exists = scope:scheme_imprison }
						save_scope_value_as = {
							name = scheme_discovered
							value = yes
						}
					}
					scope:target_domicile = { destroy_random_estate_building_variable_effect = yes }
					scope:target.house = {
						every_house_member = {
							limit = {
								age >= 8
								is_playable_character = no
								trigger_if = {
									limit = { exists = primary_spouse }
									primary_spouse = { is_landed = no }
								}
								top_liege = scope:target.top_liege
								this != scope:target
							}
							add_to_list = target_house_members
						}
						ordered_in_list = {
							list = target_house_members
							limit = {
								trigger_if = {
									limit = { exists = scope:scheme_maim }
									NOR = {
										has_trait = blind
										has_trait = eunuch_1
										has_trait = disfigured
									}
								}
							}
							order_by = {
								value = 1
								if = {
									limit = { is_adult = yes }
									add = 10
								}
								if = {
									limit = { this = scope:target.player_heir }
									add = -10
								}
								if = {
									limit = {
										can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:target }
									}
									add = 10
								}
							}
							check_range_bounds = no
							max = 3
							add_to_list = target_victims
						}
						random_in_list = {
							list = target_victims
							limit = { is_heir_of = scope:target }
							alternative_limit = { is_child_of = scope:target }
							alternative_limit = { is_close_family_of = scope:target }
							alternative_limit = { always = yes }
							save_scope_as = flavor_victim
						}
					}
					random = {
						chance = {
							value = scope:scheme.scheme_success_chance
							divide = 2
						}
						save_scope_value_as = {
							name = scheme_critical_success
							value = yes
						}
					}
					# Bonus Rewards
					random_list = {
						10 = { # Steal an Artifact
							trigger = {
								scope:target = {
									any_character_artifact = { is_equipped = no }
								}
							}
							modifier = {
								exists = scope:scheme_discovered
								factor = 2
							}
							modifier = {
								exists = scope:scheme_critical_success
								factor = 2
							}
							scope:target = {
								random_character_artifact = {
									limit = {
										is_equipped = no
										NOT = { has_variable = artifact_prevent_transfer }
									}
									weight = {
										base = 1
										# Prefer worse artifacts
										modifier = {
											rarity = masterwork
											factor = 5
										}
										modifier = {
											rarity = common
											factor = 10
										}
										# Prefer equippable artifacts
										modifier = {
											scope:owner = { can_equip_artifact = prev }
											factor = 2
										}
										# Don't like banners
										modifier = {
											exists = var:banner_dynasty
											factor = 0.1
										}
										modifier = {
											exists = var:banner_house
											factor = 0.1
										}
									}
									save_scope_as = stolen_artifact
								}
							}
						}
						10 = { # Building
							trigger = {
								scope:target_domicile = {
									OR = {
										has_domicile_building_or_higher = living_quarters_01
										has_domicile_building_or_higher = trophy_room_01
										has_domicile_building_or_higher = office_01
										has_domicile_building_or_higher = servants_quarters_01
										has_domicile_building_or_higher = library_01
										has_domicile_building_or_higher = bath_01
										has_domicile_building_or_higher = guest_room_01
										has_domicile_building_or_higher = wine_cellar_01
										has_domicile_building_or_higher = prison_01
										has_domicile_building_or_higher = reception_hall_01
										has_domicile_building_or_higher = cabinet_of_curiosities_01
										has_domicile_building_or_higher = grand_solar_01
										has_domicile_building_or_higher = temple_small_01
										has_domicile_building_or_higher = barracks_01
										has_domicile_building_or_higher = watchtower_01
										has_domicile_building_or_higher = guardhouse_01
										has_domicile_building_or_higher = garden_01
										has_domicile_building_or_higher = stable_01
										has_domicile_building_or_higher = workshop_01
										has_domicile_building_or_higher = storage_01
										has_domicile_building_or_higher = grazing_land_01
										has_domicile_building_or_higher = grain_field_01
										has_domicile_building_or_higher = vineyard_01
										has_domicile_building_or_higher = olive_01
										has_domicile_building_or_higher = silk_01
									}
								}
							}
							random_list = {
								10 = { # Diplomacy Upgrade
									trigger = {
										ep3_raid_insight_trigger = { TYPE = living_quarters }
										scope:owner.domicile ?= {
											NOT = { has_domicile_building = living_quarters_04 }
										}
									}
									save_scope_value_as = { name = stolen_building value = flag:living_quarters }
								}
								10 = { # Martial Upgrade
									trigger = {
										ep3_raid_insight_trigger = { TYPE = trophy_room }
										scope:owner.domicile ?= {
											NOT = { has_domicile_building = trophy_room_04 }
										}
									}
									save_scope_value_as = { name = stolen_building value = flag:trophy_room }
								}
								10 = { # Stewardship Upgrade
									trigger = {
										ep3_raid_insight_trigger = { TYPE = office }
										scope:owner.domicile ?= {
											NOT = { has_domicile_building = office_04 }
										}
									}
									save_scope_value_as = { name = stolen_building value = flag:office }
								}
								10 = { # Intrigue Upgrade
									trigger = {
										ep3_raid_insight_trigger = { TYPE = servants_quarters }
										scope:owner.domicile ?= {
											NOT = { has_domicile_building = servants_quarters_04 }
										}
									}
									save_scope_value_as = { name = stolen_building value = flag:servants_quarters }
								}
								10 = { # Learning Upgrade
									trigger = {
										ep3_raid_insight_trigger = { TYPE = library }
										scope:owner.domicile ?= {
											NOR = {
												has_domicile_building = library_observatory_04
												has_domicile_building = library_education_04
											}
										}
									}
									save_scope_value_as = { name = stolen_building value = flag:library }
								}
								10 = { # Bath
									trigger = {
										ep3_raid_insight_trigger = { TYPE = bath }
										scope:owner.domicile ?= {
											NOT = { has_domicile_building = bath_04 }
										}
									}
									save_scope_value_as = { name = stolen_building value = flag:bath }
								}
								10 = { # Guest Room
									trigger = {
										ep3_raid_insight_trigger = { TYPE = guest_room }
										scope:owner.domicile ?= {
											NOT = { has_domicile_building = guest_room_06 }
										}
									}
									save_scope_value_as = { name = stolen_building value = flag:guest_room }
								}
								10 = { # Wine Cellar
									trigger = {
										ep3_raid_insight_trigger = { TYPE = wine_cellar }
										scope:owner.domicile ?= {
											NOT = { has_domicile_building = wine_cellar_03 }
										}
									}
									save_scope_value_as = { name = stolen_building value = flag:wine_cellar }
								}
								10 = { # Courtyard
									trigger = {
										ep3_raid_insight_trigger = { TYPE = courtyard }
										scope:owner.domicile ?= {
											NOT = { has_domicile_building = courtyard_04 }
										}
									}
									save_scope_value_as = { name = stolen_building value = flag:courtyard }
								}
								10 = { # Prison
									trigger = {
										ep3_raid_insight_trigger = { TYPE = prison }
										scope:owner.domicile ?= {
											NOT = { has_domicile_building = prison_04 }
										}
									}
									save_scope_value_as = { name = stolen_building value = flag:prison }
								}
								10 = { # Reception Hall
									trigger = {
										ep3_raid_insight_trigger = { TYPE = reception_hall }
										scope:owner.dynasty ?= { has_dynasty_perk = ep3_administrative_legacy_3 }
										scope:owner.domicile ?= {
											NOT = { has_domicile_building = reception_hall_05 }
										}
									}
									save_scope_value_as = { name = stolen_building value = flag:reception_hall }
								}
								10 = { # Cabinet of Curiosities
									trigger = {
										ep3_raid_insight_trigger = { TYPE = cabinet_of_curiosities }
										scope:owner.dynasty ?= { has_dynasty_perk = ep3_administrative_legacy_4 }
										scope:owner.domicile ?= {
											NOT = { has_domicile_building = cabinet_of_curiosities_03 }
										}
									}
									save_scope_value_as = { name = stolen_building value = flag:cabinet_of_curiosities }
								}
								10 = { # Grand Solar
									trigger = {
										ep3_raid_insight_trigger = { TYPE = grand_solar }
										scope:owner.house.house_head = { has_character_flag = ep3_construct_grand_solar }
										scope:owner.domicile ?= {
											NOT = { has_domicile_building = grand_solar_04 }
										}
									}
									save_scope_value_as = { name = stolen_building value = flag:grand_solar }
								}
								10 = { # Temple
									trigger = {
										scope:owner = {
											NOT = { has_character_modifier = raid_insight_temple }
										}
										scope:target_domicile = { has_domicile_building_or_higher = temple_small_01 }
										scope:owner.domicile ?= {
											NOR = {
												has_domicile_building = temple_crypt_06
												has_domicile_building = temple_large_06
												has_domicile_building = temple_monastery_06
											}
										}
									}
									save_scope_value_as = { name = stolen_building value = flag:temple }
								}
								10 = { # Watchtower
									trigger = {
										ep3_raid_insight_trigger = { TYPE = barracks }
										scope:owner.domicile ?= {
											NOT = { has_domicile_building = barracks_06 }
										}
									}
									save_scope_value_as = { name = stolen_building value = flag:barracks }
								}
								10 = { # Watchtower
									trigger = {
										ep3_raid_insight_trigger = { TYPE = watchtower }
										scope:owner.domicile ?= {
											NOT = { has_domicile_building = watchtower_06 }
										}
									}
									save_scope_value_as = { name = stolen_building value = flag:watchtower }
								}
								10 = { # Guardhouse
									trigger = {
										ep3_raid_insight_trigger = { TYPE = guardhouse }
										scope:owner.domicile ?= {
											NOT = { has_domicile_building = guardhouse_04 }
										}
									}
									save_scope_value_as = { name = stolen_building value = flag:guardhouse }
								}
								10 = { # Garden
									trigger = {
										ep3_raid_insight_trigger = { TYPE = garden }
										scope:owner.domicile ?= {
											NOR = {
												has_domicile_building = garden_leisure_06
												has_domicile_building = garden_fruit_06
											}
										}
									}
									save_scope_value_as = { name = stolen_building value = flag:garden }
								}
								10 = { # Stable
									trigger = {
										ep3_raid_insight_trigger = { TYPE = stable }
										scope:owner.domicile ?= {
											NOR = {
												has_domicile_building = stable_grand_06
												has_domicile_building = stable_kennel_06
												has_domicile_building = stable_chariot_06
											}
										}
									}
									save_scope_value_as = { name = stolen_building value = flag:stable }
								}
								10 = { # Workshop
									trigger = {
										ep3_raid_insight_trigger = { TYPE = workshop }
										scope:owner.domicile ?= {
											NOR = {
												has_domicile_building = workshop_carpenter_06
												has_domicile_building = workshop_mason_06
												has_domicile_building = workshop_textile_06
											}
										}
									}
									save_scope_value_as = { name = stolen_building value = flag:workshop }
								}
								10 = { # Storage
									trigger = {
										ep3_raid_insight_trigger = { TYPE = storage }
										scope:owner.domicile ?= {
											NOR = {
												has_domicile_building = storage_warehouse_04
												has_domicile_building = storage_granary_04
											}
										}
									}
									save_scope_value_as = { name = stolen_building value = flag:storage }
								}
								10 = { # Market
									trigger = {
										ep3_raid_insight_trigger = { TYPE = market }
										scope:owner.domicile ?= {
											NOT = { has_domicile_building = market_06 }
										}
									}
									save_scope_value_as = { name = stolen_building value = flag:market }
								}
								10 = { # Grazing Lands
									trigger = {
										ep3_raid_insight_trigger = { TYPE = grazing_land }
										scope:owner.domicile ?= {
											NOR = {
												has_domicile_building = grazing_land_06
												has_domicile_building = horse_pasture_06
												has_domicile_building = camel_pasture_06
												has_domicile_building = elephant_pasture_06
											}
										}
									}
									save_scope_value_as = { name = stolen_building value = flag:grazing_land }
								}
								10 = { # Grain Field
									trigger = {
										ep3_raid_insight_trigger = { TYPE = grain_field }
										scope:owner.domicile ?= {
											NOT = { has_domicile_building = grain_field_06 }
										}
									}
									save_scope_value_as = { name = stolen_building value = flag:grain_field }
								}
								10 = { # Vineyard
									trigger = {
										ep3_raid_insight_trigger = { TYPE = vineyard }
										scope:owner.domicile ?= {
											NOT = { has_domicile_building = vineyard_06 }
										}
									}
									save_scope_value_as = { name = stolen_building value = flag:vineyard }
								}
								10 = { # Olive Plantation
									trigger = {
										ep3_raid_insight_trigger = { TYPE = olive }
										scope:owner.domicile ?= {
											NOT = { has_domicile_building = olive_06 }
										}
									}
									save_scope_value_as = { name = stolen_building value = flag:olive }
								}
								10 = { # Silk Production
									trigger = {
										ep3_raid_insight_trigger = { TYPE = silk }
										scope:owner.house = { has_house_modifier = ep3_unlocked_silk }
										scope:owner.domicile ?= {
											NOT = { has_domicile_building = silk_06 }
										}
									}
									save_scope_value_as = { name = stolen_building value = flag:silk }
								}
								10 = { # Tea Plantation
									trigger = {
										scope:owner = {
											NOT = { has_character_modifier = raid_insight_tea }
										}
										scope:target_domicile = { has_domicile_building_or_higher = japanese_tea_plantation_01 }
										scope:owner.domicile ?= {
											NOT = { has_domicile_building = japanese_tea_plantation_06 }
										}
									}
									save_scope_value_as = { name = stolen_building value = flag:tea }
								}
							}
						}
					}
					#Need to pre assign random maiming
					if = {
						limit = {
							exists = scope:scheme_maim
						}
						raid_maiming_assignment_effect = yes
					}
					trigger_event = {
						id = scheme_critical_moments.8032
						days = 1
					}
				}
				else = {
					scope:scheme = {
						if = {
							limit = { exists = scope:scheme_discovered }
							random_scheme_agent_character = {
								limit = { is_alive = yes }
								weight = {
									base = 1
									modifier = {
										add = {
											value = 20
											subtract = intrigue
											subtract = prowess
										}
									}
								}
								save_scope_as = captured
							}
						}
					}
					trigger_event = {
						id = scheme_critical_moments.8033
						days = 1
					}
				}
			}
		}
	}
}

scripted_effect raid_estate_success_effect = {
	raid_estate_success_public_effect = yes
	if = {
		limit = { exists = scope:stolen_artifact }
		scope:stolen_artifact = {
			set_owner = {
				target = scope:owner
				history = {
					location = scope:target_domicile.domicile_location
					actor = scope:owner
					recipient = scope:owner
					type = stolen
				}
			}
		}
	}
	else_if = {
		limit = { exists = scope:stolen_building }
		scope:owner = {
			switch = {
				trigger = scope:stolen_building
				flag:living_quarters = { ep3_raid_insight_effect = { TYPE = living_quarters } }
				flag:trophy_room = { ep3_raid_insight_effect = { TYPE = trophy_room } }
				flag:office = { ep3_raid_insight_effect = { TYPE = office } }
				flag:servants_quarters = { ep3_raid_insight_effect = { TYPE = servants_quarters } }
				flag:library = { ep3_raid_insight_effect = { TYPE = library } }
				flag:bath = { ep3_raid_insight_effect = { TYPE = bath } }
				flag:guest_room = { ep3_raid_insight_effect = { TYPE = guest_room } }
				flag:wine_cellar = { ep3_raid_insight_effect = { TYPE = wine_cellar } }
				flag:prison = { ep3_raid_insight_effect = { TYPE = prison } }
				flag:reception_hall = { ep3_raid_insight_effect = { TYPE = reception_hall } }
				flag:cabinet_of_curiosities = { ep3_raid_insight_effect = { TYPE = cabinet_of_curiosities } }
				flag:grand_solar = { ep3_raid_insight_effect = { TYPE = grand_solar } }
				flag:temple = { ep3_raid_insight_effect = { TYPE = temple } }
				flag:barracks = { ep3_raid_insight_effect = { TYPE = barracks } }
				flag:watchtower = { ep3_raid_insight_effect = { TYPE = watchtower } }
				flag:guardhouse = { ep3_raid_insight_effect = { TYPE = guardhouse } }
				flag:garden = { ep3_raid_insight_effect = { TYPE = garden } }
				flag:stable = { ep3_raid_insight_effect = { TYPE = stable } }
				flag:workshop = { ep3_raid_insight_effect = { TYPE = workshop } }
				flag:storage = { ep3_raid_insight_effect = { TYPE = storage } }
				flag:grazing_land = { ep3_raid_insight_effect = { TYPE = grazing_land } }
				flag:grain_field = { ep3_raid_insight_effect = { TYPE = grain_field } }
				flag:vineyard = { ep3_raid_insight_effect = { TYPE = vineyard } }
				flag:olive = { ep3_raid_insight_effect = { TYPE = olive } }
				flag:silk = { ep3_raid_insight_effect = { TYPE = silk } }
				flag:tea = { ep3_raid_insight_effect = { TYPE = tea } }
			}
		}
	}
	if = {
		limit = {
			NOT = { exists = scope:scheme_discovered }
		}
		scope:owner = {
			add_secret = {
				type = secret_raid_estate
				target = scope:target
			}
			random_secret = {
				type = secret_raid_estate
				limit = {
					secret_target = scope:target
					NOT = { exists = var:house }
				}
				save_scope_as = secret
				set_variable = {
					name = house
					value = scope:target.house
				}
				if = {
					limit = { exists = scope:scheme_maim }
					set_variable = {
						name = maim
						value = flag:yes
					}
				}
				every_in_list = {
					list = target_victims
					save_scope_as = secret_victim
					scope:secret = {
						add_to_variable_list = {
							name = victims
							target = scope:secret_victim
						}
					}
				}
			}
		}
	}
}

scripted_effect raid_estate_success_public_effect = {
	scope:owner = { add_short_term_gold = scope:gold }
	scope:target = { change_influence = medium_influence_loss }
	switch = {
		trigger = exists
		scope:scheme_kill = {
			every_in_list = {
				list = target_victims
				death = {
					death_reason = death_raid_estate
					killer = scope:owner
				}
				if = {
					limit = { exists = scope:scheme_discovered }
					hidden_effect = { set_killer_public = yes }
				}
			}
		}
		scope:scheme_maim = {
			every_in_list = {
				list = target_victims
				random_list = {
					10 = {
						trigger = {
							NOT = { has_trait = blind }
						}
						hidden_effect = {
							if = {
								limit = { has_trait = one_eyed }
								remove_trait = one_eyed
							}
						}
						add_trait = blind
					}
					10 = {
						trigger = {
							NOT = { has_trait = disfigured }
						}
						add_trait = disfigured
					}
					10 = {
						trigger = {
							is_male = yes
							NOT = { has_trait = eunuch }
						}
						add_trait = eunuch_1
					}
				}
			}
		}
		scope:scheme_imprison = {
			every_in_list = {
				list = target_victims
				save_scope_as = victim
				rightfully_imprison_character_less_verbose_effect = {
					TARGET = scope:victim
					IMPRISONER = scope:owner
				}
			}
		}
	}
	scope:target_domicile = { destroy_random_estate_building_effect = yes }
	scope:target.house = {
		if = {
			limit = {
				scope:target.domicile ?= { is_domicile_type = japanese_manor }
			}
			add_house_modifier = {
				modifier = ep3_manor_raided_modifier
				years = 5
			}
		}
		else = {
			add_house_modifier = {
				modifier = ep3_estate_raided_modifier
				years = 5
			}
		}
	}
	if = {
		limit = { exists = scope:scheme_discovered }
		raid_estate_opinion_effect = {
			OWNER = scope:owner
			TARGET = scope:target
		}
	}
	scope:owner = {
		if = {
			limit = { var:raid_estate_permission ?= scope:target.house }
			remove_variable =  raid_estate_permission
		}
		else = {
			tgp_activate_catalyst_against_hegemon_effect = {
				HEGEMON = scope:target.top_liege
				CATALYST = catalyst_governor_raided_estate
			}
		}
	}
}

# Success
scheme_critical_moments.8032 = {
	type = character_event
	title = scheme_critical_moments.8032.t
	desc = {
		desc = scheme_critical_moments.8032.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:scheme_kill
					any_in_list = {
						list = target_victims
						count > 0
					}
				}
				desc = scheme_critical_moments.8032.kill
			}
			triggered_desc = {
				trigger = {
					exists = scope:scheme_maim
					any_in_list = {
						list = target_victims
						count > 0
					}
				}
				desc = scheme_critical_moments.8032.maim
			}
			triggered_desc = {
				trigger = {
					exists = scope:scheme_imprison
					any_in_list = {
						list = target_victims
						count > 0
					}
				}
				desc = scheme_critical_moments.8032.imprison
			}
			desc = scheme_critical_moments.8032.fallback
		}
		first_valid = {
			triggered_desc = {
				trigger = { scope:owner = scope:owner.top_liege }
				desc = scheme_critical_moments.8032.emperor
			}
			triggered_desc = {
				trigger = { exists = scope:scheme_permission }
				desc = scheme_critical_moments.8032.permission
			}
			triggered_desc = {
				trigger = { exists = scope:scheme_discovered }
				desc = scheme_critical_moments.8032.crime
			}
			desc = scheme_critical_moments.8032.secret
		}
	}
	theme = intrigue
	left_portrait = {
		character = scope:target
		triggered_animation = {
			trigger = {
				exists = scope:scheme_kill
				any_in_list = {
					list = target_victims
					count > 0
				}
			}
			animation = grief
		}
		triggered_animation = {
			trigger = {
				exists = scope:scheme_maim
				any_in_list = {
					list = target_victims
					count > 0
				}
			}
			animation = rage
		}
		animation = disbelief
	}
	lower_left_portrait = scope:flavor_victim
	lower_right_portrait = {
		trigger = {
			scope:owner.top_liege != scope:owner
			scope:owner.top_liege != scope:target
			exists = scope:scheme_discovered
		}
		character = scope:owner.top_liege
	}
	override_background = { reference = burning_building }

	immediate = {
		play_music_cue = "mx_cue_murder"

		scope:target = { trigger_event = scheme_critical_moments.8034 } # Trigger the response event for the target
		raid_estate_success_effect = yes
		if = {
			limit = {
				is_ai = no
				exists = scope:scheme_permission
				house ?= { is_powerful_family = no }
				scope:target.house ?= { is_powerful_family = yes }
			}
			add_achievement_global_variable_effect = {
				VARIABLE = achieved_i_got_a_permit_achievement
				VALUE = yes
			}
		}
	}

	option = {
		name = {
			trigger = { exists = scope:scheme_discovered }
			text = scheme_critical_moments.8032.a
		}
		name = {
			trigger = {
				NOT = { exists = scope:scheme_discovered }
			}
			text = scheme_critical_moments.8032.a.secret
		}
		scope:scheme = { end_scheme = yes }
	}
	after = {
		#Hidden event that cleans up flags
		if = {
			limit = {
				exists = scope:scheme_maim
			}
			trigger_event = {
				id = scheme_critical_moments.8999
				days = 30
			}
		}

	}
}

scheme_critical_moments.8999 = {
	hidden = yes
	immediate = {
		scope:scheme_maim = {
			every_in_list = {
				list = target_victims
				remove_character_flag = raid_maiming_eunuch
				remove_character_flag = raid_maiming_blind
				remove_character_flag = raid_maiming_disfigured
			}
		}
	}
}

scripted_effect raid_estate_failure_effect = {
	if = {
		limit = { exists = scope:scheme_discovered }
		if = {
			limit = { exists = scope:captured }
			scope:captured = {
				add_character_flag = {
					flag = was_abducted_block_notification_event
					days = 2
				}
			}
			rightfully_imprison_character_less_verbose_effect = {
				TARGET = scope:captured
				IMPRISONER = scope:target
			}
		}
		scope:target.house = {
			house_head = {
				add_opinion = {
					target = scope:owner
					modifier = attempted_raid_estate_crime
				}
			}
			change_house_relation_effect = {
				HOUSE = scope:owner.house
				VALUE = house_relation_damage_medium_value
				REASON = raided_estate_attempt
                CHAR = scope:owner
                TARGET_CHAR = scope:target
                TITLE = scope:dummy_gender
			}
		}
	}
}

# Failure
scheme_critical_moments.8033 = {
	type = character_event
	title = scheme_critical_moments.8033.t
	desc = {
		desc = scheme_critical_moments.8033.desc
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:captured }
				desc = scheme_critical_moments.8033.captured
			}
			triggered_desc = {
				trigger = { exists = scope:scheme_discovered }
				desc = scheme_critical_moments.8033.discovered
			}
			desc = scheme_critical_moments.8033.fallback
		}
		first_valid = {
			triggered_desc = {
				trigger = { scope:owner = scope:owner.top_liege }
				desc = scheme_critical_moments.8032.emperor
			}
			triggered_desc = {
				trigger = { exists = scope:scheme_permission }
				desc = scheme_critical_moments.8032.permission
			}
		}
	}
	theme = intrigue
	left_portrait = {
		character = scope:target
		animation = anger
	}
	right_portrait = {
		character = scope:captured
		animation = prisonhouse
		override_imprisonment_visuals = yes
	}
	lower_right_portrait = {
		trigger = {
			scope:owner.top_liege != scope:owner
			scope:owner.top_liege != scope:target
			exists = scope:scheme_discovered
		}
		character = scope:owner.top_liege
	}
	override_background = { reference = estate }

	immediate = {
		play_music_cue = "mx_cue_murder"
		scope:target = { trigger_event = scheme_critical_moments.8034 } # Trigger the response event for the target
		raid_estate_failure_effect = yes
		stress_impact = {
			base = minor_stress_impact_gain
			ambitious = minor_stress_impact_gain
			deceitful = minor_stress_impact_gain
		}
	}

	#Option A: Too bad
	option = {
		name = scheme_critical_moments.8033.a
		scope:scheme = { end_scheme = yes }
	}
}

# Target
scheme_critical_moments.8034 = {
	type = character_event
	title = {
		desc = {
			first_valid = {
				triggered_desc = {
					trigger = { exists = scope:scheme_discovered }
					desc = scheme_critical_moments.8034.t.known
				}
				desc = scheme_critical_moments.8034.t
			}
		}
	}
	desc = {
		desc = scheme_critical_moments.8034.desc
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:scheme_successful }
				desc = scheme_critical_moments.8034.success
			}
			desc = scheme_critical_moments.8034.failure
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:scheme_kill
					any_in_list = {
						list = target_victims
						count > 0
					}
				}
				desc = scheme_critical_moments.8034.kill
			}
			triggered_desc = {
				trigger = {
					exists = scope:scheme_maim
					any_in_list = {
						list = target_victims
						count > 0
					}
				}
				desc = scheme_critical_moments.8034.maim
			}
			triggered_desc = {
				trigger = {
					exists = scope:scheme_imprison
					any_in_list = {
						list = target_victims
						count > 0
					}
				}
				desc = scheme_critical_moments.8034.imprison
			}
			triggered_desc = {
				trigger = { exists = scope:captured }
				desc = scheme_critical_moments.8034.captured
			}
		}
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:scheme_discovered }
				desc = scheme_critical_moments.8034.discovered
			}
			desc = scheme_critical_moments.8034.fallback
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:scheme_discovered
					scope:owner = scope:owner.top_liege
				}
				desc = scheme_critical_moments.8034.emperor
			}
			triggered_desc = {
				trigger = {
					exists = scope:scheme_discovered
					exists = scope:scheme_permission
				}
				desc = scheme_critical_moments.8034.permission
			}
			triggered_desc = {
				trigger = { exists = scope:scheme_discovered }
				desc = scheme_critical_moments.8034.crime
			}
		}
	}
	theme = intrigue
	left_portrait = {
		character = scope:target
		triggered_animation = {
			trigger = {
				exists = scope:scheme_successful
				exists = scope:scheme_kill
			}
			animation = grief
		}
		triggered_animation = {
			trigger = {
				exists = scope:scheme_successful
				exists = scope:scheme_maim
			}
			animation = rage
		}
		triggered_animation = {
			trigger = { exists = scope:scheme_successful }
			animation = disbelief
		}
		animation = anger
	}
	right_portrait = {
		character = scope:captured
		animation = prisonhouse
		override_imprisonment_visuals = yes
	}
	lower_left_portrait = scope:flavor_victim
	lower_center_portrait = {
		character = scope:owner
		trigger = { exists = scope:scheme_discovered }
	}
	lower_right_portrait = {
		trigger = {
			scope:owner.top_liege != scope:owner
			scope:owner.top_liege != scope:target
		}
		character = scope:owner.top_liege
	}
	override_background = {
		trigger = { exists = scope:scheme_successful }
		reference = burning_building
	}
	override_background = {
		trigger = {
			NOT = { exists = scope:scheme_successful }
		}
		reference = estate
	}

	immediate = {
		play_music_cue = "mx_cue_murder"
		show_as_tooltip = {
			if = {
				limit = { exists = scope:scheme_successful }
				raid_estate_success_public_effect = yes
			}
			else = { raid_estate_failure_effect = yes }
		}
	}

	option = {
		name = {
			text = scheme_critical_moments.8034.a.discovered
			trigger = { exists = scope:scheme_discovered }
		}
		name = {
			text = scheme_critical_moments.8034.a
			trigger = {
				NOT = { exists = scope:scheme_discovered }
			}
		}
	}
}

# Choice
scheme_critical_moments.8035 = {
	type = character_event
	title = scheme_critical_moments.8035.t
	desc = {
		desc = scheme_critical_moments.8035.desc
		first_valid = {
			triggered_desc = {
				trigger = { scope:owner = scope:owner.top_liege }
				desc = scheme_critical_moments.8035.emperor
			}
			triggered_desc = {
				trigger = { exists = scope:scheme_permission }
				desc = scheme_critical_moments.8035.permission
			}
			desc = scheme_critical_moments.8035.crime
		}
	}
	theme = intrigue
	left_portrait = {
		character = scope:owner
		animation = menacing
	}
	lower_left_portrait = {
		character = scope:owner.top_liege
		trigger = {
			NOR = {
				scope:owner.top_liege = scope:owner
				scope:owner.top_liege = scope:target
			}
			exists = scope:scheme_discovered
		}
	}
	lower_right_portrait = scope:target
	override_background = { reference = study }

	trigger = {
		scope:scheme.scheme_target_character.house = {
			any_house_member = {
				age >= 8
				is_playable_character = no
				trigger_if = {
					limit = { exists = primary_spouse }
					primary_spouse = { is_landed = no }
				}
				top_liege = scope:scheme.scheme_target_character.top_liege
				this != scope:scheme.scheme_target_character
			}
		}
	}

	on_trigger_fail = {
		scope:scheme = {
			scheme_target_character = {
				save_scope_as = target
				domicile ?= { save_scope_as = target_domicile }
			}
			scheme_owner = { save_scope_as = owner }
		}
		trigger_event = scheme_critical_moments.8031
	}

	immediate = {
		scope:scheme = {
			scheme_target_character = {
				save_scope_as = target
				domicile ?= { save_scope_as = target_domicile }
			}
			scheme_owner = { save_scope_as = owner }
		}
	}

	option = {
		name = scheme_critical_moments.8035.a
		custom_tooltip = scheme_critical_moments.8035.a.tt
		save_scope_as = scheme_kill
		stress_impact = {
			forgiving = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
			just = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_compassion = -1
				ai_boldness = 1
				ai_vengefulness = 1
			}
			modifier = {
				NOT = { has_relation_rival = scope:owner }
				add = -1000
			}
		}
	}

	option = {
		name = scheme_critical_moments.8035.b
		custom_tooltip = scheme_critical_moments.8035.b.tt
		save_scope_as = scheme_maim
		stress_impact = {
			forgiving = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
			just = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100000
			ai_value_modifier = {
				ai_compassion = -0.5
				ai_boldness = 0.5
				ai_vengefulness = 0.5
			}
			modifier = {
				NOT = { has_relation_rival = scope:owner }
				factor = 0.5
			}
		}
	}

	option = {
		name = scheme_critical_moments.8035.c
		custom_tooltip = scheme_critical_moments.8035.c.tt
		custom_tooltip = scheme_critical_moments.8035.c.warning
		save_scope_as = scheme_imprison
		ai_chance = { base = 0 }
	}

	option = {
		name = scheme_critical_moments.8035.d
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_compassion = 0.5
				ai_boldness = -0.5
				ai_vengefulness = -0.5
			}
		}
	}

	after = {
		custom_tooltip = scheme_critical_moments.8035.tt
		trigger_event = scheme_critical_moments.8031
	}
}

##################################################
# Teach Governor
# Joe Parkin
# 8041 - 8043
##################################################

scripted_effect teach_governor_track_effect = {
	if = {
		limit = { has_trait_xp = { trait = governor value >= 100 } }
		save_scope_value_as = { name = $NAME$_track value = 4 }
	}
	else_if = {
		limit = { has_trait_xp = { trait = governor value >= 75 } }
		save_scope_value_as = { name = $NAME$_track value = 3 }
	}
	else_if = {
		limit = { has_trait_xp = { trait = governor value >= 50 } }
		save_scope_value_as = { name = $NAME$_track value = 2 }
	}
	else_if = {
		limit = { has_trait_xp = { trait = governor value >= 25 } }
		save_scope_value_as = { name = $NAME$_track value = 1 }
	}
	else_if = { # Emperors get a number assignment even if they don't have the governor trait
		limit = {
			NOT = { has_trait = governor }
			primary_title.tier = tier_empire
		}
		save_scope_value_as = { name = $NAME$_track value = 2 }
	}
	else_if = { # Kings get a number assignment even if they don't have the governor trait
		limit = {
			NOT = { has_trait = governor }
			primary_title.tier = tier_kingdom
		}
		save_scope_value_as = { name = $NAME$_track value = 1 }
	}
	else = {
		save_scope_value_as = { name = $NAME$_track value = 0 }
	}
}

scripted_effect teach_governor_relative_effect = {
	scope:owner = {
		teach_governor_track_effect = { NAME = owner }
	}
	scope:target = {
		teach_governor_track_effect = { NAME = target }
	}
	save_scope_value_as = {
		name = diff_track
		value = {
			value = scope:owner_track
			subtract = scope:target_track
		}
	}
}

#	Results event for the Teach Governor scheme.
scheme_critical_moments.8041 = {
	hidden = yes

	immediate = {
		scope:scheme = {
			scheme_target_character = { save_scope_as = target }
			scheme_owner = { save_scope_as = owner }
			teach_governor_relative_effect = yes
			scheme_owner = {
				#SUCCESS ROLL
				random = {
					chance = scope:scheme.scheme_success_chance
					save_scope_value_as = {
						name = scheme_successful
						value = yes
					}
					mandala_trickster_increment_successful_schemes_effect = yes
				}
				if = {
					limit = { exists = scope:scheme_successful }
					trigger_event = {
						id = scheme_critical_moments.8042
						days = 1
					}
				}
				else = {
					trigger_event = {
						id = scheme_critical_moments.8043
						days = 1
					}
				}
			}
		}
	}
}

scripted_effect teach_governor_success_effect = {
	scope:owner = {
		change_influence = medium_influence_gain
		if = {
			limit = { NOT = { has_trait = governor } }
			add_trait = governor
		}
		if = {
			limit = { scope:owner_track < 4 }
			add_trait_xp = {
				trait = governor
				value = {
					value = 3
					if = { # Target has nothing to teach you
						limit = { scope:diff_track > 0 } # Higher Governor tier than target
						divide = scope:diff_track
					}
					else_if = { # Target has much to teach you
						limit = { scope:diff_track < 0 } # Lower Governor tier than target
						add = {
							value = 3
							multiply = scope:diff_track
							abs = yes
						}
					}
					multiply = 3
					ceiling = yes
				}
			}
		}
		if = {
			limit = { scope:target.house != house }
			add_hook = {
				type = favor_hook
				target = scope:target
				years = 5
			}
		}
		random_list = {
			50 = {
				progress_towards_friend_effect = {
					REASON = friend_mentored_in_governance
					CHARACTER = scope:target
					OPINION = default_friend_opinion
				}
			}
			50 = {
				reverse_add_opinion = {
					modifier = teach_governor_opinion
					target = scope:target
				}
			}
		}
	}
	scope:target = {
		if = {
			limit = { NOT = { has_trait = governor } }
			add_trait = governor
		}
		if = {
			limit = { scope:target_track < 4 }
			add_trait_xp = {
				trait = governor
				value = {
					value = 5
					if = { # Owner has much to teach you
						limit = { scope:diff_track > 0 }
						add = {
							value = 5
							multiply = scope:diff_track
						}
					}
					else_if = { # Target has nothing to teach you
						limit = { scope:diff_track < 0 } # Higher Governor tier than owner
						divide = {
							value = scope:diff_track
							abs = yes
						}
					}
					multiply = 4
					ceiling = yes
				}
			}
			add_character_modifier = {
				modifier = ep3_recently_mentored_governor
				years = 10
			}
		}
	}
}

# Success
scheme_critical_moments.8042 = {
	type = character_event
	title = scheme_critical_moments.8042.t
	desc = scheme_critical_moments.8042.desc
	theme = administrative
	left_portrait = {
		character = scope:owner
		animation = admiration
	}
	right_portrait = {
		character = scope:target
		animation = writing
	}
	override_background = { reference = study }

	immediate = {
		# Trigger the response event for the target
		scope:target = { trigger_event = scheme_critical_moments.8044 }
		teach_governor_success_effect = yes
	}

	option = {
		name = scheme_critical_moments.8042.a
		scope:scheme = { end_scheme = yes }
	}
}

# Failure
scheme_critical_moments.8043 = {
	type = character_event
	title = scheme_critical_moments.8043.t
	desc = scheme_critical_moments.8043.desc
	theme = administrative
	left_portrait = {
		character = scope:owner
		animation = disappointed
	}
	right_portrait = {
		character = scope:target
		animation = dismissal
	}
	override_background = { reference = study }

	immediate = {
		scope:target = {
			if = {
				limit = {
					is_alive = yes
					is_ai = yes
				}
				hidden_effect = {
					remove_opinion = {
						target = scope:owner
						modifier = mentoring_governor_opinion
					}
				}
				add_opinion = {
					target = scope:owner
					modifier = attempted_teach_governor_opinion
				}
			}
			else = { trigger_event = scheme_critical_moments.8044 }
		}
		stress_impact = {
			base = minor_stress_impact_gain
			diligent = minor_stress_impact_gain
			stubborn = minor_stress_impact_gain
		}
	}

	#Option A: Too bad
	option = {
		name = scheme_critical_moments.8043.a
		scope:scheme = { end_scheme = yes }
	}
}

# Target reaction
scheme_critical_moments.8044 = {
	type = character_event
	title = scheme_critical_moments.8044.t
	desc = {
		desc = scheme_critical_moments.8044.desc
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:scheme_successful }
				desc = scheme_critical_moments.8044.success
			}
			desc = scheme_critical_moments.8044.failure
		}
	}
	theme = administrative
	left_portrait = {
		character = scope:target
		animation = writing
	}
	right_portrait = {
		character = scope:owner
		animation = admiration
	}
	lower_right_portrait = scope:owner.top_liege
	override_background = { reference = study }

	immediate = {
		scope:owner = { save_scope_as = background_throne_room_scope }
		if = {
			limit = { exists = scope:scheme_successful }
			show_as_tooltip = { teach_governor_success_effect = yes }
		}
	}

	option = {
		name = {
			text = scheme_critical_moments.8044.a.success
			trigger = { exists = scope:scheme_successful }
		}
		name = {
			text = scheme_critical_moments.8044.a
			trigger = {
				NOT = { exists = scope:scheme_successful }
			}
		}
	}
}

# Accept response
scheme_critical_moments.8045 = {
	type = letter_event
	opening = scheme_critical_moments.8045.opening
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:recipient = { is_governor = yes }
				}
				desc = scheme_critical_moments.8045.desc
			}
			desc = scheme_critical_moments.8045.fallback
		}
		desc = scheme_critical_moments.8045.rump
	}
	sender = scope:recipient

	immediate = {
		show_as_tooltip = {
			stress_impact = {
				arrogant = minor_stress_impact_gain
				lazy = medium_stress_impact_gain
			}
			start_scheme = {
				target_character = scope:recipient
				type = teach_governor
			}
		}
	}

	option = {
		name = scheme_critical_moments.8045.a
		scope:recipient = {
			if = {
				limit = { is_ai = yes }
				add_opinion = {
					target = scope:actor
					modifier = mentoring_governor_opinion
				}
			}
		}
	}
}

# Reject response
scheme_critical_moments.8046 = {
	type = letter_event
	opening = scheme_critical_moments.8046.opening
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:recipient = { is_governor = yes }
				}
				desc = scheme_critical_moments.8046.desc
			}
			desc = scheme_critical_moments.8046.fallback
		}
		desc = scheme_critical_moments.8046.rump
	}
	sender = scope:recipient

	option = {
		name = scheme_critical_moments.8046.a
	}
}

##################################################
# Ingratiate Family
# Joe Parkin
# 8051 - 8054
##################################################

#	Results event for the Ingratiate Family scheme.
scheme_critical_moments.8051 = {
	hidden = yes

	immediate = {
		scope:scheme = {
			scheme_target_character = { save_scope_as = target }
			scheme_owner = {
				save_scope_as = owner
				#SUCCESS ROLL
				random = {
					chance = scope:scheme.scheme_success_chance
					save_scope_value_as = {
						name = scheme_successful
						value = yes
					}
					mandala_trickster_increment_successful_schemes_effect = yes
				}
				if = {
					limit = { exists = scope:scheme_successful }
					trigger_event = {
						id = scheme_critical_moments.8052
						days = 1
					}
				}
				else = {
					trigger_event = {
						id = scheme_critical_moments.8053
						days = 1
					}
				}
			}
		}
	}
}

scripted_effect ingratiate_family_success_effect = {
	scope:owner = {
		house = {
			add_house_modifier = {
				modifier = ep3_ingratiated_family_modifier
				years = 10
			}
		}
		progress_towards_friend_effect = {
			REASON = friend_ingratiate_family
			CHARACTER = scope:target
			OPINION = 0
		}
	}
	scope:target = {
		change_influence = medium_influence_gain
		if = {
			limit = { is_ai = yes }
			add_opinion = {
				target = scope:owner
				modifier = ingratiate_family_opinion
			}
		}
	}
}

#Success
scheme_critical_moments.8052 = {
	type = character_event
	title = scheme_critical_moments.8052.t
	desc = scheme_critical_moments.8052.desc
	theme = diplomacy
	left_portrait = {
		character = scope:owner
		animation = war_over_tie
	}
	right_portrait = {
		character = scope:target
		animation = admiration
	}

	immediate = {
		# Trigger the response event for the target
		scope:target = { trigger_event = scheme_critical_moments.8054 }
		ingratiate_family_success_effect = yes
	}

	option = {
		name = scheme_critical_moments.8052.a
		scope:scheme = { end_scheme = yes }
	}
}

#Failure
scheme_critical_moments.8053 = {
	type = character_event
	title = scheme_critical_moments.8053.t
	desc = scheme_critical_moments.8053.desc
	theme = diplomacy
	left_portrait = {
		character = scope:owner
		animation = disbelief
	}
	right_portrait = {
		character = scope:target
		animation = dismissal
	}

	immediate = {
		scope:target = {
			show_as_tooltip = {
				change_influence = medium_influence_gain
				if = {
					limit = { is_ai = yes }
					add_opinion = {
						target = scope:owner
						modifier = attempted_ingratiate_family_opinion
					}
				}
			}

			# Trigger the response event for the target
			trigger_event = scheme_critical_moments.8054
		}
		stress_impact = {
			base = minor_stress_impact_gain
			ambitious = minor_stress_impact_gain
			impatient = minor_stress_impact_gain
		}
	}

	#Option A: Too bad
	option = {
		name = scheme_critical_moments.8053.a
		scope:scheme = { end_scheme = yes }
	}
}

# Target reaction
scheme_critical_moments.8054 = {
	type = character_event
	title = scheme_critical_moments.8054.t
	desc = {
		desc = scheme_critical_moments.8054.desc
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:scheme_successful }
				desc = scheme_critical_moments.8054.success
			}
			desc = scheme_critical_moments.8054.failure
		}
	}
	theme = diplomacy
	left_portrait = {
		character = scope:target
		triggered_animation = {
			trigger = { exists = scope:scheme_successful }
			animation = happiness
		}
		animation = dismissal
	}
	right_portrait = {
		character = scope:owner
		animation = war_over_tie
	}

	immediate = {
		if = {
			limit = { is_ai = yes }
			hidden_effect = {
				remove_opinion = {
					modifier = ingratiating_family_opinion
					target = scope:owner
				}
			}
		}
		if = {
			limit = { exists = scope:scheme_successful }
			show_as_tooltip = { ingratiate_family_success_effect = yes }
			if = {
				limit = { is_ai = yes }
				add_opinion = {
					target = scope:owner
					modifier = ingratiate_family_opinion
				}
			}
		}
		else = {
			change_influence = medium_influence_gain
			if = {
				limit = { is_ai = yes }
				add_opinion = {
					target = scope:owner
					modifier = attempted_ingratiate_family_opinion
				}
			}
		}
	}

	option = {
		name = {
			trigger = { exists = scope:scheme_successful }
			text = scheme_critical_moments.8054.a.success
		}
		name = {
			trigger = {
				NOT = { exists = scope:scheme_successful }
			}
			text = scheme_critical_moments.8054.a
		}
	}
}

##################################################
# Prepare Greek Fire Dromons
# Jason Cantalini
# 8060 - 8062
##################################################

#	Results event for the Prepare Greek Fire Dromons scheme.
scheme_critical_moments.8060 = {
	hidden = yes

	immediate = {
		scope:scheme = {
			scheme_owner = {
				save_scope_as = owner
				#SUCCESS ROLL
				random = {
					chance = scope:scheme.scheme_success_chance
					save_scope_value_as = {
						name = scheme_successful
						value = yes
					}
					mandala_trickster_increment_successful_schemes_effect = yes
				}
				if = {
					limit = { exists = scope:scheme_successful }
					trigger_event = {
						id = scheme_critical_moments.8061
						days = 1
					}
				}
				else = {
					trigger_event = {
						id = scheme_critical_moments.8062
						days = 1
					}
				}
			}
		}
	}
}

scripted_effect prepare_fire_dromons_success_effect = {
	scope:byzantion = {
		add_county_modifier = {
			modifier = defensive_fire_dromons_modifier
			desc = defensive_fire_dromons_modifier_custom_desc
			years = 30
		}
	}
}

# Success
scheme_critical_moments.8061 = {
	type = character_event
	title = scheme_critical_moments.8061.t
	desc = scheme_critical_moments.8061.desc
	theme = byzantine
	override_background = {
		reference = docks
	}
	widget = {
		gui = "event_window_widget_vfx_heavy_smoke"
		container = "foreground_shader_vfx_container"
	}
	left_portrait = {
		character = root
		animation = eccentric
	}

	immediate = {
		title:c_byzantion = {
			save_scope_as = byzantion
		}
		prepare_fire_dromons_success_effect = yes
	}

	option = {
		name = scheme_critical_moments.8061.a
		scope:scheme = { end_scheme = yes }
	}
}

# Failure
scheme_critical_moments.8062 = {
	type = character_event
	title = scheme_critical_moments.8062.t
	desc = scheme_critical_moments.8062.desc
	theme = administrative
	override_background = {
		reference = docks
	}
	widget = {
		gui = "event_window_widget_vfx_heavy_smoke"
		container = "foreground_shader_vfx_container"
	}
	left_portrait = {
		character = root
		animation = fear
		camera = camera_event_left_forward
	}

	immediate = {
		stress_impact = {
			base = minor_stress_impact_gain
			ambitious = minor_stress_impact_gain
			paranoid = minor_stress_impact_gain
		}
		title:c_byzantion = {
			save_scope_as = byzantion
		}
	}

	#Option A: Too bad
	option = {
		name = scheme_critical_moments.8062.a
		scope:scheme = { end_scheme = yes }
	}
}

##Scheme for Censor/Justice to help find secrets
#Results event.
scheme_critical_moments.8065 = {
	hidden = yes

	immediate = {
		if = {
			limit = {
				scope:scheme.var:secrets_found >= 1
			}
			save_scope_value_as = {
				name = scheme_successful
				value = yes
			}
			scope:owner = {
				trigger_event = scheme_critical_moments.8066
			}
		}
		else = {
			scope:owner = {
				trigger_event = scheme_critical_moments.8067
			}
		}
	}
}

#Success event.
scheme_critical_moments.8066 = {
	type = character_event
	window = scheme_successful_event
	title = scheme_critical_moments.8066.t
	desc = scheme_critical_moments.8066.desc
	theme = intrigue
	left_portrait = {
		character = scope:owner
		animation = scheme
	}
	right_portrait = {
		character = scope:hegemon
		animation = throne_room_ruler_hu
	}
	lower_right_portrait = {
		character = scope:target
	}

	immediate = {
		scope:owner.top_liege = {
			save_scope_as = hegemon
		}
		scope:scheme.var:secrets_found = {
			save_scope_as = secrets_found_value
		}
	}

	option = {
		name = scheme_critical_moments.8066.a
		scope:scheme = { end_scheme = yes }
		add_gold = major_gold_value
	}
	option = {
		name = scheme_critical_moments.8066.b
		trigger = {
			has_treasury = yes
		}
		scope:scheme = { end_scheme = yes }
		add_treasury = major_treasury_value
	}
}

#Failure event.
scheme_critical_moments.8067 = {
	type = character_event
	window = scheme_failed_event
	title = scheme_critical_moments.8067.t
	desc = scheme_critical_moments.8067.desc
	theme = intrigue
	left_portrait = {
		character = scope:owner
		animation = throne_room_chancellor
	}
	right_portrait = {
		character = scope:hegemon
		animation = disappointed
	}
	lower_right_portrait = {
		character = scope:target
	}

	immediate = {
		scope:owner.top_liege = {
			save_scope_as = hegemon
		}
		scope:scheme.var:secrets_found = {
			save_scope_as = secrets_found_value
		}
	}

	option = {
		name = scheme_critical_moments.8067.a
		scope:scheme = { end_scheme = yes }
		change_influence = major_influence_loss
	}
}

#Pick a minor secret to reveal
scheme_critical_moments.8068 = {
	hidden = yes

	trigger = {
		scope:target_character = {
			spymaster_task_find_secrets_court_has_minor_secrets_trigger = yes
		}
	}

	immediate = {
		scope:councillor = {
			save_scope_as = active_councillor
		}
		scope:scheme = {
			change_variable = {
				name = secrets_found
				add = 1
			}
		}
		scope:target_character = {
			#Find any secrets from the court owner
			if = {
				limit = {
					any_secret = {
						save_temporary_scope_as = illegal_or_shunned_secret
						spymaster_task_find_secrets_suitable_minor_secret_trigger = yes
					}
				}
				every_secret = {
					limit = {
						spymaster_task_find_secrets_suitable_minor_secret_trigger = yes
					}
					add_to_temporary_list = suitable_secrets
				}
			}
			#Find any secrets from courtiers or guests
			every_courtier_or_guest = {
				limit = {
					any_secret = {
						spymaster_task_find_secrets_suitable_minor_secret_trigger = yes
					}
				}
				every_secret = {
					limit = {
						spymaster_task_find_secrets_suitable_minor_secret_trigger = yes
						NOT = { is_in_list = suitable_secrets }
					}
					add_to_temporary_list = suitable_secrets
				}
			}
			#Find any secrets from direct vassals
			every_vassal = {
				limit = {
					any_secret = {
						spymaster_task_find_secrets_suitable_minor_secret_trigger = yes
					}
				}
				every_secret = {
					limit = {
						spymaster_task_find_secrets_suitable_minor_secret_trigger = yes
						NOT = { is_in_list = suitable_secrets }
					}
					add_to_temporary_list = suitable_secrets
				}
			}
		}

		#Pick a Secret to discover
		random_in_list = {
			list = suitable_secrets
			weight = {
				base = 1
				modifier = {
					add = 2
					secret_owner = {
						save_temporary_scope_as = secret_holder
					}
					spymaster_find_secrets_secret_holder_is_interesting_to_me_trigger = yes
				}
				modifier = {
					add = 1
					spymaster_find_secrets_secret_target_is_interesting_to_me_trigger = yes
				}
				# Less likely to discovery crypto-religionist secret if owner has Taqiya tenet
				modifier = {
					add = -3
					secret_type = secret_crypto_religionist
					secret_owner = {
						secret_faith ?= { has_doctrine_parameter = sanctioned_false_conversion }
					}
				}
				# Less likely to pick crypto-religionist secrets (b/c narratively they are hard to discover)
				modifier = {
					factor = 0.25
					secret_type = secret_crypto_religionist
				}
			}
			save_scope_as = secret_to_reveal
			secret_owner = {
				save_scope_as = secret_holder
			}
		}

		#Fire events
		# If the secret is a crypto-religionist secret, then there is a chance that the spymaster does not discover anything after all
		if = {
			limit = {
				scope:secret_to_reveal = {
					secret_type = secret_crypto_religionist
				}
			}
			random = {
				chance = {
					value = 50
					# Even more likely to not discover this secret if the target practices Taqiya
					if = {
						limit = { secret_faith ?= { has_doctrine_parameter = sanctioned_false_conversion } }
						add = 25
					}
				}
				trigger_event = spymaster_task.0399
			}
		}
		scope:councillor_liege = {
			if = { #It's someone I care about
				limit = {
					OR = {
						spymaster_find_secrets_secret_holder_is_interesting_to_me_trigger = yes
						scope:secret_to_reveal = {
							spymaster_find_secrets_secret_target_is_interesting_to_me_trigger = yes
						}
					}
				}
				trigger_event = {
					on_action = task_find_secrets_reveal_selection
				}
			}
			else = { #For everyone else, send a feed message
				send_interface_message = {
					type = msg_spymaster_task_good
					title = spymaster_task.0311.notification
					desc = {
						triggered_desc = {
							trigger = {
								scope:active_councillor = { intrigue <= average_skill_level }
							}
							desc = task_intrigue_good_unskilled_notification_tooltip
						}
						triggered_desc = {
							trigger = {
								scope:active_councillor = { intrigue > average_skill_level }
							}
							desc = task_intrigue_good_skilled_notification_tooltip
						}
					}

					left_icon = scope:secret_holder
					right_icon = scope:councillor

					scope:secret_to_reveal = {
						reveal_to = scope:councillor_liege
					}
				}
			}
		}
		scope:councillor = {
			if = { #Check that the Spymaster doesn't already know the secret
				limit = {
					scope:secret_to_reveal = {
						NOT = { is_known_by = prev }
					}
				}
				if = { #It's the owner of the court or someone else I care about
					limit = { spymaster_find_secrets_secret_holder_is_interesting_to_me_trigger = yes }
					trigger_event = {
						on_action = task_find_secrets_reveal_selection
					}
				}
				else = { #For everyone else, send a feed message
					send_interface_message = {
						type = msg_spymaster_task_good
						title = spymaster_task.0311.notification

						left_icon = scope:secret_holder

						desc = blank_line

						scope:secret_to_reveal = {
							reveal_to = scope:councillor
						}
					}
				}
			}
		}
	}
}

#get a major secret
scheme_critical_moments.8069 = {
	hidden = yes

	trigger = {
	}

	immediate = {
		scope:councillor = {
			save_scope_as = active_councillor
		}
		scope:scheme = {
			change_variable = {
				name = secrets_found
				add = 1
			}
		}
		scope:target_character = {
			#Find any secrets from the court owner
			if = {
				limit = {
					any_secret = {
						spymaster_task_find_secrets_suitable_major_secret_trigger = yes
					}
				}
				every_secret = {
					limit = {
						spymaster_task_find_secrets_suitable_major_secret_trigger = yes
					}
					add_to_temporary_list = suitable_secrets
				}
			}
			#Find any secrets from courtiers
			every_courtier_or_guest = {
				limit = {
					any_secret = {
						spymaster_task_find_secrets_suitable_major_secret_trigger = yes
					}
				}
				every_secret = {
					limit = {
						spymaster_task_find_secrets_suitable_major_secret_trigger = yes
						NOT = { is_in_list = suitable_secrets }
					}
					add_to_temporary_list = suitable_secrets
				}
			}
			#Find any secrets from direct vassals
			every_vassal = {
				limit = {
					any_secret = {
						spymaster_task_find_secrets_suitable_major_secret_trigger = yes
					}
				}
				every_secret = {
					limit = {
						spymaster_task_find_secrets_suitable_major_secret_trigger = yes
						NOT = { is_in_list = suitable_secrets }
					}
					add_to_temporary_list = suitable_secrets
				}
			}
		}

		#Pick a Secret to discover
		random_in_list = {
			list = suitable_secrets
			weight = {
				base = 1
				modifier = {
					add = 2
					secret_owner = {
						save_temporary_scope_as = secret_holder
					}
					spymaster_find_secrets_secret_holder_is_interesting_to_me_trigger = yes
				}
				modifier = {
					add = 1
					spymaster_find_secrets_secret_target_is_interesting_to_me_trigger = yes
				}
			}
			save_scope_as = secret_to_reveal
			secret_owner = {
				save_scope_as = secret_holder
			}
		}

		#Fire events
		scope:councillor_liege = {
			if = { #It's someone I care about
				limit = {
					OR = {
						spymaster_find_secrets_secret_holder_is_interesting_to_me_trigger = yes
						scope:secret_to_reveal = {
							spymaster_find_secrets_secret_target_is_interesting_to_me_trigger = yes
						}
					}
				}
				trigger_event = {
					on_action = task_find_secrets_reveal_selection
				}
			}
			else = { #For everyone else, send a feed message
				send_interface_message = {
					type = msg_spymaster_task_good
					title = spymaster_task.0311.notification
					desc = {
						triggered_desc = {
							trigger = {
								scope:active_councillor = { intrigue <= average_skill_level }
							}
							desc = task_intrigue_good_unskilled_notification_tooltip
						}
						triggered_desc = {
							trigger = {
								scope:active_councillor = { intrigue > average_skill_level }
							}
							desc = task_intrigue_good_skilled_notification_tooltip
						}
					}

					left_icon = scope:secret_holder
					right_icon = scope:councillor

					scope:secret_to_reveal = {
						reveal_to = scope:councillor_liege
					}
				}
			}
		}
		scope:councillor = {
			if = { #Check that the Spymaster doesn't already know the secret
				limit = {
					scope:secret_to_reveal = {
						NOT = { is_known_by = prev }
					}
				}
				if = { #It's the owner of the court or someone else I care about
					limit = {
						OR = {
							scope:secret_holder = {
								is_ruler = yes
							}
							spymaster_find_secrets_secret_holder_is_interesting_to_me_trigger = yes
							scope:secret_to_reveal = {
								spymaster_find_secrets_secret_target_is_interesting_to_me_trigger = yes
							}
						}
					}
					trigger_event = {
						on_action = task_find_secrets_reveal_selection
					}
				}
				else = { #For everyone else, send a feed message
					scope:councillor = {
						send_interface_message = {
							type = msg_spymaster_task_good
							title = spymaster_task.0311.notification

							left_icon = scope:secret_holder

							desc = blank_line

							scope:secret_to_reveal = {
								reveal_to = scope:councillor
							}
						}
					}
				}
			}
		}
	}
}

#get a hook
scheme_critical_moments.8070 = {
	type = character_event
	title = scheme_critical_moments.8070.t
	theme = fabricate_hook_scheme
	desc = {
		desc = spymaster_task.0381.desc_other_court
		desc = spymaster_task.0381.desc
	}
	right_portrait = {
		character = root
		animation = scheme
	}
	left_portrait = {
		character = scope:character_to_hook
		animation = boredom
	}

	trigger = {
		scope:target_character = {
			OR = {
				any_courtier_or_guest = {
					spymaster_task_courtier_valid_for_hook_fabrication_trigger = yes
				}
				any_vassal = {
					spymaster_task_courtier_valid_for_hook_fabrication_trigger = yes
				}
			}
		}
	}

	immediate = {
		scope:target_character = {
			random_courtier_or_guest = {
				limit = {
					spymaster_task_courtier_valid_for_hook_fabrication_trigger = yes
				}
				weight = {
					base = 1
					modifier = { # Prioritise actual Courtiers
						add = 3
						is_courtier_of = scope:target_character
					}
				}
				save_scope_as = character_to_hook
			}
			random_vassal = {
				limit = {
					spymaster_task_courtier_valid_for_hook_fabrication_trigger = yes
				}
				weight = {
					base = 1
					modifier = { # Prioritise powerful Vassals
						add = 3
						is_powerful_vassal_of = scope:target_character
					}
				}
				save_scope_as = character_to_hook
			}
		}
	}

	#add the hook to yourself
	option = {
		name = scheme_critical_moments.8070.a
		add_hook = {
			target = scope:character_to_hook
			type = fabrication_hook
		}
		remove_short_term_gold = medium_gold_value
		scope:scheme = {
			change_variable = {
				name = secrets_found
				add = 1
			}
		}
		if = {
			limit = {
				government_has_flag = government_has_influence
			}
			change_influence = {
				value = minor_influence_gain
				multiply = scope:character_to_hook.highest_held_title_tier
			}
		}
		if = {
			limit = {
				scope:character_to_hook = {
					is_ruler = yes
				}
			}
			situation:dynastic_cycle = {
				if = {
					limit = {
						situation_top_has_catalyst = catalyst_find_secrets_bad_outcome
					}
					trigger_situation_catalyst = {
						catalyst = catalyst_find_secrets_bad_outcome
						character = root
					}
				}
			}
		}
		stress_impact = {
			honest = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				has_dread_level_towards = {
					target = scope:councillor_liege
					level = 1
				}
				add = -50
			}
			ai_value_modifier = {
				ai_greed = -1
				ai_honor = -1
			}
			modifier = {
				factor = 0
				OR = {
					has_trait = loyal
					has_trait = honest
					has_dread_level_towards = {
						target = scope:councillor_liege
						level = 2
					}
				}
			}
			modifier = {
				factor = 0
				short_term_gold <= medium_gold_value
			}
		}
	}

	#add the hook to the employer
	option = {
		name = laamp_extra_contract_schemes.0022.b
		scope:councillor_liege = {
			add_hook = {
				target = scope:character_to_hook
				type = fabrication_hook
			}
		}
		if = {
			limit = {
				has_treasury = yes
				has_title = title:e_minister_censor
			}
			remove_treasury = minor_gold_value	
		}
		else = {
			remove_short_term_gold = minor_gold_value
		}
		add_merit_if_relevant_effect = {
			MERIT = minor_merit_value
		}
		scope:scheme = {
			change_variable = {
				name = secrets_found
				add = 1
			}
		}
		if = {
			limit = {
				scope:character_to_hook = {
					is_ruler = yes
				}
			}
			situation:dynastic_cycle = {
				if = {
					limit = {
						situation_top_has_catalyst = catalyst_find_secrets_good_outcome
					}
					trigger_situation_catalyst = {
						catalyst = catalyst_find_secrets_good_outcome
						character = root
					}
				}
			}
		}
		stress_impact = {
			honest = medium_stress_impact_gain
		}
		ai_chance = {
			base = 20
			modifier = {
				is_in_same_movement_as = { TARGET = scope:councillor_liege }
				add = 20
			}
			ai_value_modifier = {
				ai_honor = 1
			}
		}
	}

	#don't take the hook
	option = {
		name = laamp_extra_contract_schemes.0022.c
		flavor = spymaster_task.0381.b.flavor
		if = {
			limit = {
				scope:scheme = {
					scheme_agent_charges < opportunity_cap_value
				}
			}
			scope:scheme = {
				change_opportunities = 1
			}
		}
		scope:character_to_hook = {
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 30
			}
		}
		ai_chance = {
			base = 5
			modifier = {
				is_in_pro_hegemon_or_hegemon_movement = no
				is_in_same_movement_as = { TARGET = scope:character_to_hook }
				add = 200
			}
			ai_value_modifier = {
				ai_sociability = 0.5
				ai_honor = -1
			}
			modifier = {
				is_close_or_extended_family_of = scope:character_to_hook
				add = 200
			}
			modifier = {
				has_any_good_relationship_with_character_trigger = { CHARACTER = scope:character_to_hook }
				add = 200
			}
		}
	}
}

# Find Criminal
scheme_critical_moments.8071 = {
	type = character_event
	title = scheme_critical_moments.8071.t
	theme = fabricate_hook_scheme
	desc = scheme_critical_moments.8071.desc
	left_portrait = {
		character = root
		animation = scheme
	}
	right_portrait = {
		character = scope:criminal
		animation = eyeroll
	}

	trigger = {
	}

	immediate = {
		scope:target_character = {
			random_vassal_or_below = {
				limit = {
					is_imprisoned = no
					liege = {
						has_imprisonment_reason = prev
					}
				}
				weight = {
					base = 1
					modifier = { # Prioritize powerful Vassals
						add = 3
						is_powerful_vassal_of = scope:target_character
					}
					modifier = { # Prioritize direct Vassals
						add = 1
						is_vassal_of = scope:target_character
					}
				}
				save_scope_as = criminal
				save_scope_as = character_to_hook # for reusing localization
			}
		}
	}

	#Imprison them yourself
	option = {
		name = scheme_critical_moments.8071.a
		trigger = {
			is_character_interaction_valid = {
				recipient = scope:criminal
				interaction = imprison_interaction
			}
		}
		remove_short_term_treasury = minor_treasury_value
		if = {
			limit = {
				government_has_flag = government_has_influence
			}
			change_influence = {
				value = minor_influence_gain
				multiply = scope:criminal.highest_held_title_tier
			}
		}
		show_as_tooltip = {
			imprison = {
				target = scope:criminal
				type = house_arrest
			}
		}
		hidden_effect = {
			rightfully_imprison_character_effect = {
				TARGET = scope:criminal
				IMPRISONER = root
			}
		}
		scope:criminal.liege = {
			consume_imprisonment_reasons = scope:criminal
		}
		scope:scheme = {
			change_variable = {
				name = secrets_found
				add = 1
			}
		}
		stress_impact = {
			honest = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				has_dread_level_towards = {
					target = scope:councillor_liege
					level = 1
				}
				add = -50
			}
			modifier = {
				factor = 0
				OR = {
					has_trait = loyal
					has_trait = honest
					has_dread_level_towards = {
						target = scope:councillor_liege
						level = 2
					}
				}
			}
			modifier = {
				factor = 0
				short_term_gold <= medium_gold_value
			}
		}
	}

	#Let the proper Liege imprison them
	option = {
		name = scheme_critical_moments.8071.b
		trigger = {
			scope:criminal.liege = {
				is_character_interaction_valid = {
					recipient = scope:criminal
					interaction = imprison_interaction
				}
			}
		}
		show_as_tooltip = {
			scope:criminal.liege = {
				imprison = {
					target = scope:criminal
					type = house_arrest
				}
			}
		}
		hidden_effect = {
			rightfully_imprison_character_effect = {
				TARGET = scope:criminal
				IMPRISONER = scope:criminal.liege
			}
		}
		scope:criminal.liege = {
			consume_imprisonment_reasons = scope:criminal
		}
		add_merit_if_relevant_effect = {
			MERIT = minor_merit_value
		}
		scope:scheme = {
			change_variable = {
				name = secrets_found
				add = 1
			}
		}
		stress_impact = {
			honest = medium_stress_impact_gain
		}
		ai_chance = {
			base = 20
			modifier = {
				is_in_same_movement_as = { TARGET = scope:councillor_liege }
				add = 20
			}
		}
	}

	# Pardon them
	option = {
		name = scheme_critical_moments.8071.c
		flavor = spymaster_task.0381.b.flavor
		trigger = {
			is_character_interaction_valid = {
				recipient = scope:criminal
				interaction = pardon_interaction
			}
		}
		save_scope_as = actor # for loc
		scope:criminal = {
			save_scope_as = recipient # for loc
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = pardon_interaction_toast_title
				desc = pardon_interaction_toast_minister
				right_icon = scope:actor
				if = {
					limit = {
						OR = {
							scope:recipient.liege = {
								has_extra_criminal_reason_against_trigger = {
									CRIMINAL = scope:recipient
								}
							}
							is_close_or_extended_family_of = scope:actor
						}
					}
					scope:actor = {
						change_strife_opinion = massive_strife_gain
					}
				}
				scope:actor = {
					if = {
						limit = {
							can_add_hook = {
								target = scope:recipient
								type = loyalty_hook
							}
						}
						add_hook = {
							type = loyalty_hook
							target = scope:recipient
						}
					}
				}
				consume_all_criminal_reasons_effect = {
					LIEGE = scope:recipient.liege
					CRIMINAL = scope:recipient
				}
				situation:dynastic_cycle = {
					if = {
						limit = {
							situation_top_has_catalyst = catalyst_minister_pardoned_known_criminal
						}
						trigger_situation_catalyst = {
							catalyst = catalyst_minister_pardoned_known_criminal
							character = root
						}
					}
				}
            }
        }
        hidden_effect = {
			scope:recipient.liege = {
				send_interface_toast = {
					type = event_toast_effect_neutral
					title = pardon_interaction_toast_title
					desc = pardon_interaction_toast_minister_liege
					right_icon = scope:actor
					left_icon = scope:recipient
					show_as_tooltip = {
						if = {
							limit = {
								OR = {
									has_extra_criminal_reason_against_trigger = {
										CRIMINAL = scope:recipient
									}
									scope:recipient = {
										is_close_or_extended_family_of = scope:actor
									}
								}
							}
							scope:actor = {
								change_strife_opinion = massive_strife_gain
							}
						}
						consume_all_criminal_reasons_effect = {
							LIEGE = scope:recipient.liege
							CRIMINAL = scope:recipient
						}
						situation:dynastic_cycle = {
							if = {
								limit = {
									situation_top_has_catalyst = catalyst_minister_pardoned_known_criminal
								}
								trigger_situation_catalyst = {
									catalyst = catalyst_minister_pardoned_known_criminal
									character = root
								}
							}
						}
	            	}
	            }
	        }
        }
		ai_chance = {
			base = 5
			modifier = {
				is_in_same_movement_as = { TARGET = scope:character_to_hook }
				add = 200
			}
			modifier = {
				is_close_or_extended_family_of = scope:character_to_hook
				add = 200
			}
			modifier = {
				has_any_good_relationship_with_character_trigger = { CHARACTER = scope:character_to_hook }
				add = 200
			}
		}
	}

	#don't do anything
	option = {
		name = scheme_critical_moments.8071.d
		flavor = spymaster_task.0381.b.flavor
		if = {
			limit = {
				scope:scheme = {
					scheme_agent_charges < opportunity_cap_value
				}
			}
			scope:scheme = {
				change_opportunities = 1
			}
		}
		if = {
			limit = {
				can_add_hook = {
					target = scope:criminal
					type = indebted_hook
				}
			}
			add_hook = {
				type = indebted_hook
				target = scope:criminal
			}
		}
		scope:criminal = {
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 30
			}
		}
		ai_chance = {
			base = 5
		}
	}
}
