﻿namespace = intrigue_scheming

##################################################

#Intrigue Scheming events

	#1001		- Go behind your council-members' backs for the sake of a county
	#1011		- Invent code
	#1201		- Hired spies construct a report of your castle's weaknesses
	#1401		- Meet a merchant from a far away land
	#1601		- Potential to turn a secret into a hook - or other things
	
	# Messages in Blood
	#1701		- A message from an agent
	#1702		- A payment
	#1703  	 	- A confirmation
	#1704 		- A contract
	#2001		- Gain intrigue mentor
	#2101		- Sneaky person seeks you out for retinue position
	#4021		- Interrogation
	#4040		- Passing Suspicion
	#4050-4054 - Information Brokering

##################################################

namespace = intrigue_scheming_special

##################################################

#Intrigue Scheming Rare events

	#1001-1099 - Convince Courtier to Share Spy-Secrets
	#1301-1399 - Root out secrets at your court
	#1601-1699	- Blackmail and Trickery

##################################################

#Play Robin Hood - Go behind your council-members' backs for the sake of a county
	#by Linnéa Thimrén
intrigue_scheming.1001 = {
	type = character_event
	title = intrigue_scheming.1001.t
	desc = intrigue_scheming.1001.desc
	
	theme = intrigue_skulduggery_focus
	left_portrait = {
		character = scope:councillor
		animation = personality_cynical
	}

	trigger = {
		NOT = { has_character_flag = had_event_intrigue_scheming_1001 }
		any_councillor = {
			NOT = { is_consort_of = root }
			ai_compassion <= low_negative_compassion
		}
		any_directly_owned_province = {
			is_county_capital = no
			exists = county
		}
	}

	immediate = {
		add_character_flag = {
			flag = had_event_intrigue_scheming_1001
			years = 5
		}
		random_directly_owned_province = {
			limit = { is_county_capital = no }
			county = { save_scope_as = county }
		}
		random_councillor = {
			limit = {
				NOT = { is_consort_of = root }
				ai_compassion <= low_negative_compassion
			}
			save_scope_as = councillor
		}
	}

	option = {
		name = intrigue_scheming.1001.a
		stress_impact = {
			callous = minor_stress_impact_gain
			greedy = minor_stress_impact_gain
			cynical = minor_stress_impact_gain
		}
		add_intrigue_lifestyle_xp = minor_lifestyle_xp
		scope:county = {
			add_county_modifier = {
				modifier = encouraged_improvement_modifier
				days = 365
			}
		}
		scope:councillor = {
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = -20
			}
		}
		ai_chance = {
			base = 70
			modifier = {
				add = 20
				OR = {
					has_trait = compassionate
					has_trait = generous
					has_trait = just
				}
			}
		}
	}

	option = {
		name = intrigue_scheming.1001.b
		add_prestige = medium_prestige_gain
		scope:county = {
			add_county_modifier = {
				modifier = governance_abandoned_villages_modifier
				days = 365
			}
		}
		add_character_modifier = {
			modifier = increased_levies_modifier
			days = 3650
		}
		stress_impact = {
			compassionate = minor_stress_impact_gain
			generous = minor_stress_impact_gain
			just = minor_stress_impact_gain
		}
		ai_chance = {
			base = 30
			modifier = {
				add = 60
				OR = {
					has_trait = greedy
					has_trait = callous
				}
			}
			modifier = {
				add = 20
				OR = {
					has_trait = cynical
					has_trait = sadistic
				}
			}
		}
	}
}

##################################################
#Invent code for messages. Start, you contemplate the need for better encryption
	#by Linnéa Thimrén
##################################################

intrigue_scheming.1011 = {
	type = character_event
	title = intrigue_scheming.1011.t
	desc = intrigue_scheming.1011.desc
	
	theme = intrigue_skulduggery_focus
	left_portrait = {
		character = root
		animation = personality_rational
	}
	
	trigger = {
		NOT = { has_character_flag = intrigue_scheming_1011 }
		any_targeting_scheme = {
			OR = {
				scheme_type = murder
				scheme_type = abduct
			}
		}
		any_intrigue_councillor = {
			is_alive = yes
		}
	}

	weight_multiplier = {
		base = 1
		upweight_for_focus_modifier = { FOCUS = intrigue_skulduggery_focus }
	}

	immediate = {
		random_intrigue_councillor = { #save spymaster
			save_scope_as = council_member
		}
		add_character_flag = {
			flag = intrigue_scheming_1011
			years = 15
		}
	}

	option = {
		name = intrigue_scheming.1011.a
		remove_short_term_gold = medium_gold_value
		flavor = intrigue_scheming.1011.a.flavor
		trigger_event = {
			id = intrigue_scheming.1012
			days = { 20 60 }
		}
		ai_chance = {
			base = 90
			modifier = {
				add = -90
				short_term_gold < medium_gold_value_check
			}
		}
	}

	option = {
		name = intrigue_scheming.1011.b
		add_character_modifier = {#
			modifier = more_vigilant_recistance_modifier
			days = 1095
		}
		ai_chance = {
			base = 10
			modifier = {
				add = 40
				has_trait = greedy
			}
		}
	}
}

intrigue_scheming.1012 = {
	type = character_event
	title = intrigue_scheming.1011.t
	desc = {
		desc = intrigue_scheming.1012.desc
		random_valid = {
			desc = intrigue_scheming.1012.desc_archimedes
			desc = intrigue_scheming.1012.desc_al_kindi
		}
		desc = intrigue_scheming.1012.desc_ending
	}
	
	theme = intrigue_skulduggery_focus
	left_portrait = {
		character = scope:cryptographer
		animation = personality_dishonorable
	}

	immediate = {
		create_character = {
			employer = root
			gender_female_chance = {
				if = {
					limit = { root.faith = { has_doctrine = doctrine_gender_female_dominated } }
					add = 80
				}
				else_if = {
					limit = { root.faith = { has_doctrine = doctrine_gender_male_dominated } }
					add = 20
				}
				else = {
					add = 50
				}
			}
			age = { 35 50 }
			learning = { 8 12 }
			intrigue = { 6 8 }
			trait = education_intrigue_3
			faith = root.faith
			culture = root.culture
			save_scope_as = cryptographer
		}
	}

	#Involve yourself in the project.
	#Let the cryptographer do everything.

	option = {
		name = intrigue_scheming.1012.a
		duel = {
			skill = intrigue
			value = decent_skill_rating
			10 = {
				desc = intrigue_scheming.1012.a.duel_success
					compare_modifier = {
						value = scope:duel_value
						multiplier = 1
					}
				show_as_tooltip = { add_intrigue_lifestyle_xp = medium_lifestyle_xp }
				trigger_event = {
					id = intrigue_scheming.1013
					days = { 10 20 }
				}
			}
			5 = {
				desc = intrigue_scheming.1012.a.duel_failure
				show_as_tooltip = {
					add_character_modifier = {
						modifier = invented_code_resistance_modifier
						days = 1095
					}
				}
				trigger_event = {
					id = intrigue_scheming.1014
					days = { 10 20 }
				}
			}
		}
		stress_impact = {
			base = medium_stress_gain
			lazy = medium_stress_impact_gain
			diligent = medium_stress_impact_loss
		}
		ai_chance = {
			base = 90
			modifier = {
				add = -90
				short_term_gold < medium_gold_value_check
			}
			modifier = {
				add = 20
				OR = {
					has_trait = stubborn
					has_trait = diligent
				}
			}
		}
	}

	option = {
		name = intrigue_scheming.1012.b
		add_intrigue_lifestyle_xp = miniscule_lifestyle_xp
		add_character_modifier = {
			modifier = invented_code_slight_resistance_modifier
			days = 1095
		}
		stress_impact = {
			base = medium_stress_loss
			diligent = medium_stress_impact_gain
			ambitious = medium_stress_impact_gain
			lazy = major_stress_impact_loss
		}
		ai_chance = {
			base = 10
			modifier = {
				add = 100
				short_term_gold < medium_gold_value_check
			}
			modifier = {
				add = 40
				has_trait = greedy
			}
			modifier = {
				add = 20
				has_trait = lazy
			}
		}
	}
}

intrigue_scheming.1013 = {
	type = character_event
	title = intrigue_scheming.1011.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:cryptographer = {
						is_alive = yes
					}
				}
				desc = intrigue_scheming.1013.desc_alive
			}
			triggered_desc = {
				trigger = {
					scope:cryptographer = {
						is_alive = no
					}
				}
				desc = intrigue_scheming.1013.desc_dead
			}
		}
		random_valid = {
			triggered_desc = {
				trigger = {
					has_character_flag = transposition
				}
				desc = intrigue_scheming.1013.desc_transposition
			}
			triggered_desc = {
				trigger = {
					has_character_flag = substitution
				}
				desc = intrigue_scheming.1013.desc_substitution
			}
			triggered_desc = {
				trigger = {
					has_character_flag = cipher
				}
				desc = intrigue_scheming.1013.desc_cipher
			}
		}
	}
	
	theme = intrigue_skulduggery_focus
	left_portrait = {
		character = root
		animation = personality_dishonorable
	}
	right_portrait = {
		character = scope:cryptographer
		animation = scheme
	}

	immediate = {
		hidden_effect = {
			random_list = {
				40 = {
					modifier = {
						add = 20
						OR = {
							has_trait = intellect_bad_1
							has_trait = intellect_bad_2
							has_trait = intellect_bad_3
						}
					}
					modifier = {
						add = 10
						has_trait_rank = {
							trait = education_intrigue
							rank <= 1
						}
					}
					modifier = {
						add = 5
						has_trait_rank = {
							trait = education_intrigue
							rank <= 2
						}
					}
					add_character_flag = transposition
					set_variable = {
						name = intrigue_exp_gain_value
						value = minor_lifestyle_xp
					}
				}
				30 = {
					compare_modifier = {
						target = root
						value = learning
						step = 2
						multiplier = 0.4
					}
					compare_modifier = {
						target = root
						value = intrigue
						step = 2
						multiplier = 0.4
					}
					modifier = {
						add = 10
						has_trait_rank = {
							trait = education_intrigue
							rank >= 3
						}
					}
					add_character_flag = substitution
					set_variable = {
						name = intrigue_exp_gain_value
						value = medium_lifestyle_xp
					}
				}
				30 = {
					compare_modifier = {
						target = root
						value = learning
						step = 2
						multiplier = 0.4
					}
					compare_modifier = {
						target = root
						value = intrigue
						step = 2
						multiplier = 0.4
					}
					modifier = {
						add = 10
						has_trait_rank = {
							trait = education_intrigue
							rank >= 3
						}
					}
					add_character_flag = cipher
					set_variable = {
						name = intrigue_exp_gain_value
						value = major_lifestyle_xp
					}
				}
			}
		}
	}

	option = {
		name = intrigue_scheming.1013.a
		if = {
			limit = {
				has_character_flag = transposition
			}
			custom_tooltip = intrigue_scheming.1013.a.tt
			hidden_effect = { add_intrigue_lifestyle_xp = minor_lifestyle_xp }
		}
		else_if = {
			limit = {
				has_character_flag = substitution
			}
			custom_tooltip = intrigue_scheming.1013.b.tt
			hidden_effect = { add_intrigue_lifestyle_xp = medium_lifestyle_xp }
		}
		else_if = {
			limit = {
				has_character_flag = cipher
			}
			custom_tooltip = intrigue_scheming.1013.c.tt
			hidden_effect = { add_intrigue_lifestyle_xp = major_lifestyle_xp }
		}
		add_character_modifier = {
			modifier = invented_code_resistance_modifier
			days = 1095
		}
	}

	after = {
		remove_character_flag = transposition
		remove_character_flag = substitution
		remove_character_flag = cipher
		remove_variable = intrigue_exp_gain_value
	}
}

intrigue_scheming.1014 = {
	type = character_event
	title = intrigue_scheming.1011.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:cryptographer = {
						is_alive = yes
					}
				}
				desc = intrigue_scheming.1014.desc_alive
			}
			triggered_desc = {
				trigger = {
					scope:cryptographer = {
						is_alive = no
					}
				}
				desc = intrigue_scheming.1014.desc_dead
			}
		}
	}
	
	theme = intrigue_skulduggery_focus
	left_portrait = {
		character = root
		animation = disgust
	}
	right_portrait = {
		character = scope:cryptographer
		animation = shame
	}

	option = {
		name = intrigue_scheming.1014.a
		add_intrigue_lifestyle_xp = miniscule_lifestyle_xp
		if = {
			limit = {
				scope:cryptographer = {
					is_alive = no
				}
			}
			add_character_modifier = {
				modifier = invented_code_resistance_modifier
				days = 1095
			}
		}
	}

}

##################################################
#Hired spies construct a report of your castle's weaknesses
	#by Linnéa Thimrén
##################################################

intrigue_scheming.1201 = {
	type = character_event
	title = intrigue_scheming.1201.t
	desc = intrigue_scheming.1201.desc
	
	theme = intrigue_skulduggery_focus
	left_portrait = {
		character = root
		animation = personality_dishonorable
	}
	
	trigger = {
		NOT = { has_character_flag = hired_spies_to_report_event }
		is_landed = yes
		exists = capital_county
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = 0.2
			has_trait = paranoid
		}
		upweight_for_focus_modifier = { FOCUS = intrigue_skulduggery_focus }
	}

	immediate = {
		add_character_flag = {
			flag = hired_spies_to_report_event
			days = 3650
		}
	}

	option = { #yes, please crawl all over my castle!
		name = intrigue_scheming.1201.a
		remove_short_term_gold = medium_gold_value
		trigger_event = {
			id = intrigue_scheming.1202
			days = { 30 60 }
		}
		stress_impact = {
			arrogant = minor_stress_impact_gain
			greedy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 70
		}
	}

	option = { #say no and gain a slight defense bonus
		name = intrigue_scheming.1201.b
		capital_county = {
			add_county_modifier = {
				modifier = minor_increased_castle_defense
				days = 3650
			}
		}
		stress_impact = {
			humble = minor_stress_impact_gain
		}
		ai_chance = {
			base = 30
			modifier = {
				add = 40
				has_trait = paranoid
				has_trait = arrogant
			}
		}
	}
}

#You said yes, gain defense modifier and/or keep them around?
intrigue_scheming.1202 = {
	type = character_event
	title = intrigue_scheming.1201.t
	desc = intrigue_scheming.1202.desc
	
	theme = intrigue_skulduggery_focus
	left_portrait = {
		character = scope:hired_spy
		animation = personality_vengeful
	}

	trigger = {
		is_ruler = yes
		exists = capital_county
	}

	immediate = {
		create_character = {
			employer = root
			gender_female_chance = {
				if = {
					limit = { root.faith = { has_doctrine = doctrine_gender_female_dominated } }
					add = 65
				}
				else_if = {
					limit = { root.faith = { has_doctrine = doctrine_gender_male_dominated } }
					add = 35
				}
				else = {
					add = 50
				}
			}
			age = { 20 40 }
			intrigue = { 10 12 }
			trait = education_intrigue_3
			faith = root.faith
			culture = root.culture
			save_scope_as = hired_spy
		}
	}

	#Spy leaves (+xp, no modifier)
	#Spy remains (+xp, modifier)
	#Spy is killed (++xp, no modifier)

	option = { #Hired spy leaves you with defense mod and focus point gain
		name = intrigue_scheming.1202.a
		remove_courtier_or_guest = scope:hired_spy
		add_intrigue_lifestyle_xp = minor_lifestyle_xp
		stress_impact = {
			paranoid = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
		}
	}

	option = { #Hired spy stays and you get defense mod and focus point gain
		name = intrigue_scheming.1202.b
		custom_tooltip = intrigue_scheming.1202.b.tt
		capital_county = {	
			add_county_modifier = {
				modifier = increased_castle_defense
				days = 3650
			}
		}
		add_intrigue_lifestyle_xp = minor_lifestyle_xp
		stress_impact = {
			paranoid = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
		}
	}

	option = { #They have to die. You get the focus point gain though!
		name = intrigue_scheming.1202.c
		trigger = {
			OR = {
				has_trait = sadistic
				has_trait = paranoid
				has_trait = callous
			}
		}
		trait = sadistic
		trait = paranoid
		trait = callous

		add_dread = medium_dread_gain
		scope:hired_spy = {
			death = {
				killer = root
				death_reason = death_disappearance
			}
		}
		add_intrigue_lifestyle_xp = medium_lifestyle_xp
		stress_impact = {
			compassionate = minor_stress_impact_gain
			trusting = minor_stress_impact_gain
		}
		ai_chance = {
			base = 0
			modifier = {
				add = 50
				OR = {
					has_trait = paranoid
					has_trait = deceitful
				}
			}
			modifier = {
				add = 30
				OR = {
					has_trait = wrathful
					has_trait = callous
				}
			}
		}
	}
}

##################################################
# Meet a merchant from a far away land
	# by Linnéa Thimrén
##################################################

intrigue_scheming.1401 = {
	type = character_event
	title = intrigue_scheming.1401.t
	desc = {
		desc = intrigue_scheming.1401.desc_opening
		random_valid = {
			triggered_desc = {
				trigger = {
					has_character_flag = outcome_1
				}
				desc = intrigue_scheming.1401.desc1
			}
			triggered_desc = {
				trigger = {
					has_character_flag = outcome_2
				}
				desc = intrigue_scheming.1401.desc2
			}
			triggered_desc = {
				trigger = {
					has_character_flag = outcome_3
				}
				desc = intrigue_scheming.1401.desc3
			}
		}
		desc = intrigue_scheming.1401.desc_ending
	}
	
	theme = intrigue_skulduggery_focus
	override_background = { event_background = market }
	
	left_portrait = {
		character = root
		animation = personality_rational
	}
	
	trigger = {
		NOT = { has_character_flag = met_merchant_event }
		is_landed = yes
		exists = capital_county
	}

	weight_multiplier = {
		base = 1
		compare_modifier = {
			target = root
			value = stewardship
			step = 2
			multiplier = 0.1
		}
		upweight_for_focus_modifier = { FOCUS = intrigue_skulduggery_focus }
	}

	immediate = {
		add_character_flag = {
			flag = met_merchant_event
			days = 3650
		}
		random_dummy_gender_effect = yes
		hidden_effect = {
			random_list = {
				10 = {
					add_character_flag = {
						flag = outcome_1
						days = 10
					}
				}
				10 = {
					add_character_flag = {
						flag = outcome_2
						days = 10
					}
				}
				10 = {
					add_character_flag = {
						flag = outcome_3
						days = 10
					}
				}
			}
		}
		capital_county = {
			save_scope_as = county
		}
	}


	option = {
		name = intrigue_scheming.1401.a
		flavor = intrigue_scheming.1401.a.tt

		duel = {
			skill = diplomacy
			value = decent_skill_rating
			12 = {		
				desc = intrigue_scheming.1401.a.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 1
				}
				if = {
					limit = {
						has_character_flag = outcome_1
					}
					send_interface_toast = {
						title = intrigue_scheming.1401.a.success
						add_character_modifier = {
							modifier = more_vigilant_recistance_modifier
							days = 1095
						}
					}
				}
				else_if = {
					limit = {
						has_character_flag = outcome_2
					}
					send_interface_toast = {
						title = intrigue_scheming.1401.a.success
						add_character_modifier = {
							modifier = read_people_power_modifier
							days = 1095
						}
					}
				}
				else_if = {
					limit = {
						has_character_flag = outcome_3
					}
					send_interface_toast = {
						title = intrigue_scheming.1401.a.success
						add_character_modifier = {
							modifier = better_understanding_of_people
							days = 1095
						}
					}
				}
				add_intrigue_lifestyle_xp = minor_lifestyle_xp
			}
			12 = {		
				desc = intrigue_scheming.1401.a.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -1
				}
				send_interface_toast = {	
					title = intrigue_scheming.1401.a.failure
					add_prestige = minor_prestige_loss
				}
			}
		}
		stress_impact = {
			vengeful = minor_stress_impact_gain
			wrathful = minor_stress_impact_gain
			arrogant = minor_stress_impact_gain
			sadistic = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
			modifier = {
				add = 20
				OR = {
					has_trait = gregarious
					has_trait = calm
					has_trait = temperate
				}
			}
			compare_modifier = {
			target = root
				value = stewardship
				step = 2
				multiplier = 0.2
			}
		}
	}

	option = {
		name = intrigue_scheming.1401.b
		add_dread = minor_dread_gain
		random = {
			chance = 30
			send_interface_toast = {
				title = intrigue_scheming.1401.b.penalty
				left_icon = scope:county
				scope:county = {
					add_county_modifier = {
						modifier = intrigue_threatened_merchant_modifier
						days = 1825
					}
				}
			}
		}
		if = {
			limit = {
				has_character_flag = outcome_1
			}
			add_character_modifier = {
				modifier = more_vigilant_recistance_modifier
				days = 1095
			}
		}
		else_if = {
			limit = {
				has_character_flag = outcome_2
			}
			add_character_modifier = {
				modifier = read_people_power_modifier
				days = 1095
			}
		}
		else_if = {
			limit = {
				has_character_flag = outcome_3
			}
			add_character_modifier = {
				modifier = better_understanding_of_people
				days = 1095
			}
		}
		add_intrigue_lifestyle_xp = miniscule_lifestyle_xp
		stress_impact = {
			gregarious = minor_stress_impact_gain
			just = minor_stress_impact_gain
			compassionate = minor_stress_impact_gain
			calm = minor_stress_impact_gain
			temperate = minor_stress_impact_gain
			forgiving = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
			modifier = {
				add = 20
				OR = {
					has_trait = vengeful
					has_trait = wrathful
					has_trait = sadistic
					has_trait = callous
					has_trait = arrogant
				}
			}
		}
	}
	option = {
		name = intrigue_scheming.1401.c
		remove_short_term_gold = medium_gold_value
		if = {
			limit = {
				has_character_flag = outcome_1
			}
			add_character_modifier = {
				modifier = more_vigilant_recistance_modifier
				days = 1095
			}
		}
		else_if = {
			limit = {
				has_character_flag = outcome_2
			}
			add_character_modifier = {
				modifier = read_people_power_modifier
				days = 1095
			}
		}
		else_if = {
			limit = {
				has_character_flag = outcome_3
			}
			add_character_modifier = {
				modifier = better_understanding_of_people
				days = 1095
			}
		}
		add_intrigue_lifestyle_xp = minor_lifestyle_xp
		stress_impact = {
			greedy = medium_stress_impact_gain
			vengeful = minor_stress_impact_gain
			wrathful = minor_stress_impact_gain
			arrogant = minor_stress_impact_gain
			sadistic = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
			modifier = {
				add = 20
				OR = {
					has_trait = compassionate
					has_trait = generous
				}
			}
		}
	}
	after = {
		remove_character_flag = outcome_1
		remove_character_flag = outcome_2
		remove_character_flag = outcome_3
	}
}

##################################################
#Potential to turn a secret into a hook - or other things
#	by Petter Vilberg
##################################################

scripted_trigger intrigue_scheming_1601_target_requirement_trigger = {
	#Trigger for the blackmailed vassal
	is_ai = yes
	any_secret = {
		is_known_by = root
	}
	NOT = {
		root = { has_hook = prev }
	}
}

scripted_trigger intrigue_scheming_1601_other_character_trigger = {
	#Trigger for the possible reputation-target
	is_ai = yes
	opinion = {
		target = scope:blackmailed_vassal
		value > low_positive_opinion
	}
	opinion = {
		target = root
		value < high_positive_opinion
	}
}

intrigue_scheming.1601 = {
	type = character_event
	title = intrigue_scheming.1601.t
	desc = intrigue_scheming.1601.desc
	
	theme = intrigue_skulduggery_focus
	left_portrait = {
		character = scope:blackmailed_vassal
		animation = worry
	}
	
	trigger = {
		NOT = { has_character_flag = had_intrigue_scheming_1601_event }
		any_vassal = {
			intrigue_scheming_1601_target_requirement_trigger = yes
			save_temporary_scope_as = blackmailed_vassal
		}
	}

	immediate = {
		add_character_flag = {
			flag = had_intrigue_scheming_1601_event
			days = 1825
		}
		random_vassal = {
			limit = { intrigue_scheming_1601_target_requirement_trigger = yes }
			save_scope_as = blackmailed_vassal
		}
		random_vassal = {
			limit = {
				intrigue_scheming_1601_other_character_trigger = yes
				any_targeting_scheme = {
					scheme_type = seduce
					scheme_owner = root
				}
			}
			alternative_limit = {
				intrigue_scheming_1601_other_character_trigger = yes
				any_targeting_scheme = {
					scheme_type = befriend
					scheme_owner = root
				}
			}
			alternative_limit = {
				intrigue_scheming_1601_other_character_trigger = yes
				is_powerful_vassal = yes
			}
			alternative_limit = {
				intrigue_scheming_1601_other_character_trigger = yes
			}
			save_scope_as = other_vassal
		}
		add_intrigue_lifestyle_xp = medium_lifestyle_xp
	}

	option = { #Pay me
		name = intrigue_scheming.1601.a
		scope:blackmailed_vassal = {
			pay_short_term_gold = {
				gold = medium_gold_value
				target = root
			}
		}
		stress_impact = {
			generous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 1
			}
		}
	}

	option = { #Talk me up to someone
		name = intrigue_scheming.1601.b
		trigger = {
			exists = scope:other_vassal
		}
		scope:other_vassal = {
			add_opinion = {
				target = root
				modifier = reputation_opinion
				opinion = low_positive_opinion
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 0.5
			}
		}
	}
	
	option = { #I just thought you should know
		name = intrigue_scheming.1601.c
		add_dread = minor_dread_gain
		scope:blackmailed_vassal = {
			stress_impact = {
				base = medium_stress_gain
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = -1
			}
		}
	}
}


##################################################
# GAIN INTRIGUE MENTOR #
#	by Linnéa Thimrén  #
##################################################

scripted_trigger intrigue_scheming_2001_future_mentor_trigger = {
	is_adult = yes
	is_ai = yes
	is_landed = no
	is_close_family_or_spouse_of_root_trigger = no
	opinion = {
		target = root
		value > neutral_opinion
	}
	intrigue > root.intrigue
	OR = {
		AND = {
			OR = {
				is_ai = no
				is_adult = yes
				has_lifestyle = intrigue_lifestyle
			}
			intrigue >= decent_skill_rating
		}
		intrigue >= high_skill_rating
	}
}

#Gain intrigue mentor
intrigue_scheming.2001 = {
	type = character_event
	title = intrigue_scheming.2001.t
	desc = intrigue_scheming.2001.desc
	
	theme = intrigue_skulduggery_focus
	left_portrait = {
		character = scope:future_mentor
		animation = personality_dishonorable
	}
	
	trigger = {
		NOT = { has_character_flag = had_intrigue_scheming_2001_event }
		num_of_relation_intrigue_mentor = 0
		OR = {
			any_courtier_or_guest = {
				intrigue_scheming_2001_future_mentor_trigger = yes
			}
			court_owner = {
				any_courtier_or_guest = {
					has_dynasty = yes
					this.dynasty = {
						any_dynasty_member = {
							intrigue_scheming_2001_future_mentor_trigger = yes
						}
					}
				}
			}
		}
	}

	immediate = {
		add_character_flag = {
			flag = had_intrigue_scheming_2001_event
			days = 1825
		}
		random_courtier_or_guest = {
			limit = {
				intrigue_scheming_2001_future_mentor_trigger = yes
			}
			save_scope_as = future_mentor
		}
		if = {
			limit = {
				NOT = { exists = scope:future_mentor }
			}
			court_owner = {
				random_courtier = {
					limit = {
						has_dynasty = yes
						this.dynasty = {
							any_dynasty_member = {
								intrigue_scheming_2001_future_mentor_trigger = yes
							}
						}
					}
					this.dynasty = {
						random_dynasty_member = {
							limit = {
								intrigue_scheming_2001_future_mentor_trigger = yes
							}
							save_scope_as = future_mentor
						}
					}
				}
			}
		}
		if = {
			limit = {
				NOT = { exists = scope:future_mentor }
			}
			court_owner = {
				random_courtier_or_guest = {
					limit = {
						has_dynasty = yes
						this.dynasty = {
							any_dynasty_member = {
								intrigue_scheming_2001_future_mentor_trigger = yes
							}
						}
					}
					this.dynasty = {
						random_dynasty_member = {
							limit = {
								intrigue_scheming_2001_future_mentor_trigger = yes
							}
							save_scope_as = future_mentor
						}
					}
				}
			}
		}
		scope:future_mentor = {
			assign_quirk_effect = yes
		}
		add_intrigue_lifestyle_xp = minor_lifestyle_xp
	}

	option = {
		name = intrigue_scheming.2001.a
		hidden_effect = {
			set_relation_intrigue_mentor = scope:future_mentor
		}
		set_relation_mentor = scope:future_mentor
	}

	option = {
		name = intrigue_scheming.2001.b
		scope:future_mentor = {
			add_opinion = {
				modifier = insulted_courtier
				target = root
			}
		}
	}
}

##################################################
#Sneaky person seeks you out (might be an agent)
#	by Linnéa Thimrén
##################################################

intrigue_scheming.2101 = {
	type = character_event
	title = intrigue_scheming.2101.t
	desc = intrigue_scheming.2101.desc
	
	theme = intrigue_skulduggery_focus
	left_portrait = {
		character = scope:sneaky_person
		animation = personality_bold
	}
	
	trigger = {
		NOT = { has_character_flag = had_intrigue_scheming_2101_event }
	}

	weight_multiplier = {
		base = 0.2
		modifier = {
			add = 0.8
			any_scheme = {
				scheme_owner = {
					this = root
				}
				scheme_target = {
					is_in_the_same_court_as_or_guest = root
				}
			}
		}
		upweight_for_focus_modifier = { FOCUS = intrigue_skulduggery_focus }
	}

	immediate = {
		add_character_flag = {
			flag = had_intrigue_scheming_2101_event
			days = 3650
		}
		create_character = {
			location = root.capital_province
			age = { 20 40 }
			trait = education_intrigue_3
			trait = deceitful
			intrigue = { 10 15 }
			culture = root.culture
			faith = root.faith
			save_scope_as = sneaky_person
			gender_female_chance = 50
			dynasty = none
		}
		if = {
			limit = {
				any_targeting_scheme = { count >= 1 }
			}
			random_targeting_scheme = {
				limit = {
					scheme_skill = intrigue
					scheme_owner = { is_ai = yes }
				}
				save_scope_as = sneaky_person_scheme
				scheme_owner = {
					save_scope_as = sneaky_person_scheme_owner
					hidden_effect = {
						if = {
							limit = {
								can_add_hook = {
									type = favor_hook
									target = scope:sneaky_person #They are an agent!
								}
							}
							random = {
								chance = 50
								add_hook = {
									type = favor_hook
									target = scope:sneaky_person #They are an agent!
								}
							}
						}
					}
				}
			}
		}
	}

	option = { #You're hired!
		name = intrigue_scheming.2101.a
		scope:sneaky_person = {
			visit_court_of = root
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = low_positive_opinion
			}
		}
		if = {
			limit = {
				exists = scope:sneaky_person_scheme_owner
				intrigue > scope:sneaky_person.intrigue
			}
			trigger_event = {
				id = intrigue_scheming.2102 #You suspect something is up with them
				days = { 60 90 }
			}
		}
		ai_chance = {
			base = 100
		}
	}

	option = { #No thank you
		name = intrigue_scheming.2101.b
		scope:sneaky_person = {
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = low_negative_opinion
			}
		}
		ai_chance = {
			base = 0
			modifier = {
				add = 80
				has_trait = paranoid
			}
		}
	}
}

intrigue_scheming.2102 = {
	type = character_event
	title = intrigue_scheming.2102.t
	desc = intrigue_scheming.2102.desc
	
	theme = intrigue_skulduggery_focus
	left_portrait = {
		character = scope:sneaky_person
		animation = paranoia
	}
	
	trigger = {
		scope:sneaky_person_scheme = {
			scheme_is_character_agent = scope:sneaky_person
		}
		scope:sneaky_person = {
			host = root
		}
		exists = cp:councillor_spymaster
		scope:sneaky_person = cp:councillor_spymaster
	}

	immediate = {
	}

	option = { #Call them out on their shady business!
		name = intrigue_scheming.2102.a
		add_intrigue_lifestyle_xp = minor_lifestyle_xp
		duel = {
			target = scope:sneaky_person
			skill = intrigue
			12 = {		
				desc = intrigue_scheming.2102.a.tt
				compare_modifier = {
					value = scope:duel_value
					multiplier = 0.5
				}
				custom_tooltip = intrigue_scheming.2102.a.tt
				send_interface_toast = {
					left_icon = scope:sneaky_person
					title = intrigue_scheming.2102.a.tt
				}
				add_character_flag = {
					flag = not_noticed
					days = 80
				}
			}
			12 = {		
				desc = intrigue_scheming.2102.b.tt
				compare_modifier = {
					value = scope:duel_value
					multiplier = -0.5
				}
				custom_tooltip = intrigue_scheming.2102.b.tt
				send_interface_toast = {
					left_icon = scope:sneaky_person
					title = intrigue_scheming.2102.b.tt
				}
				add_character_flag = {
					flag = noticed
					days = 80
				}
			}
		}
		trigger_event = {
			id = intrigue_scheming.2103
			days = { 30 60 }
		}
		stress_impact = {
			trusting = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				add = 20
				OR = {
					has_trait = paranoid
					has_trait = wrathful
					has_trait = vengeful
					has_trait = ambitious
					has_trait = deceitful
				}
			}
		}
	}

	option = { #Never mind
		name = intrigue_scheming.2102.b
		stress_impact = {
			paranoid = medium_stress_impact_gain
		}
		ai_chance = {
			base = 0
			modifier = {
				add = 50
				OR = {
					has_trait = trusting
					has_trait = honest
					has_trait = calm
					has_trait = lazy
					has_trait = content
					has_trait = forgiving
				}
			}
		}
	}
}

intrigue_scheming.2103 = {
	type = character_event
	title = intrigue_scheming.2102.t
	desc = {
		random_valid = {
			triggered_desc = {
				trigger = {
					has_character_flag = not_noticed
				}
				desc = intrigue_scheming.2103.desc_not_noticed
			}
			triggered_desc = {
				trigger = {
					has_character_flag = noticed
				}
				desc = intrigue_scheming.2103.desc_noticed
			}
		}
	}
	
	theme = intrigue_skulduggery_focus
	left_portrait = {
		character = scope:sneaky_person
		animation = scheme
	}

	trigger = {
		scope:sneaky_person_scheme = {
			NOT = {
				is_scheme_agent_exposed = scope:sneaky_person
			}
		}
	}

	immediate = {
	
	}

	option = { #Imprison them!
		name = intrigue_scheming.2103.a
		trigger = {
			has_character_flag = not_noticed
		}
		scope:sneaky_person_scheme = {
			expose_scheme_agent = scope:sneaky_person
		}
		imprison = {
			target = scope:sneaky_person
			type = dungeon
		}
	}

	option = { #Throw them out!
		name = intrigue_scheming.2103.b
		trigger = {
			has_character_flag = not_noticed
		}
		remove_courtier_or_guest = scope:sneaky_person
		hidden_effect = {
			if = {
				limit = {
					scope:sneaky_person_scheme_owner = {
						is_landed = yes
						court_owner = this
					}		
				}
				scope:sneaky_person_scheme_owner = {
					add_courtier = scope:sneaky_person
				}
			}
		}
	}
	option = {
		name = intrigue_scheming.2103.c
		trigger = {
			has_character_flag = noticed
		}
	}
	after = {
		remove_character_flag = not_noticed
		remove_character_flag = noticed
	}
}

##################################################
# Servants and Masters
# 3001-3039
#  by Petter Vilberg
##################################################
#Convert a Hook on someone's Courtier into a Secret or Hook on the Court Owner

scripted_trigger intrigue_scheming_3001_new_target_trigger = {
	is_ai = yes
	NOT = { this = root }
	OR = {
		target_is_liege_or_above = root
		any_vassal = {
			this = root
		}
		AND = {
			top_liege = root.top_liege
			OR = {
				highest_held_title_tier = root.highest_held_title_tier
				highest_held_title_tier < root.highest_held_title_tier
			}
		}
		#Neighboring ruler of one rank lower than root
		any_neighboring_realm_same_rank_owner = {
			liege = { this = root }
		}
	}
	NOT = {
		any_targeting_scheme = {
			scheme_owner = root
			scheme_type = murder
		}
	}
	NOT = {
		root = {
			has_hook = prev
		}
	}
}

scripted_trigger intrigue_scheming_3001_hooked_courtier_trigger = {
	is_ai = yes
	is_landed = no
	age >= 14
	exists = court_owner
	court_owner = {
		intrigue_scheming_3001_new_target_trigger = yes
	}	
}

scripted_trigger intrigue_scheming_3001_relevant_secret_trigger = {
	secret_owner = { save_temporary_scope_as = relevant_secret_owner }
	OR = {
		secret_is_always_interesting_trigger = yes
		is_blackmailable_secret_trigger = { BLACKMAILER = root PARTICIPANT = scope:relevant_secret_owner }
	}
	NOT = { is_known_by = root }
}

intrigue_scheming.3001 = {
	type = character_event
	title = intrigue_scheming.3001.t
	desc = intrigue_scheming.3001.desc
	
	theme = intrigue_skulduggery_focus
	left_portrait = {
		character = scope:hooked_courtier
		animation = worry
	}
	right_portrait = {
		character = scope:new_target
		animation = happiness
	}
	
	trigger = {
		any_hooked_character = {
			intrigue_scheming_3001_hooked_courtier_trigger = yes
		}
		NOT = { has_character_flag = had_event_intrigue_scheming_3001 }
	}

	weight_multiplier = {
		base = 1
		compare_modifier = {
			value = intrigue
			multiplier = 0.05
		}
		downweight_for_focus_modifier = { FOCUS = intrigue_temptation_focus }
	}

	immediate = {
		add_character_flag = {
			flag = had_event_intrigue_scheming_3001
			years = 5
		}
		random_hooked_character = {
			limit = {
				root = { NOT = { has_strong_hook = prev } }
				intrigue_scheming_3001_hooked_courtier_trigger = yes
			}
			alternative_limit = {
				intrigue_scheming_3001_hooked_courtier_trigger = yes
			}
			save_scope_as = hooked_courtier
			court_owner = {
				save_scope_as = new_target
			}
		}
	}

	option = { #Look for a Secret
		name = intrigue_scheming.3001.a
		trigger = {
			NOR = {
				has_trait = deceitful
				has_trait = schemer
				has_focus = intrigue_skulduggery_focus
			}
		}
		remove_hook = {
			target = scope:hooked_courtier
		}
		custom_tooltip = intrigue_scheming.3001.a.tt			
		trigger_event = {
			id = intrigue_scheming.3002 #Event to figure out if there is a secret to be found
			days = { 5 10 }
		}
		stress_impact = {
			honest = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = medium_chance_impact_negative_honor
			}
		}
	}

	option = { #Look for or fabricate a secret
		name = intrigue_scheming.3001.b
		trigger = {
			OR = {
				has_trait = deceitful
				has_trait = schemer
				has_focus = intrigue_skulduggery_focus
			}
			OR = {
				random_blackmailable_secret_can_be_added_simple_trigger = {
					TARGET = scope:new_target
					BLACKMAILER = root
				}
				scope:new_target = {
					any_secret = {
						intrigue_scheming_3001_relevant_secret_trigger = yes
					}
				}
			}
		}
		trait = deceitful
		add_intrigue_lifestyle_xp = medium_lifestyle_xp
		remove_hook = {
			target = scope:hooked_courtier
		}
		custom_tooltip = intrigue_scheming.3001.b.tt
		show_as_tooltip = {
			duel = {
				skill = intrigue
				target = scope:new_target
				20 = {		
					compare_modifier = {
						value = scope:duel_value
						multiplier = 1
						min = -19
					}
					desc = intrigue_scheming.3001.b.success
					send_interface_toast = {
						title = intrigue_scheming.3001.b.success
						left_icon = scope:hooked_courtier
						right_icon = scope:new_target
						custom_tooltip = intrigue_scheming.3001.b.success_tt
					}
				}
				10 = {		
					compare_modifier = {
						value = scope:duel_value
						multiplier = -1
						min = -9
					}
					desc = intrigue_scheming.3001.b.failure
					send_interface_toast = {
						title = intrigue_scheming.3001.b.failure
						left_icon = scope:hooked_courtier
						right_icon = scope:new_target
						scope:new_target = {
							add_opinion = {
								target = root
								modifier = angry_opinion
								opinion = low_negative_opinion
							}
						}
					}
				}
			}
		}
		hidden_effect = {
			trigger_event = {
				id = intrigue_scheming.3011
				days = { 5 10 }
			}
		}
		stress_impact = {
			honest = major_stress_impact_gain
			lazy = minor_stress_impact_gain	
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = medium_chance_impact_negative_honor
				ai_honor = medium_chance_impact_positive_boldness
			}
		}
	}

	option = { #Depraved option
		name = intrigue_scheming.3001.c
		trigger = {
			OR = {
				has_trait = sadistic
				has_trait = torturer
				has_focus = intrigue_intimidation_focus
			}
		}
		trait = sadistic
		add_intrigue_lifestyle_xp = medium_lifestyle_xp
		remove_hook = {
			target = scope:hooked_courtier
		}
		duel = {
			skill = intrigue
			target = scope:hooked_courtier
			25 = {		
				compare_modifier = {
					value = scope:duel_value
					multiplier = 1
				}
				desc = intrigue_scheming.3001.c.success
				show_as_tooltip = {
					scope:hooked_courtier = {
						death = {
							death_reason = death_murder
							killer = scope:new_target
						}
					}
					scope:new_target = {
						add_secret = {
							type = secret_murder
							target = scope:hooked_courtier
						}
					}
				}
				hidden_effect = {
					trigger_event = {
						id = intrigue_scheming.3021
						days = { 5 10 }
					}
				}
			}
			10 = {
				desc = intrigue_scheming.3001.c.failure_secret
				show_as_tooltip = {
					scope:hooked_courtier = {
						death = {
							death_reason = death_plotting
						}
					}
				}
				hidden_effect = {
					trigger_event = {
						id = intrigue_scheming.3023
						days = { 5 10 }
					}
				}
			}
			10 = {		
				compare_modifier = {
					value = scope:duel_value
					multiplier = -0.5
					min = -9
				}
				desc = intrigue_scheming.3001.c.failure
				show_as_tooltip = {
					scope:hooked_courtier = {
						death = {
							death_reason = death_murder
							killer = root
						}
					}
					add_secret = {
						type = secret_murder
						target = scope:hooked_courtier
					}
					custom_tooltip = intrigue_scheming.3001.c.failure.tt
				}
				hidden_effect = {
					trigger_event = {
						id = intrigue_scheming.3022
						days = { 5 10 }
					}
				}
			}
		}
		stress_impact = {
			compassionate = major_stress_impact_gain
			honest = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = high_chance_impact_negative_honor
				ai_compassion = high_chance_impact_negative_compassion
			}
		}
	}

	option = { #Threaten your way to a Hook
		name = intrigue_scheming.3001.d
		trigger = {
			dread > medium_dread
			can_add_hook = {
				target = scope:new_target
				type = threat_hook
			}	
		}
		add_internal_flag = special
		custom_tooltip = available_because_of_dread_tt
		remove_hook = {
			target = scope:hooked_courtier
		}
		duel = {
			skill = intrigue
			target = scope:new_target
			12 = {		
				compare_modifier = {
					value = scope:duel_value
					multiplier = 1
					min = -1
				}
				desc = intrigue_scheming.3001.d.success
				show_as_tooltip = {
					add_hook = {
						target = scope:new_target
						type = threat_hook
					}
					scope:new_target = {
						add_opinion = {
							target = root
							modifier = cruelty_opinion
							opinion = -30
						}
					}
				}
				hidden_effect = {
					trigger_event = {
						id = intrigue_scheming.3031
						days = { 5 10 }
					}
				}
			}
			12 = {		
				compare_modifier = {
					value = scope:duel_value
					multiplier = -1
					min = -11
				}
				desc = intrigue_scheming.3001.d.failure
				show_as_tooltip = {	
					add_dread = minor_dread_loss
					scope:new_target = {
						add_opinion = {
							target = root
							modifier = respect_opinion
							opinion = -30
						}
					}
				}
				hidden_effect = {
					trigger_event = {
						id = intrigue_scheming.3032
						days = { 5 10 }
					}
				}
			}
		}
		stress_impact = {
			compassionate = minor_stress_impact_gain
			craven = medium_stress_impact_gain
			humble = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = medium_chance_impact_negative_honor
				ai_boldness = medium_chance_impact_positive_boldness
			}
		}
	}

	option = { #Decline
		name = intrigue_scheming.3001.z
		add_dread = minor_dread_gain
		stress_impact = {
			humble = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
		}
	}
}

#Event checking for the existence of a Secret
intrigue_scheming.3002 = {
	hidden = yes

	immediate = {
		if = {
			limit = {
				scope:new_target = {
					any_secret = {
						intrigue_scheming_3001_relevant_secret_trigger = yes
					}
				}
			}
			scope:new_target = {
				random_secret = {
					limit = {
						intrigue_scheming_3001_relevant_secret_trigger = yes
					}
					save_scope_as = secret_to_reveal
				}
			}
			trigger_event = intrigue_scheming.3003
		}
		else = {
			trigger_event = intrigue_scheming.3004
		}
	}
}


#A Secret was found!
intrigue_scheming.3003 = {
	type = character_event
	title = intrigue_scheming.3001.t
	desc = intrigue_scheming.3003.desc
	
	theme = intrigue_skulduggery_focus
	left_portrait = {
		character = scope:hooked_courtier
		animation = shame
	}
	right_portrait = {
		character = scope:new_target
		animation = worry
	}
	
	immediate = {
		add_intrigue_lifestyle_xp = minor_lifestyle_xp
	}

	option = {
		name = intrigue_scheming.3003.a
		scope:secret_to_reveal = {
			reveal_to = root
		}
	}

	option = {
		trigger = {
			scope:secret_to_reveal = { is_blackmailable_secret_trigger = { BLACKMAILER = root PARTICIPANT = scope:new_target } }
		}
		name = intrigue_scheming.3003.b

		hidden_effect = {
			scope:secret_to_reveal = {
				reveal_to = root
			}
		}

		blackmail_target_with_secret_effect = { TARGET = scope:new_target SECRET = scope:secret_to_reveal }
	}
}


#No Secret was found
intrigue_scheming.3004 = {
	type = character_event
	title = intrigue_scheming.3001.t
	desc = intrigue_scheming.3004.desc
	
	theme = intrigue_skulduggery_focus
	left_portrait = {
		character = scope:hooked_courtier
		animation = disgust
	}
	right_portrait = {
		character = scope:new_target
		animation = happiness
	}
	
	option = {
		name = intrigue_scheming.3004.a
		add_dread = minor_dread_loss
	}
}


#Check if there is an existing secret to find
intrigue_scheming.3011 = {
	hidden = yes

	immediate = {
		if = {
			limit = {
				scope:new_target = {
					any_secret = {
						intrigue_scheming_3001_relevant_secret_trigger = yes
					}
				}
			}
			scope:new_target = {
				random_secret = {
					limit = {
						intrigue_scheming_3001_relevant_secret_trigger = yes
					}
					save_scope_as = secret_to_reveal
				}
			}
			trigger_event = intrigue_scheming.3012 #A Secret was found
		}
		else = {
			duel = {
				skill = intrigue
				target = scope:new_target
				20 = {		
					compare_modifier = {
						value = scope:duel_value
						multiplier = 1
					}
					desc = intrigue_scheming.3001.b.success
					trigger_event = intrigue_scheming.3013
				}
				10 = {		
					compare_modifier = {
						value = scope:duel_value
						multiplier = -0.5
						min = -9
					}
					desc = intrigue_scheming.3001.b.failure
					trigger_event = intrigue_scheming.3014
				}
			}
		}
	}
}

# A Secret was found!
intrigue_scheming.3012 = {
	type = character_event
	title = intrigue_scheming.3001.t
	desc = intrigue_scheming.3003.desc
	
	theme = intrigue_skulduggery_focus
	left_portrait = {
		character = scope:hooked_courtier
		animation = shame
	}
	right_portrait = {
		character = scope:new_target
		animation = worry
	}
	
	immediate = {
		add_intrigue_lifestyle_xp = minor_lifestyle_xp
	}

	option = {
		name = intrigue_scheming.3003.a
		scope:secret_to_reveal = {
			reveal_to = root
		}
	}

	option = {
		trigger = {
			scope:secret_to_reveal = { is_blackmailable_secret_trigger = { BLACKMAILER = root PARTICIPANT = scope:new_target } }
		}
		name = intrigue_scheming.3003.b

		hidden_effect = {
			scope:secret_to_reveal = {
				reveal_to = root
			}
		}

		blackmail_target_with_secret_effect = { TARGET = scope:new_target SECRET = scope:secret_to_reveal }
	}
}

# A Secret was fabricated
intrigue_scheming.3013 = {
	type = character_event
	title = intrigue_scheming.3001.t
	desc = intrigue_scheming.3013.desc
	
	theme = intrigue_skulduggery_focus
	left_portrait = {
		character = scope:hooked_courtier
		animation = shame
	}
	right_portrait = {
		character = scope:new_target
		animation = shock
	}

	trigger = {
		#NOTE: If a secret cannot be fabricated, something has happened between the previous event and this one, and the chain simply dies
		random_blackmailable_secret_can_be_added_simple_trigger = {
			TARGET = scope:new_target
			BLACKMAILER = root
		}
	}

	immediate = {
		scope:new_target = {
			add_random_blackmailable_secret_effect = {
				BLACKMAILER = root
			}
		}
		add_intrigue_lifestyle_xp = minor_lifestyle_xp
	}
	
	option = {
		name = intrigue_scheming.3013.a
		scope:new_secret = {
			reveal_to = root
		}
	}

	option = {
		trigger = {
			scope:new_secret = { is_blackmailable_secret_trigger = { BLACKMAILER = root PARTICIPANT = scope:new_target } }
		}
		name = intrigue_scheming.3003.b

		hidden_effect = {
			scope:new_secret = {
				reveal_to = root
			}
		}

		blackmail_target_with_secret_effect = { TARGET = scope:new_target SECRET = scope:new_secret }
	}
}

# Fabricating a Secret failed
intrigue_scheming.3014 = {
	type = character_event
	title = intrigue_scheming.3001.t
	desc = intrigue_scheming.3014.desc
	
	theme = intrigue_skulduggery_focus
	left_portrait = {
		character = scope:hooked_courtier
		animation = disgust
	}
	right_portrait = {
		character = scope:new_target
		animation = disapproval
	}
	
	option = {
		name = intrigue_scheming.3014.a
		scope:new_target = {
			add_opinion = {
				target = root
				modifier = angry_opinion
				opinion = -20
			}
		}
	}
}

# Tricking the target into committing murder
intrigue_scheming.3021 = {
	type = character_event
	title = intrigue_scheming.3001.t
	desc = intrigue_scheming.3021.desc
	
	theme = intrigue_skulduggery_focus
	left_portrait = {
		character = scope:hooked_courtier
		animation = shame
	}
	right_portrait = {
		character = scope:new_target
		animation = shock
	}
	
	immediate = {
		scope:hooked_courtier = {
			death = {
				death_reason = death_plotting
				killer = scope:new_target
			}
		}	
		scope:new_target = {
			add_secret = {
				type = secret_murder
				target = scope:hooked_courtier
			}
			random_secret = {
				limit = {
					secret_type = secret_murder
					secret_target = scope:hooked_courtier
				}
				save_scope_as = secret
			}
		}
		add_intrigue_lifestyle_xp = minor_lifestyle_xp
	}

	option = {
		name = intrigue_scheming.3021.a
		scope:secret = {
			reveal_to = root
		}
	}
	
	option = {
		trigger = {
			scope:secret = { is_blackmailable_secret_trigger = { BLACKMAILER = root PARTICIPANT = scope:new_target } }
		}
		name = intrigue_scheming.3003.b
		hidden_effect = {
			scope:secret = {
				reveal_to = root
			}
		}
		blackmail_target_with_secret_effect = { TARGET = scope:new_target SECRET = scope:secret }
	}
}


# Failing to trick the target into committing murder
# Secret is discovered
intrigue_scheming.3022 = {
	type = character_event
	title = intrigue_scheming.3001.t
	desc = intrigue_scheming.3022.desc
	
	theme = intrigue_skulduggery_focus
	left_portrait = {
		character = scope:hooked_courtier
		animation = disgust
	}
	right_portrait = {
		character = scope:new_target
		animation = disapproval
	}
	
	immediate = {
		scope:hooked_courtier = {
			death = {
				death_reason = death_plotting
				killer = root
			}
		}
		add_secret = {
			type = secret_murder
			target = scope:hooked_courtier
		}
		random_secret = {
			limit = {
				secret_type = secret_murder
				secret_target = scope:hooked_courtier
			}
			save_scope_as = secret
		}
	}

	option = {
		name = intrigue_scheming.3022.a
		scope:secret = {
			reveal_to = scope:new_target
		}
	}
}

# Failing to trick the target into committing murder
# Secret is safe
intrigue_scheming.3023 = {
	type = character_event
	title = intrigue_scheming.3001.t
	desc = intrigue_scheming.3023.desc
	
	theme = intrigue_skulduggery_focus
	left_portrait = {
		character = scope:hooked_courtier
		animation = disgust
	}
	right_portrait = {
		character = scope:new_target
		animation = disbelief
	}
	
	immediate = {
		scope:hooked_courtier = {
			death = {
				death_reason = death_plotting
				killer = root
			}
		}
	}

	option = {
		name = intrigue_scheming.3023.a
		add_secret = {
			type = secret_murder
			target = scope:hooked_courtier
		}
	}
}

# Successful Threats
intrigue_scheming.3031 = {
	type = character_event
	title = intrigue_scheming.3001.t
	desc = intrigue_scheming.3031.desc
	
	theme = intrigue_skulduggery_focus
	left_portrait = {
		character = scope:hooked_courtier
		animation = shame
	}
	right_portrait = {
		character = scope:new_target
		animation = fear
	}
	
	immediate = {
		add_intrigue_lifestyle_xp = minor_lifestyle_xp
	}

	option = {
		name = intrigue_scheming.3031.a
		add_intrigue_lifestyle_xp = minor_lifestyle_xp
		add_hook = {
			target = scope:new_target
			type = threat_hook
		}
		scope:new_target = {
			add_opinion = {
				target = root
				modifier = cruelty_opinion
				opinion = -30
			}
		}
	}
}

# Failure to Threaten
intrigue_scheming.3032 = {
	type = character_event
	title = intrigue_scheming.3001.t
	desc = intrigue_scheming.3032.desc
	
	theme = intrigue_skulduggery_focus
	left_portrait = {
		character = scope:hooked_courtier
		animation = disgust
	}
	right_portrait = {
		character = scope:new_target
		animation = disapproval
	}
	
	option = {
		name = intrigue_scheming.3032.a
		add_dread = minor_dread_loss
		scope:new_target = {
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = -30
			}
		}
	}
}

###END Servants and Masters

##################################################
# The Weight of Influence
# 3040 - 3059
#  by Petter Vilberg
##################################################

scripted_trigger intrigue_scheming_3041_liege_target = {
	is_ai = yes
	NOT = { this = root }
	OR = {
		#In the same realm as root and of equal or lower rank
		AND = {
			top_liege = root.top_liege
			OR = {
				highest_held_title_tier = root.highest_held_title_tier
				highest_held_title_tier < root.highest_held_title_tier
			}
		}
		#A neighbor of equal rank
		any_neighboring_realm_same_rank_owner = {
			this = root
		}
		#A neighbor of one rank below root
		liege = {
			any_neighboring_realm_same_rank_owner = {
				this = root
			}
		}
	}
	NOT = {
		any_targeting_scheme = {
			scheme_owner = root
			scheme_type = murder
		}
	}
	NOT = {
		root = {
			has_hook = prev
		}
	}
}

scripted_trigger intrigue_scheming_3041_vassal_target = {
	is_ai = yes
	exists = liege
	liege = {
		intrigue_scheming_3041_liege_target = yes
	}
	root = { has_usable_hook = prev }
}

intrigue_scheming.3041 = {
	type = character_event
	title = intrigue_scheming.3041.t
	desc = intrigue_scheming.3041.desc
	
	theme = intrigue_skulduggery_focus
	left_portrait = {
		character = scope:vassal_target
		animation = dismissal
	}
	right_portrait = {
		character = scope:liege_target
		animation = personality_honorable
	}
	
	trigger = {
		OR = {
			has_trait = schemer
			intrigue >= very_high_skill_rating
		}
		NOT = {
			has_character_flag = had_event_intrigue_scheming_3041
		}
		any_hooked_character = {
			intrigue_scheming_3041_vassal_target = yes
		}
	}

	weight_multiplier = {
		base = 1
		compare_modifier = {
			value = intrigue
			multiplier = 0.05
		}
		modifier = {
			add = 0.5
			has_focus = intrigue_intimidation_focus
		}
		modifier = {
			add = 0.5
			has_focus = intrigue_skulduggery_focus
		}
		upweight_for_focus_modifier = { FOCUS = intrigue_skulduggery_focus }
	}

	immediate = {
		add_character_flag = {
			flag = had_event_intrigue_scheming_3041
			years = 5
		}
		random_hooked_character = {
			limit = {
				intrigue_scheming_3041_vassal_target = yes
			}
			save_scope_as = vassal_target
			liege = {
				save_scope_as = liege_target
			}
		}
	}

	#Use vassal to pressure liege
	option = {
		name = intrigue_scheming.3041.a
		add_intrigue_lifestyle_xp = minor_lifestyle_xp
		use_hook = scope:vassal_target
		duel = {
			target = scope:liege_target
			skill = intrigue
			12 = {		
				compare_modifier = {
					value = scope:duel_value
					multiplier = 0.5
				}
				desc = intrigue_scheming.3041.a.success
				show_as_tooltip = {
					add_hook = {
						target = scope:liege_target
						type = manipulation_hook
					}
				}
				hidden_effect = {
					trigger_event = {
						id = intrigue_scheming.3042
						days = { 5 10 }
					}
				}
			}
			12 = {		
				compare_modifier = {
					value = scope:duel_value
					multiplier = -0.5
				}
				desc = intrigue_scheming.3041.a.failure
				show_as_tooltip = {
					reverse_add_opinion = {
						target = scope:liege_target
						modifier = angry_opinion
						opinion = medium_negative_opinion
					}
					if = {
						limit = {
							scope:liege_target.top_liege = {
								NOT = { this = root }
							}
						}
						reverse_add_opinion = {
							target = scope:liege_target.top_liege
							modifier = angry_opinion
							opinion = low_negative_opinion
						}
					}
				}
				trigger_event = {
					id = intrigue_scheming.3043
					days = { 5 10 }
				}
			}
		}
		stress_impact = {
			honest = medium_stress_impact_gain
			craven = minor_stress_impact_gain
			content = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = medium_chance_impact_positive_rationality
			}
		}
	}

	# Torture the vassal to make your point
	option = {
		name = intrigue_scheming.3041.b
		add_intrigue_lifestyle_xp = minor_lifestyle_xp
		use_hook = scope:vassal_target
		custom_tooltip = intrigue_scheming.3041.b.torture_desc
		show_as_tooltip = {
			random_list = {
				75 = {
					compare_modifier = {
						target = scope:liege_target
						value = ai_compassion
						multiplier = 0.25
					}
					desc = intrigue_scheming.3041.b.success
					send_interface_toast = {
						left_icon = scope:liege_target
						title = intrigue_scheming.3041.b.success
						add_hook = {
							target = scope:liege_target
							type = threat_hook
						}
						reverse_add_opinion = {
							target = scope:liege_target
							modifier = cruelty_opinion
							opinion = -30
						}
					}
					trigger_event = {
						id = intrigue_scheming.3052
						days = { 5 10 }
					}
				}
				25 = {
					compare_modifier = {
						target = scope:liege_target
						value = ai_boldness
						multiplier = 0.25
					}
					desc = intrigue_scheming.3041.b.failure
					send_interface_toast = {
						left_icon = scope:liege_target
						title = intrigue_scheming.3041.b.failure
						add_prestige = medium_prestige_loss
						reverse_add_opinion = {
							target = scope:liege_target
							modifier = respect_opinion
							opinion = -30
						}
					}
					trigger_event = {
						id = intrigue_scheming.3053
						days = { 5 10 }
					}
				}
			}
		}
		hidden_effect = {
			if = {
				#If the target is Sadistic, things do not go according to plan
				limit = {
					scope:liege_target = {
						OR = {
							has_trait = sadistic
							has_trait = torturer
						}
					}
				}
				trigger_event = {
					id = intrigue_scheming.3051
					days = { 5 10 }
				}
			}
			else = {
				#Roll for actual event outcome
				random_list = {
					75 = {
						compare_modifier = {
							target = scope:liege_target
							value = ai_compassion
							multiplier = 0.25
						}
						trigger_event = {
							id = intrigue_scheming.3052
							days = { 5 10 }
						}
					}
					25 = {
						compare_modifier = {
							target = scope:liege_target
							value = ai_boldness
							multiplier = 0.25
						}
						trigger_event = {
							id = intrigue_scheming.3053
							days = { 5 10 }
						}
					}
				}
			}
		}
		stress_impact = {
			compassionate = massive_stress_impact_gain
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_rationality = low_chance_impact_negative_rationality
				ai_honor = medium_chance_impact_negative_honor
			}
		}
	}
	
	# I can do it myself
	option = {
		name = intrigue_scheming.3041.c
		add_character_modifier = {
			modifier = intrigue_emphasizing_personal_schemes_modifier
			years = 5
		}
		ai_chance = {
			base = 100
			modifier = {
				add = 50
				has_trait = patient
			}
			modifier = {
				add = 50
				has_trait = diligent
			}
		}
	}
}

# Deception succeeds: Gain Manipulation Hook
intrigue_scheming.3042 = {
	type = character_event
	title = intrigue_scheming.3041.t
	desc = intrigue_scheming.3042.desc
	
	theme = intrigue_skulduggery_focus
	left_portrait = {
		character = scope:vassal_target
		animation = shock
	}
	right_portrait = {
		character = scope:liege_target
		animation = scheme
	}
	
	option = {
		name = intrigue_scheming.3042.a
		add_hook = {
			target = scope:liege_target
			type = manipulation_hook
		}
		scope:liege_target = {
			add_opinion = {
				target = scope:vassal_target
				modifier = angry_opinion
				opinion = -50
			}
			add_opinion = {
				target = root
				modifier = angry_opinion
				opinion = -30
			}
		}
	}
}

# Deception fails: Reduce Opinion(s)
intrigue_scheming.3043 = {
	type = character_event
	title = intrigue_scheming.3041.t
	desc = intrigue_scheming.3043.desc
	
	theme = intrigue_skulduggery_focus
	left_portrait = {
		character = scope:vassal_target
		animation = disapproval
	}
	right_portrait = {
		character = scope:liege_target
		animation = disgust
	}
	
	option = {
		name = intrigue_scheming.3043.a
		reverse_add_opinion = {
			target = scope:liege_target
			modifier = angry_opinion
			opinion = -40
		}
		if = {
			limit = {
				scope:liege_target.top_liege = {
					NOR = {
						this = root
						this = scope:liege_target
					}
				}
			}
			reverse_add_opinion = {
				target = scope:liege_target.top_liege
				modifier = angry_opinion
				opinion = -20
			}
		}
	}
}

# Depravity failed: Liege target is Sadistic
intrigue_scheming.3051 = {
	type = character_event
	title = intrigue_scheming.3041.t
	desc = intrigue_scheming.3051.desc
	
	theme = intrigue_skulduggery_focus
	left_portrait = {
		character = scope:vassal_target
		animation = fear
	}
	right_portrait = {
		character = scope:liege_target
		animation = lunatic
	}

	immediate = {
		scope:vassal_target = {
			death = {
				death_reason = death_disappearance
			}
		}
	}
	
	option = {
		name = intrigue_scheming.3051.a
		stress_impact = {
			base = medium_stress_gain
		}
		scope:liege_target = {
			add_dread = minor_dread_gain
		}
		hidden_effect = {
			add_opinion = {
				target = scope:liege_target
				modifier = cruelty_opinion
				opinion = -30
			}
		}
		reverse_add_opinion = {
			target = scope:liege_target
			modifier = respect_opinion
			opinion = -30
		}
	}

	option = {
		name = intrigue_scheming.3051.b
		trigger = {
			OR = {
				has_trait = sadistic
				has_trait = torturer
			}
		}
		trait = sadistic
		exclusive = yes
		scope:liege_target = {
			add_dread = minor_dread_gain
		}
		add_opinion = {
			target = scope:liege_target
			modifier = respect_opinion
			opinion = low_positive_opinion
		}
	}
}

# Depravity Success: Gain Threat Hook
intrigue_scheming.3052 = {
	type = character_event
	title = intrigue_scheming.3041.t
	desc = intrigue_scheming.3052.desc
	
	theme = intrigue_skulduggery_focus
	left_portrait = {
		character = scope:vassal_target
		animation = shock
	}
	right_portrait = {
		character = scope:liege_target
		animation = fear
	}

	immediate = {
		random_list = {
			1 = {
				trigger = {
					scope:vassal_target = {
						NOT = { has_trait = disfigured }
					}
				}
				scope:vassal_target = {
					add_trait = disfigured
				}
			}
			1 = {
				trigger = {
					scope:vassal_target = {
						NOT = { has_trait = blind }
					}
				}
				scope:vassal_target = {
					add_trait = blind
				}
			}
			1 = {
				trigger = {
					scope:vassal_target = {
						NOT = { has_trait = eunuch }
						is_male = yes
					}
				}
				scope:vassal_target = {
					add_trait = eunuch
				}
			}
			1 = {
				trigger = {
					scope:vassal_target = {
						NOT = { has_trait = maimed }
					}
				}
				scope:vassal_target = {
					add_trait = maimed
				}
			}
			1 = {
				trigger = {
					scope:vassal_target = {
						NOT = { has_trait = scarred }
					}
				}
				scope:vassal_target = {
					add_trait = scarred
				}
			}
		}
	}
	
	option = {
		name = intrigue_scheming.3052.a
		add_hook = {
			target = scope:liege_target
			type = threat_hook
		}
		reverse_add_opinion = {
			target = scope:liege_target
			modifier = disgusted_opinion
			opinion = medium_negative_opinion
		}
		reverse_add_opinion = {
			target = scope:vassal_target
			modifier = cruelty_opinion
			opinion = very_high_negative_opinion
		}
	}
}

#Depravity Failure:
intrigue_scheming.3053 = {
	type = character_event
	title = intrigue_scheming.3041.t
	desc = intrigue_scheming.3053.desc
	
	theme = intrigue_skulduggery_focus
	left_portrait = {
		character = scope:vassal_target
		animation = dismissal
	}
	right_portrait = {
		character = scope:liege_target
		animation = fear
	}

	immediate = {
		random_list = {
			1 = {
				trigger = {
					scope:vassal_target = {
						NOT = { has_trait = disfigured }
					}
				}
				scope:vassal_target = {
					add_trait = disfigured
				}
			}
			1 = {
				trigger = {
					scope:vassal_target = {
						NOT = { has_trait = blind }
					}
				}
				scope:vassal_target = {
					add_trait = blind
				}
			}
			1 = {
				trigger = {
					scope:vassal_target = {
						NOT = { has_trait = eunuch }
						is_male = yes
					}
				}
				scope:vassal_target = {
					add_trait = eunuch
				}
			}
			1 = {
				trigger = {
					scope:vassal_target = {
						NOT = { has_trait = maimed }
					}
				}
				scope:vassal_target = {
					add_trait = maimed
				}
			}
			1 = {
				trigger = {
					scope:vassal_target = {
						NOT = { has_trait = scarred }
					}
				}
				scope:vassal_target = {
					add_trait = scarred
				}
			}
		}
	}
	
	option = {
		name = intrigue_scheming.3053.a
		add_prestige = medium_prestige_loss
		reverse_add_opinion = {
			target = scope:liege_target
			modifier = disgusted_opinion
			opinion = medium_negative_opinion
		}
		reverse_add_opinion = {
			target = scope:vassal_target
			modifier = cruelty_opinion
			opinion = very_high_negative_opinion
		}
	}
}


##################################################
# Fabricate Bastardy
# 3060-369
#  by Petter Vilberg
##################################################

scripted_trigger intrigue_scheming_3061_heir_trigger = {
	# Basic qualifications.
	exists = father
	exists = mother
	exists = real_father
	save_temporary_scope_as = heir
	real_father = scope:target #You cannot steal someone else's bastardy
	father = {
		this = scope:target
		any_courtier_or_guest = {
			is_male = yes
			can_be_parent_of = scope:heir
		}
	}

	# Disqualifying traits.
	NOR = {
		has_trait = bastard
		has_trait = legitimized_bastard
		has_trait = child_of_concubine
		has_trait = wild_oat
		has_trait = twin # To reduce the complexity of the bastardry system, twins cannot be bastards.
	}

	# Don't hurt your own family.
	NOT = { is_close_or_extended_family_of = root }
	mother = {
		is_alive = yes
		NOT = { is_close_or_extended_family_of = root }
	}
}

scripted_trigger intrigue_scheming_3061_potential_other_father = {
	NOR = {
		#Being extremely thorough here to guarantee no infinite loops
		this = scope:target
		this = scope:heir
		this = scope:heir.father
		this = scope:heir.real_father
		this = scope:heir.mother
		this = root
	}
	is_male = yes
	can_be_parent_of = scope:heir
}

scripted_trigger intrigue_scheming_3061_target_trigger = {
	is_landed = yes
	save_temporary_scope_as = target
	exists = player_heir
	player_heir = {
		intrigue_scheming_3061_heir_trigger = yes	
	}
}

scripted_effect intrigue_scheming_3061_change_father_apply_secret_effect = {
	debug_log = "Begin Intrigue Scheming 3061 Scopes Logging. Target/Heir/Mother/Father/Real_Father/New_Real_Father/New_Father"
	debug_log_scopes = no
	scope:heir = {
		debug_log_scopes = no
		mother = {
			debug_log_scopes = no
		}
		father = {
			debug_log_scopes = no
		}
		real_father = {
			debug_log_scopes = no
		}
	}

	scope:heir = {
		hidden_effect = {
			set_real_father = scope:new_father
		}
		real_father = {
			debug_log_scopes = no
		}
		scope:new_father = {
			debug_log_scopes = no
		}
		debug_log "End Intrigue Schiming 3061 Scopes Logging."

		mother = {
			add_secret = {
				type = secret_disputed_heritage
				target = scope:heir
			}
			random_secret = {
				limit = {
					secret_type = secret_disputed_heritage
					secret_target = scope:heir
				}
				save_scope_as = secret
				reveal_to_without_events_effect = { CHARACTER = root }
				reveal_to_without_events_effect = { CHARACTER = scope:heir }
			}
		}
	}
}

scripted_effect intrigue_scheming_3061_failure_penalty_effect = {
}

intrigue_scheming.3061 = {
	type = character_event
	title = intrigue_scheming.3061.t
	desc = intrigue_scheming.3061.desc
	
	theme = intrigue_skulduggery_focus
	left_portrait = {
		character = scope:target
		animation = paranoia
	}
	right_portrait = {
		character = scope:new_father
		animation = worry
	}
	lower_left_portrait = scope:heir
	lower_right_portrait = scope:commoner_target
	
	trigger = {
		OR = {
			has_trait = schemer
			intrigue >= very_high_skill_rating
		}
		OR = {
			has_focus = intrigue_skulduggery_focus
			has_focus = intrigue_intimidation_focus
		}
		is_at_war = no
		NOT = {
			has_character_flag = had_event_intrigue_scheming_3061
		}
		OR = {
			any_relation = {
				type = rival
				intrigue_scheming_3061_target_trigger = yes
			}
			AND = {
				is_landed = yes
				any_neighboring_top_liege_realm_owner = {
					intrigue_scheming_3061_target_trigger = yes
				}
			}
			AND = {
				is_landed = yes
				any_neighboring_realm_same_rank_owner = {
					intrigue_scheming_3061_target_trigger = yes
				}
			}
			any_vassal = {
				is_powerful_vassal = yes
				intrigue_scheming_3061_target_trigger = yes
			}
		}
		scope:target = {
			OR = {
				any_vassal = {
					intrigue_scheming_3061_potential_other_father = yes
				}
				any_courtier_or_guest = {
					intrigue_scheming_3061_potential_other_father = yes
				}
			}
		}
	}

	weight_multiplier = {
		base = 1
		upweight_for_focus_modifier = { FOCUS = intrigue_skulduggery_focus }
	}

	immediate = {
		add_character_flag = {
			flag = had_event_intrigue_scheming_3061
			days = 3650
		}
		every_relation = {
			type = rival
			limit = {
				intrigue_scheming_3061_target_trigger = yes
			}
			add_to_temporary_list = potential_target
		}
		every_neighboring_top_liege_realm_owner = {
			limit = {
				intrigue_scheming_3061_target_trigger = yes
			}
			add_to_temporary_list = potential_target
		}
		every_neighboring_realm_same_rank_owner = {
			limit = {
				intrigue_scheming_3061_target_trigger = yes
			}
			add_to_temporary_list = potential_target
		}
		every_vassal = {
			limit = {
				is_powerful_vassal = yes
				intrigue_scheming_3061_target_trigger = yes
			}
			add_to_temporary_list = potential_target
		}
		random_in_list = {
			list = potential_target
			weight = {
				base = 1
				modifier = {
					add = 3
					has_relation_rival = root
				}
			}
			save_scope_as = target
			player_heir = {
				save_scope_as = heir
				if = {
					limit = {
						exists = mother
					}
					mother = {
						save_scope_as = mother
					}
				}
			}

			# Find someone to be pinned as the new father
			every_vassal = {
				limit = {
					intrigue_scheming_3061_potential_other_father = yes
				}
				add_to_temporary_list = potential_new_father
			}

			every_courtier_or_guest = {
				limit = {
					intrigue_scheming_3061_potential_other_father = yes
				}
				add_to_temporary_list = potential_new_father
			}

			random_in_list = {
				list = potential_new_father
				weight = {
					base = 1
					modifier = {
						add = 3
						is_landed = yes
					}
				}
				save_scope_as = new_father
			}
		}

		# Create a Peasant to be potential father target
		save_scope_as = template
		create_character = {
			location = root.capital_province
			template = servant_character
			gender = male
			save_scope_as = commoner_target
		}

		# Save target's Spymaster if they exist
		scope:target = {
			if = {
				limit = {
					exists = cp:councillor_spymaster
				}
				save_scope_as = other_spymaster
			}
		}
	}

	option = { # Fabricate yourself as the father
		name = intrigue_scheming.3061.c
		trigger = {
			is_male = yes
			can_be_parent_of = scope:heir
			OR = {
				has_trait = deceitful
				has_focus = intrigue_skulduggery_focus
				has_trait = schemer
			}
		}
		trait = deceitful
		if = {
			limit = {
				exists = scope:other_spymaster
			}
			duel = {
				target = scope:other_spymaster
				skill = intrigue
				12 = {		
					compare_modifier = {
						value = scope:duel_value
						multiplier = 0.5
					}
					desc = intrigue_scheming.3061.success
					custom_tooltip = intrigue_scheming.3061.c.success_tt
					add_intrigue_lifestyle_xp = medium_lifestyle_xp
					hidden_effect = {
						trigger_event = {
							id = intrigue_scheming.3066
							days = { 5 10 }
						}
					}
				}
				12 = {		
					compare_modifier = {
						value = scope:duel_value
						multiplier = -0.5
					}
					desc = intrigue_scheming.3061.failure
					show_as_tooltip = {
						add_prestige = medium_prestige_loss
						dynasty = { add_dynasty_prestige = medium_dynasty_prestige_loss }
						scope:target = {
							add_opinion = {
								target = root
								modifier = trust_opinion
								opinion = medium_negative_opinion
							}
						}
					}
					hidden_effect = {
						trigger_event = {
							id = intrigue_scheming.3067
							days = { 5 10 }
						}
					}
				}
			}
		}
		else = {
			duel = {
				target = scope:target
				skill = intrigue
				15 = {		
					compare_modifier = {
						value = scope:duel_value
						multiplier = 0.5
					}
					desc = intrigue_scheming.3061.success
					custom_tooltip = intrigue_scheming.3061.c.success_tt
					add_intrigue_lifestyle_xp = medium_lifestyle_xp
					hidden_effect = {
						trigger_event = {
							id = intrigue_scheming.3066
							days = { 5 10 }
						}
					}
				}
				15 = {		
					compare_modifier = {
						value = scope:duel_value
						multiplier = -0.5
					}
					desc = intrigue_scheming.3061.failure
					show_as_tooltip = {
						add_prestige = medium_prestige_loss
						dynasty = { add_dynasty_prestige = medium_dynasty_prestige_loss }
						scope:target = {
							add_opinion = {
								target = root
								modifier = trust_opinion
								opinion = medium_negative_opinion
							}
						}
					}
					hidden_effect = {
						trigger_event = {
							id = intrigue_scheming.3067
							days = { 5 10 }
						}
					}
				}
			}
		}
		stress_impact = {
			family_first = medium_stress_impact_gain
		}
		ai_chance = {
			base = 200
		}
	}

	option = { #Fabricate new_father as the father
		name = intrigue_scheming.3061.a
		if = {
			limit = {
				exists = scope:other_spymaster
			}
			duel = {
				target = scope:other_spymaster
				skill = intrigue
				15 = {		
					compare_modifier = {
						value = scope:duel_value
						multiplier = 0.5
					}
					desc = intrigue_scheming.3061.success
					custom_tooltip = intrigue_scheming.3061.a.success_tt
					add_intrigue_lifestyle_xp = medium_lifestyle_xp
					hidden_effect = {
						trigger_event = {
							id = intrigue_scheming.3062
							days = { 5 10 }
						}
					}
				}
				15 = {		
					compare_modifier = {
						value = scope:duel_value
						multiplier = -0.5
					}
					desc = intrigue_scheming.3061.failure
					show_as_tooltip = {
						add_prestige = medium_prestige_loss
						scope:target = {
							add_opinion = {
								target = root
								modifier = trust_opinion
								opinion = -30
							}
						}
					}
					hidden_effect = {
						trigger_event = {
							id = intrigue_scheming.3063
							days = { 5 10 }
						}
					}
				}
			}
		}
		else = {
			duel = {
				target = scope:target
				skill = intrigue
				15 = {		
					compare_modifier = {
						value = scope:duel_value
						multiplier = 0.5
					}
					desc = intrigue_scheming.3061.success
					custom_tooltip = intrigue_scheming.3061.a.success_tt
					add_intrigue_lifestyle_xp = medium_lifestyle_xp
					hidden_effect = {
						trigger_event = {
							id = intrigue_scheming.3062
							days = { 5 10 }
						}
					}
				}
				15 = {		
					compare_modifier = {
						value = scope:duel_value
						multiplier = -0.5
					}
					desc = intrigue_scheming.3061.failure
					show_as_tooltip = {
						add_prestige = medium_prestige_loss
						scope:target = {
							add_opinion = {
								target = root
								modifier = trust_opinion
								opinion = -30
							}
						}
					}
					hidden_effect = {
						trigger_event = {
							id = intrigue_scheming.3063
							days = { 5 10 }
						}
					}
				}
			}
		}
		stress_impact = {
			honest = medium_stress_impact_gain
			family_first = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
		}
	}

	option = { #Fabricate someone lowborn as the father
		name = intrigue_scheming.3061.b
		if = {
			limit = {
				exists = scope:other_spymaster
			}
			duel = {
				target = scope:other_spymaster
				skill = intrigue
				15 = {		
					compare_modifier = {
						value = scope:duel_value
						multiplier = 0.5
					}
					desc = intrigue_scheming.3061.success
					custom_tooltip = intrigue_scheming.3061.b.success_tt
					add_intrigue_lifestyle_xp = medium_lifestyle_xp
					hidden_effect = {
						trigger_event = {
							id = intrigue_scheming.3064
							days = { 5 10 }
						}
					}
				}
				15 = {		
					compare_modifier = {
						value = scope:duel_value
						multiplier = -0.5
					}
					desc = intrigue_scheming.3061.failure
					show_as_tooltip = {
						add_prestige = medium_prestige_loss
						scope:target = {
							add_opinion = {
								target = root
								modifier = trust_opinion
								opinion = -30
							}
						}
					}
					hidden_effect = {
						trigger_event = {
							id = intrigue_scheming.3065
							days = { 5 10 }
						}
					}
				}
			}
		}
		else = {
			duel = {
				target = scope:target
				skill = intrigue
				15 = {		
					compare_modifier = {
						value = scope:duel_value
						multiplier = 0.5
					}
					desc = intrigue_scheming.3061.success
					custom_tooltip = intrigue_scheming.3061.b.success_tt
					add_intrigue_lifestyle_xp = medium_lifestyle_xp
					hidden_effect = {
						trigger_event = {
							id = intrigue_scheming.3064
							days = { 5 10 }
						}
					}
				}
				15 = {		
					compare_modifier = {
						value = scope:duel_value
						multiplier = -0.5
					}
					desc = intrigue_scheming.3061.failure
					show_as_tooltip = {
						add_prestige = medium_prestige_loss
						scope:target = {
							add_opinion = {
								target = root
								modifier = trust_opinion
								opinion = -30
							}
						}
					}
					hidden_effect = {
						trigger_event = {
							id = intrigue_scheming.3065
							days = { 5 10 }
						}
					}
				}
			}
		}
		stress_impact = {
			honest = medium_stress_impact_gain
			family_first = medium_stress_impact_gain
		}
	}
	
	option = { #No thanks
		name = intrigue_scheming.3061.d
		dynasty = { add_dynasty_prestige = medium_dynasty_prestige_gain }
	}
}

#Fabricate new fatherhood success - new father
intrigue_scheming.3062 = {
	type = character_event
	title = intrigue_scheming.3061.t
	desc = {
		desc = intrigue_scheming.3062.opening
		desc = intrigue_scheming.3062.ending
	}
	
	theme = intrigue_skulduggery_focus
	left_portrait = {
		character = scope:target
		animation = paranoia
	}
	right_portrait = {
		character = scope:mother
		animation = worry
	}
	lower_left_portrait = scope:heir
	lower_right_portrait = scope:new_father
	
	immediate = {
		intrigue_scheming_3061_change_father_apply_secret_effect = yes
	}

	option = {
		name = intrigue_scheming.3062.a
		scope:secret = {
			expose_secret = root
		}
	}

	option = {
		name = intrigue_scheming.3062.b
		custom_tooltip = intrigue_scheming.3062.b.tt
	}
}


#Fabricate new fatherhood failure - new father
intrigue_scheming.3063 = {
	type = character_event
	title = intrigue_scheming.3061.t
	desc = {
		desc = intrigue_scheming.3063.opening
		desc = intrigue_scheming.3063.ending
	}
	
	theme = intrigue_skulduggery_focus
	left_portrait = {
		character = scope:target
		animation = anger
	}
	right_portrait = {
		character = scope:new_father
		animation = disbelief
	}
	lower_left_portrait = scope:heir
	
	option = {
		name = intrigue_scheming.3063.a
		add_prestige = medium_prestige_loss
		reverse_add_opinion = {
			target = scope:target
			modifier = trust_opinion
			opinion = -30
		}
		reverse_add_opinion = {
			target = scope:mother
			modifier = insult_opinion
			opinion = -20
		}
	}
}

#Fabricate new fatherhood success - commoner
intrigue_scheming.3064 = {
	type = character_event
	title = intrigue_scheming.3061.t
	desc = {
		desc = intrigue_scheming.3062.opening
		desc = intrigue_scheming.3064.ending
	}
	
	theme = intrigue_skulduggery_focus
	left_portrait = {
		character = scope:target
		animation = rage
	}
	right_portrait = {
		character = scope:mother
		animation = shock
	}
	lower_left_portrait = scope:heir
	lower_right_portrait = scope:commoner_target
	
	immediate = {
		intrigue_scheming_3061_change_father_apply_secret_effect = yes
	}

	option = {
		name = intrigue_scheming.3062.a
		scope:secret = {
			expose_secret = root
		}
	}

	option = {
		name = intrigue_scheming.3062.b
		custom_tooltip = intrigue_scheming.3062.b.tt
	}
}


#Fabricate new fatherhood failure - commoner
intrigue_scheming.3065 = {
	type = character_event
	title = intrigue_scheming.3061.t
	desc = {
		desc = intrigue_scheming.3065.opening
		desc = intrigue_scheming.3063.ending
	}
	
	theme = intrigue_skulduggery_focus
	left_portrait = {
		character = scope:target
		animation = anger
	}
	lower_left_portrait = scope:heir
	right_portrait = {
		character = scope:mother
		animation = disbelief
	}
	lower_right_portrait = scope:commoner_target
	
	option = {
		name = intrigue_scheming.3063.a
		add_prestige = medium_prestige_loss
		add_prestige = medium_prestige_loss
		reverse_add_opinion = {
			target = scope:target
			modifier = trust_opinion
			opinion = -30
		}
		reverse_add_opinion = {
			target = scope:mother
			modifier = insult_opinion
			opinion = -20
		}
	}
}

#Fabricate new fatherhood success - me
intrigue_scheming.3066 = {
	type = character_event
	title = intrigue_scheming.3061.t
	desc = intrigue_scheming.3066.desc
	
	theme = intrigue_skulduggery_focus
	left_portrait = {
		character = scope:target
		animation = rage
	}
	lower_left_portrait = scope:heir
	right_portrait = {
		character = scope:mother
		animation = shock
	}

	
	immediate = {
		intrigue_scheming_3061_change_father_apply_secret_effect = yes
	}

	option = {
		name = intrigue_scheming.3066.a
		scope:secret = {
			expose_secret = root
		}
	}

	option = {
		name = intrigue_scheming.3066.b
		custom_tooltip = intrigue_scheming.3062.b.tt
	}
}


#Fabricate new fatherhood failure - me
intrigue_scheming.3067 = {
	type = character_event
	title = intrigue_scheming.3061.t
	desc = {
		desc = intrigue_scheming.3067.opening
		desc = intrigue_scheming.3063.ending
	}
	
	theme = intrigue_skulduggery_focus
	left_portrait = {
		character = scope:target
		animation = anger
	}
	right_portrait = {
		character = scope:mother
		animation = disbelief
	}

	immediate = {
		progress_towards_rival_effect = {
			CHARACTER = scope:mother
			OPINION = no
		}
	}
	
	option = {
		name = intrigue_scheming.3067.a
		add_prestige = medium_prestige_loss
		if = {
			limit = { exists = dynasty }
			dynasty = { add_dynasty_prestige = minor_dynasty_prestige_loss }
		}
		reverse_add_opinion = {
			target = scope:target
			modifier = trust_opinion
			opinion = -40
		}
		reverse_add_opinion = {
			target = scope:mother
			modifier = insult_opinion
			opinion = -30
		}
	}
}

##################################################
# Interrogation
# by Sean Hughes
# 4021-4027
##################################################

scripted_trigger intrigue_scheming_4021_has_own_secret = {
	save_temporary_scope_as = prisoner
	any_secret = {
		NOT = {
			is_known_by = root
		}
		secret_owner = scope:prisoner
	}
}
scripted_trigger intrigue_scheming_4021_knows_other_secret = {
	save_temporary_scope_as = prisoner
	any_secret = {
		NOR = {
			is_known_by = root
			secret_owner = scope:prisoner
		}
	}
}

#Decide how you want to approach learning the secret.
intrigue_scheming.4021 = {
	type = character_event
	title = intrigue_scheming.4021.t
	desc = intrigue_scheming.4021.desc
	
	theme = intrigue_skulduggery_focus
	left_portrait = {
		character = scope:prisoner
		animation = fear
	}
	
	#Requires a prisoner with a secret you don't know.
	trigger = {
		NOT = { has_character_flag = had_event_intrigue_scheming_4021 }
		any_prisoner = {
			is_ai = yes
			is_adult = yes
			OR = {
				intrigue_scheming_4021_has_own_secret = yes
				intrigue_scheming_4021_knows_other_secret = yes
			}
		}
	}

	weight_multiplier = {
		base = 0.20

		#More likely to occur if the prisoner knows a secret which isn't their own.
		modifier = {
			any_prisoner = {
				intrigue_scheming_4021_knows_other_secret = yes
			}
			factor = 5
		}
		downweight_for_focus_modifier = { FOCUS = intrigue_temptation_focus }
	}

	immediate = {
		add_character_flag = {
			flag = had_event_intrigue_scheming_4021
			years = 5
		}
		random_prisoner = {
			limit = {
				is_ai = yes
				is_adult = yes
				OR = {
					intrigue_scheming_4021_has_own_secret = yes
					intrigue_scheming_4021_knows_other_secret = yes
				}
			}

			weight = {
				base = 100
			
				modifier = {
					intrigue_scheming_4021_knows_other_secret = yes
					factor = 5
				}
			}

			save_scope_as = prisoner
		}

		scope:prisoner = {
			random_secret = {
				limit = {
					NOR = {
						is_known_by = root
						secret_owner = scope:prisoner
					}
				}
				alternative_limit = {
					NOT = {
						is_known_by = root
					}
				}

				save_scope_as = target_secret
			}
		}
	}

	#Offer release in exchange for the secret.
	option = {
		name = intrigue_scheming.4021.a

		stress_impact = {
			sadistic = medium_stress_impact_gain
			callous = minor_stress_impact_gain
			deceitful = minor_stress_impact_gain
		}

		duel = {
			skill = diplomacy
			target = scope:prisoner

			60 = {
				desc = intrigue_scheming.4021.a.success

				#More likely if you are persuasive
				compare_modifier = {
					value = scope:duel_value
					multiplier = 5
					min = -59
				}

				#More likely to accept deal based on varying personalities.
				compare_modifier = { # Will not betray another.
					trigger = {
						scope:target_secret = {
							NOT = { secret_owner = scope:prisoner }
						}
					}
					value = scope:prisoner.ai_honor
					multiplier = -0.2
				}
				compare_modifier = { # Will sell out someone for their own gain.
					trigger = {
						scope:target_secret = {
							NOT = { secret_owner = scope:prisoner }
						}
					}
					value = scope:prisoner.ai_greed
					multiplier = 0.5
				}
				compare_modifier = { # Let's be honest, it's a good deal.
					trigger = {
						scope:target_secret = {
							NOT = { secret_owner = scope:prisoner }
						}
					}
					value = scope:prisoner.ai_rationality
					multiplier = 0.25
				}

				# Reveal the secret
				show_as_tooltip = {
					custom_tooltip = intrigue_scheming.4021.success
					add_intrigue_lifestyle_xp = medium_lifestyle_xp
					scope:prisoner = {
						release_from_prison = yes
					}
				}
				hidden_effect = {
					send_interface_toast = {
						title = intrigue_scheming.4021.a.success
						left_icon = scope:prisoner
						scope:target_secret = {
							reveal_to = root
						}
						add_intrigue_lifestyle_xp = medium_lifestyle_xp
						scope:prisoner = {
							release_from_prison = yes
						}
						
					}
				}
			}
			40 = {
				desc = intrigue_scheming.4021.a.failure

				# Less likely to accept is Secret is:
				modifier = { # Own Secret (Could be Blackmailed).
					scope:target_secret = {
						secret_owner = scope:prisoner
					}
					factor = 1.5
				}
				modifier = { # Own Secret which is Criminal (More valuable Blackmail.)
					scope:target_secret = {
						secret_owner = scope:prisoner
						is_criminal_for = scope:prisoner
					}
					factor = 2 # x3 total
				}
				modifier = {
					AND = { # Own Secret which is Criminal and Root is Liege (i.e., you could re-imprison them if you found out!)
						exists = scope:prisoner.liege
						scope:prisoner.liege = root
						scope:target_secret = {
							secret_owner = scope:prisoner
							is_criminal_for = scope:prisoner
						}
					}
					factor = 3 # x9 total
				}	

				#Inform the player that they failed to learn the secret.
				send_interface_toast = {
					title = intrigue_scheming.4021.a.failure
					left_icon = scope:prisoner
					custom_tooltip = intrigue_scheming.4021.failure
				}
			}
		}

		ai_chance = {
			base = 100

			ai_value_modifier = {
				ai_compassion = 100
				ai_greed = -100
			}
		}		
	}

	#Trick them into revealing the secret.
	option = {
		name = intrigue_scheming.4021.b

		stress_impact = {
			honest = medium_stress_impact_gain
			just = minor_stress_impact_gain
			compassionate = minor_stress_impact_gain
		}

		duel = {
			skill = intrigue
			target = scope:prisoner
			50 = {
				desc = intrigue_scheming.4021.b.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				modifier = {					
					add = 10
					has_trait = schemer
				}
				# Reveal the secret
				show_as_tooltip = {
					custom_tooltip = intrigue_scheming.4021.success
					add_intrigue_lifestyle_xp = medium_lifestyle_xp
				}
				hidden_effect = {
					send_interface_toast = {
						title = intrigue_scheming.4021.b.success
						left_icon = scope:prisoner
						scope:target_secret = {
							reveal_to = root
						}
						add_intrigue_lifestyle_xp = medium_lifestyle_xp					
					}
				}
			}
			50 = {
				desc = intrigue_scheming.4021.b.failure

				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}

				modifier = {
					add = 10
					scope:prisoner = {
						has_trait = intellect_good_1
					}
				}
				modifier = {
					add = 20
					scope:prisoner = {
						has_trait = intellect_good_2
					}
				}
				modifier = {
					add = 30
					scope:prisoner = {
						has_trait = intellect_good_3
					}
				}

				#Inform the player that they failed to learn the secret.
				send_interface_toast = {
					title = intrigue_scheming.4021.b.failure
					left_icon = scope:prisoner
					custom_tooltip = intrigue_scheming.4021.failure
				}
			}
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = -100
				ai_greed = 50
			}
		}
	}
	
	#Torture them into revealing the secret.
	option = {
		name = intrigue_scheming.4021.c

		stress_impact = {
			compassionate = medium_stress_impact_gain
			forgiving = minor_stress_impact_gain
			generous = minor_stress_impact_gain
		}

		random_list = {
			40 = {
				desc = intrigue_scheming.4021.c.success

				# Lifestyle Trait Bonus
				modifier = {
					add = 5
					has_trait = torturer
				}

				#Personality Trait Bonuses
				modifier = {
					add = 40
					has_trait = sadistic
				}
				modifier = {
					add = 20
					has_trait = callous
				}
				modifier = {
					add = 10
					has_trait = vengeful
				}
				modifier = {
					add = 10
					has_trait = arrogant
				}
				modifier = {
					add = 10
					has_trait = arbitrary
				}
				modifier = {
					add = 10
					has_trait = greedy
				}
				modifier = {
					add = 10
					has_trait = wrathful
				}

				# Reveal the secret
				show_as_tooltip = {
					custom_tooltip = intrigue_scheming.4021.success
					add_intrigue_lifestyle_xp = medium_lifestyle_xp
				}
				hidden_effect = {
					send_interface_toast = {
						title = intrigue_scheming.4021.c.success
						left_icon = scope:prisoner
						scope:target_secret = {
							reveal_to = root
						}
						add_intrigue_lifestyle_xp = medium_lifestyle_xp				
					}
				}				
			}
			120 = {
				desc = intrigue_scheming.4021.c.failure

				modifier = { # Characters who aren't inherently bold (or whose boldness is reduced by your Dread) are less likely to refuse.
					add = -40
 					dread_modified_ai_boldness = {
						dreaded_character = root
							value <= 0
						}
				}
				modifier = { # Intimidated characters even less likely to refuse.
					add = -40
 					dread_modified_ai_boldness = {
						dreaded_character = root
							value <= -40
						}
				}
				modifier = { # Cowed characters will never refuse
					add = -40
 					dread_modified_ai_boldness = {
						dreaded_character = root
							value <= -40
						}
				}

				# Personality Trait Penalties (ROOT's Personality)
				modifier = {
					add = 10
					has_trait = generous
				}
				modifier = {
					add = 20
					has_trait = forgiving
				}
				modifier = {
					add = 40
					has_trait = compassionate
				}

				#Inform the player that they failed to learn the secret.
				send_interface_toast = {
					title = intrigue_scheming.4021.c.failure
					left_icon = scope:prisoner
					custom_tooltip = intrigue_scheming.4021.failure
				}
			}
		}
		
		ai_chance = {
			base = 50

			modifier = {
				add = 25
				dread > 20
			}
			modifier = {
				add = 50
				dread > 50
			}
			modifier = {
				add = 100
				dread > 80
			}

			ai_value_modifier = {
				ai_compassion = -200
				ai_vengefulness = 100
			}
		}
	}
}


##################################################
# Passing Suspicion
# by Sean Hughes
# 4040
##################################################

scripted_trigger intrigue_scheming_4040_is_unrelated_to_char = {
	is_available_ai_adult = yes
	NOR = {
		this = $CHAR$
		has_relation_rival = $CHAR$
		has_relation_friend = $CHAR$
		has_relation_lover = $CHAR$
	}
}

intrigue_scheming.4040 = {
	type = character_event
	title = intrigue_scheming.4040.t
	desc = intrigue_scheming.4040.desc
	
	theme = intrigue_skulduggery_focus
	left_portrait = {
		character = scope:courtier_1
		animation = paranoia
	}
	lower_left_portrait = scope:courtier_2
	lower_center_portrait = scope:courtier_3
	
	trigger = {
		NOT = { has_character_flag = had_event_intrigue_scheming_4040 }
		#Get the first courtier.
		any_courtier_or_guest = {
			is_available_ai_adult = yes
			save_temporary_scope_as = courtier_1
		}
		#Get our second courtier.
		any_courtier_or_guest = {
			is_available_ai_adult = yes

			#Not courtier 1 and has no significant relationship with courtier 1.
			intrigue_scheming_4040_is_unrelated_to_char = { CHAR = scope:courtier_1 }
			

			save_temporary_scope_as = courtier_2
		}
		#Get our third courtier.
		any_courtier_or_guest = {
			is_available_ai_adult = yes

			#Not courtiers 1 or 2, or has significant relationships with courtiers 1 or 2.
			AND = {
				intrigue_scheming_4040_is_unrelated_to_char = { CHAR = scope:courtier_1 }
				intrigue_scheming_4040_is_unrelated_to_char = { CHAR = scope:courtier_2 }
			}
		}
	}

	weight_multiplier = {
		base = 1
		upweight_for_focus_modifier = { FOCUS = intrigue_skulduggery_focus }
	}

	immediate = {
		add_character_flag = {
			flag = had_event_intrigue_scheming_4040
			years = 5
		}
		random_courtier_or_guest = {
			limit = {
				is_available_ai_adult = yes

				#Ensure a 2nd and 3rd courtier exist, both of which have no relationship with each other or a relationship with this courtier.
				save_temporary_scope_as = courtier_1
				root = {
					any_courtier_or_guest = {
						intrigue_scheming_4040_is_unrelated_to_char = { CHAR = scope:courtier_1 }
						save_temporary_scope_as = courtier_2
					}
					any_courtier_or_guest = {
						intrigue_scheming_4040_is_unrelated_to_char = { CHAR = scope:courtier_1 }
						intrigue_scheming_4040_is_unrelated_to_char = { CHAR = scope:courtier_2 }
					}
				}
			}
			weight = {
				base = 1
				modifier = {
					is_councillor_of = root
					add = 10
				}
				modifier = {
					exists = father
					father = {
						is_powerful_vassal = yes
						liege = root
					}
					add = 10
				}
				modifier = {
					exists = mother
					mother = {
						is_powerful_vassal = yes
						liege = root
					}
					add = 10
				}
			}

			save_scope_as = courtier_1
		}
		random_courtier_or_guest = {
			limit = {
				is_available_ai_adult = yes

				#Not courtier 1 and has no significant relationship with courtier 1.
				intrigue_scheming_4040_is_unrelated_to_char = { CHAR = scope:courtier_1 }

				#Ensure that a 3rd courtier exists which does not have a relationship with these first 2 courtiers.
				save_temporary_scope_as = courtier_2
				root = {
					any_courtier_or_guest = {
						intrigue_scheming_4040_is_unrelated_to_char = { CHAR = scope:courtier_1 }
						intrigue_scheming_4040_is_unrelated_to_char = { CHAR = scope:courtier_2 }
					}
				}
			}
			weight = {
				base = 1
				modifier = {
					is_councillor_of = root
					add = 10
				}
				modifier = {
					exists = father
					father = {
						is_powerful_vassal = yes
						liege = root
					}
					add = 10
				}
				modifier = {
					exists = mother
					mother = {
						is_powerful_vassal = yes
						liege = root
					}
					add = 10
				}
			}
			save_scope_as = courtier_2
		}
		random_courtier_or_guest = {
			limit = {
				is_available_ai_adult = yes

				#Not courtiers 1 or 2, or has significant relationships with courtiers 1 or 2.
				AND = {
					intrigue_scheming_4040_is_unrelated_to_char = { CHAR = scope:courtier_1 }
					intrigue_scheming_4040_is_unrelated_to_char = { CHAR = scope:courtier_2 }
				}
			}
			weight = {
				base = 1
				modifier = {
					is_councillor_of = root
					add = 10
				}
				modifier = {
					exists = father
					father = {
						is_powerful_vassal = yes
						liege = root
					}
					add = 10
				}
				modifier = {
					exists = mother
					mother = {
						is_powerful_vassal = yes
						liege = root
					}
					add = 10
				}
			}
			save_scope_as = courtier_3
		}
	}

	option = {
		name = intrigue_scheming.4040.a
		duel = {
			skill = intrigue
			value = {
				add = scope:courtier_1.intrigue
				add = scope:courtier_2.intrigue
				add = scope:courtier_3.intrigue
				multiply = 0.33
			}

			50 = {
				desc = intrigue_scheming.4040.a.success

				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				modifier = {
					has_trait = deceitful
					add = 10
				}

				send_interface_toast = {
					title = intrigue_scheming.4040.a.success

					#Custom tooltip here is for shortening the effects from this event option.
					#The event localization has '40' written in it, so if you change the below values make sure to update the localisation!
					custom_tooltip = intrigue_scheming.4040.a.success.tt
					hidden_effect = {
						scope:courtier_1 = {
							add_opinion = {
								modifier = suspicion_opinion
								target = scope:courtier_2
								opinion = medium_negative_opinion
							}
							add_opinion = {
								modifier = suspicion_opinion
								target = scope:courtier_3
								opinion = medium_negative_opinion
							}
						}
						scope:courtier_2 = {
							add_opinion = {
								modifier = suspicion_opinion
								target = scope:courtier_1
								opinion = medium_negative_opinion
							}
							add_opinion = {
								modifier = suspicion_opinion
								target = scope:courtier_3
								opinion = medium_negative_opinion
							}
						}
						scope:courtier_3 = {
							add_opinion = {
								modifier = suspicion_opinion
								target = scope:courtier_1
								opinion = medium_negative_opinion
							}
							add_opinion = {
								modifier = suspicion_opinion
								target = scope:courtier_2
								opinion = medium_negative_opinion
							}
						}
					}
					add_intrigue_lifestyle_xp = medium_lifestyle_xp
				}
			}
			50 = {
				desc = intrigue_scheming.4040.a.failure

				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				modifier = {
					has_trait = honest
					add = 10
				}

				compare_modifier = {
					value = scope:courtier_1.intrigue
					multiplier = 0.5
				}
				compare_modifier = {
					value = scope:courtier_2.intrigue
					multiplier = 0.5
				}
				compare_modifier = {
					value = scope:courtier_3.intrigue
					multiplier = 0.5
				}

				send_interface_toast = {
					title = intrigue_scheming.4040.a.failure
					add_prestige = minor_prestige_loss
				}
			}
		}
	}

	option = {
		name = intrigue_scheming.4040.b
		add_character_modifier = {
			modifier = intrigue_court_spies_modifier
			years = 5
		}
	}
	
	option = {
		name = intrigue_scheming.4040.c.dread
		trigger = {
			dread >= medium_dread
		}

		flavor = intrigue_scheming.4040.c.dread.tt
		add_prestige = major_prestige_gain
		add_intrigue_lifestyle_xp = minor_lifestyle_xp
	}
}

##################################################
# Information Brokering
# by Sean Hughes
# 4050-4054
##################################################

scripted_trigger intrigue_scheming_4050_valid_secret_buyer = {
	exists = $SECRET$

	#We're not selling secrets to children.
	is_adult = yes
	is_alive = yes
	
	#Ensure the potential buyer does not already know the secret.
	$SECRET$ = {
		NOT = { is_known_by = prev }
	}
	#Ensure the potential buyer is neither the seller, the secret owner, or (in the case of taboo relationships) the secret target.
	NOR = {
		this = root
		this = $SECRET$.secret_owner
		AND = {
			$SECRET$ = {
				OR = {
					secret_type = secret_disputed_heritage
					secret_type = secret_unmarried_illegitimate_child
					secret_type = secret_lover
				}
			}
			AND = {
				exists = $SECRET$.secret_target
				this = $SECRET$.secret_target
			}
		}
	}
}

scripted_trigger intrigue_scheming_4050_sellable_murder_secret = {
	# Only murder secrets.
	OR = {
		secret_type = secret_murder
		secret_type = secret_murder_attempt
	}

	# We must not be the secret owner.
	NOT = { secret_owner = root }

	# Secret target must exist and not be us.
	exists = secret_target
	NOT = { secret_target = root }

	save_temporary_scope_as = potential_secret
	secret_target = {
		any_close_or_extended_family_member = {
			intrigue_scheming_4050_valid_secret_buyer = { SECRET = scope:potential_secret }
		}
	}
}

scripted_trigger intrigue_scheming_4050_sellable_bastard_secret = {
	# Only bastardry secrets.
	OR = {
		secret_type = secret_disputed_heritage
		secret_type = secret_unmarried_illegitimate_child
	}

	# We must not be the secret owner.
	NOT = { secret_owner = root }

	# Secret target must exist and not be us.
	exists = secret_target
	NOT = { secret_target = root }

	save_temporary_scope_as = potential_secret
	secret_owner = {
		OR = {
			any_close_or_extended_family_member = {
				intrigue_scheming_4050_valid_secret_buyer = { SECRET = scope:potential_secret }
			}
			any_spouse = {
				intrigue_scheming_4050_valid_secret_buyer = { SECRET = scope:potential_secret }
			}
		}
	}
}

scripted_trigger intrigue_scheming_4050_sellable_relationship_secret = {
	# Only lover secrets
	secret_type = secret_lover

	# We must not be the secret owner.
	NOT = { secret_owner = root }

	# Secret target must exist and not be us.
	exists = secret_target
	NOT = { secret_target = root }

	save_temporary_scope_as = potential_secret
	secret_owner = {
		OR = {
			any_close_or_extended_family_member = {
				intrigue_scheming_4050_valid_secret_buyer = { SECRET = scope:potential_secret }
			}
			any_spouse = {
				intrigue_scheming_4050_valid_secret_buyer = { SECRET = scope:potential_secret }
			}
		}
	}
}

intrigue_scheming.4050 = {
	type = character_event
	title = intrigue_scheming.4050.t
	desc = {
		desc = intrigue_scheming.4050.desc.start
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:secret = {
						secret_type = secret_lover
					}
					scope:target = { is_close_family_of = scope:owner }

				}
				desc = intrigue_scheming.4050.desc.incest
			}
			triggered_desc = {
				trigger = {
					scope:secret = {
						secret_type = secret_lover
					}
					NOT = { scope:target = { is_close_family_of = scope:owner } }
				}
				desc = intrigue_scheming.4050.desc.lover
			}
			triggered_desc = {
				trigger = {
					scope:secret = {
						secret_type = secret_disputed_heritage
						secret_type = secret_unmarried_illegitimate_child
					}
				}
				desc = intrigue_scheming.4050.desc.bastard
			}
			triggered_desc = {
				trigger = {
					scope:secret = {
						secret_type = secret_murder_attempt
						NOT = { secret_target = scope:buyer }
					}
				}
				desc = intrigue_scheming.4050.desc.murderattempt
			}
			triggered_desc = {
				trigger = {
					scope:secret = {
						secret_type = secret_murder_attempt
						secret_target = scope:buyer
					}
				}
				desc = intrigue_scheming.4050.desc.murderattemptself
			}
			triggered_desc = {
				trigger = {
					scope:secret = {
						secret_type = secret_murder
					}
				}
				desc = intrigue_scheming.4050.desc.murder
			}
		}
		desc = intrigue_scheming.4050.desc.end
	}
	
	theme = intrigue_skulduggery_focus
	left_portrait = {
		character = scope:buyer
		animation = personality_greedy
	}
	right_portrait = {
		character = scope:owner
		animation = worry
	}
	lower_right_portrait = scope:target
	
	trigger = {
		NOT = { has_character_flag = had_event_intrigue_scheming_4050 }
		any_known_secret = {
			OR = {
				AND = {
					intrigue_scheming_4050_sellable_murder_secret = yes # Saves the potential secret scope.
					secret_target = {
						any_close_or_extended_family_member = {
							intrigue_scheming_4050_valid_secret_buyer = { SECRET = scope:potential_secret }
						}
					}
				}
				AND = {
					OR = {
						intrigue_scheming_4050_sellable_bastard_secret = yes # Saves the potential secret scope.
						intrigue_scheming_4050_sellable_relationship_secret = yes # Saves the potential secret scope.
					}
					secret_owner = {
						any_close_or_extended_family_member = {
							intrigue_scheming_4050_valid_secret_buyer = { SECRET = scope:potential_secret }
						}
					}
				}
			}
		}
	}

	weight_multiplier = {
		base = 1
		upweight_for_focus_modifier = { FOCUS = intrigue_skulduggery_focus }
	}

	immediate = {
		add_character_flag = {
			flag = had_event_intrigue_scheming_4050
			years = 5
		}
		root = {
			save_scope_as = seller
		}
		random_known_secret = {
			limit = {
				#Ensure we have a valid secret buyer.
				OR = {
					AND = {
						always = yes
						intrigue_scheming_4050_sellable_murder_secret = yes # Saves the potential secret scope.
						secret_target = {
							any_close_or_extended_family_member = {
								intrigue_scheming_4050_valid_secret_buyer = { SECRET = scope:potential_secret }
							}
						}
					}
					AND = {
						OR = {
							intrigue_scheming_4050_sellable_bastard_secret = yes # Saves the potential secret scope.
							intrigue_scheming_4050_sellable_relationship_secret = yes # Saves the potential secret scope.
						}
						secret_owner = {
							any_close_or_extended_family_member = {
								intrigue_scheming_4050_valid_secret_buyer = { SECRET = scope:potential_secret }
							}
						}
					}
				}
				#Ensure we have a valid secret target (While some secrets have no targets, all the types we're looking for do, and we want to ensure they are valid!)
				exists = secret_target
			}
			save_scope_as = secret

			#Saving the owner/target scopes for loc and portraits.
			secret_owner = {
				save_scope_as = owner
			}
			secret_target = {
				save_scope_as = target
			}

			# Compile a list of potential secret buyers.
			if = {
				limit = {
					secret_target = { intrigue_scheming_4050_valid_secret_buyer = { SECRET = scope:secret } }
				}
				secret_target = {
					add_to_list = potential_secret_buyers
				}
			}
			secret_target = {
				every_close_or_extended_family_member = {
					limit = {
						intrigue_scheming_4050_valid_secret_buyer = { SECRET = scope:secret }
					}
					add_to_list = potential_secret_buyers
				}
			}
			secret_owner = {
				every_close_or_extended_family_member = {
					limit = {
						intrigue_scheming_4050_valid_secret_buyer = { SECRET = scope:secret }
					}
					add_to_list = potential_secret_buyers
				}
				every_spouse = {
					limit = {
						intrigue_scheming_4050_valid_secret_buyer = { SECRET = scope:secret }
					}
					add_to_list = potential_secret_buyers
				}
				every_relation = {
					type = rival
					limit = {
						intrigue_scheming_4050_valid_secret_buyer = { SECRET = scope:secret }
					}
					add_to_list = potential_secret_buyers
				}
				every_vassal = {
					limit = {
						intrigue_scheming_4050_valid_secret_buyer = { SECRET = scope:secret }
						highest_held_title_tier >= tier_county # We don't want to bother selling secrets to mere barons!
					}
					add_to_list = potential_secret_buyers
				}
				liege = {
					if = {
						limit = {
							intrigue_scheming_4050_valid_secret_buyer = { SECRET = scope:secret }
						}
						add_to_list = potential_secret_buyers
					}
				}
			}

			ordered_in_list = {
				list = potential_secret_buyers

				order_by = {
					value = 0

					# Strong preference for secret buyers who can actually afford to buy the secret!
					if = {
						limit = {
							OR = {
								AND = {
									is_ai = yes
									short_term_gold >= major_gold_value_check
								}
								AND = {
									is_ai = no
									gold >= major_gold_value_check
								}
							}
						}
						add = major_gold_value_check
					}
					else = {
						if = {
							limit = {
								is_ai = yes
							}
							add = short_term_gold
						}
						else = {
							add = gold
						}
					}

					# Players get priority on buying the secret.
					if = {
						limit = {
							is_ai = no
						}
						add = 100
					}

					# Targets of murder plots get priority on buying the secret (drama reasons!)
					if = {
						limit = {
							scope:secret = {
								intrigue_scheming_4050_sellable_murder_secret = yes
							}
							this = scope:target
						}
						add = 50
					}

					# Spouses get priority on buying illicit relationship secrets.
					if = {
						limit = {
							scope:secret = {
								intrigue_scheming_4050_sellable_relationship_secret = yes
							}
							OR = {
								is_spouse_of = scope:owner
								is_spouse_of = scope:target
							}
						}
						add = 50
					}

					# House heads get priority on buying bastardry secrets.
					if = {
						limit = {
							scope:secret = {
								intrigue_scheming_4050_sellable_bastard_secret = yes
							}
							this = scope:owner.house.house_head
						}
						add = 50
					}


					# Parents of the secret target and/or owner get smaller priority bonus for buying the secret.
					if = {
						limit = {
							OR = {
								this = scope:secret.secret_target.father
								this = scope:secret.secret_target.mother
								this = scope:secret.secret_owner.father
								this = scope:secret.secret_owner.mother
							}
						}
						add = 25
					}
					# Children get a smaller priority bonus for buying the secret.
					if = {
						limit = {
							OR = {
								is_child_of = scope:secret.secret_target
								is_child_of = scope:secret.secret_owner
							}
						}
						add = 25
					}

					# More powerful characters get priority for buying the secret.
					add = {
						value = highest_held_title_tier
						subtract = 1 # We're not including barons
						min = 0 # but we don't want to penalize unlanded
						multiply = 50 # Counts = 50, Emperors = 200
					}
				}

				save_scope_as = buyer
			}
		}

		scope:buyer = {
			if = {
				limit = {
					OR = {
						is_ai = no
						short_term_gold >= major_gold_value_check
					}
				}
				save_scope_value_as = {
					name = saved_gold_amount
					value = major_gold_value_check
				}
			}
			else = {
				save_scope_value_as = {
					name = saved_gold_amount
					value = short_term_gold
				}
			}
		}
	}

	#Sell the secret for cold hard cash.
	option = {
		name = intrigue_scheming.4050.a

		#Displays a chance-less outcome list if the secret buyer is a player, since we cannot predict their responses.
		if = {
			limit = {
				scope:buyer = {
					is_ai = no
				}
			}
			intrigue_scheming_4050_display_player_response_effect = {
				PAYMENT = flag:gold
			}
		}
		#Displays the likelyhood of the AI accepting this offer if the player proposes it.
		else = {
			random_list = {
				70 = {
					desc = intrigue_scheming.4050.success
					save_scope_value_as = {
						name = payment
						value = flag:gold
					}
					show_as_tooltip = {
						scope:buyer = {
							pay_short_term_gold = {
								target = scope:seller
								gold = scope:saved_gold_amount
							}
							add_intrigue_lifestyle_xp = major_lifestyle_xp
						}
						scope:secret = {
							reveal_to = scope:buyer
						}
						hidden_effect = { add_focus_progress = standard_lifestyle_focus_progress }
					}
					trigger_event = {
						id = intrigue_scheming.4052
						days = { 5 7 }
					}

					compare_modifier = {
						value = scope:buyer.ai_greed
						multiplier = -0.5
						max = 0
					}
					compare_modifier = {
						value = scope:buyer.ai_rationality
						multiplier = 0.5
					}
					compare_modifier = {
						value = scope:buyer.ai_vengefulness
						multiplier = 0.25
					}
					compare_modifier = {
						value = scope:buyer.ai_zeal
						multiplier = 0.25
					}
					
					modifier = {
						scope:buyer = {
							has_trait = paranoid
						}
						factor = 2
					}
				}
				30 = {
					intrigue_scheming_4050_offer_refused_effect = yes
					desc = intrigue_scheming.4050.failure
					modifier = {
						scope:buyer = {
							has_trait = trusting
						}
						factor = 0.5
					}
				}
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 1
				ai_rationality = -0.5
			}

			modifier = {
				gold <= minor_gold_value
				add = 40
			}
			modifier = {
				gold <= medium_gold_value
				add = 50
			}
			modifier = {
				gold <= major_gold_value
				add = 60
			}
		}
	}

	#Exchange the secret for another secret.
	option = {
		name = intrigue_scheming.4050.b
		trigger = {
			scope:buyer = {
				any_known_secret = {
					NOT = { is_known_by = root }
				}
			}
		}

		scope:buyer = {
			random_known_secret = {
				limit = {
					NOR = {
						is_known_by = root
						secret_owner = scope:buyer # The AI won't sell their own secret!
					}
					is_criminal_for = secret_owner

				}
				alternative_limit = {
					NOR = {
						is_known_by = root
						secret_owner = scope:buyer # The AI won't sell their own secret!
					}
				}
				save_scope_as = payment_secret
			}
		}

		#Displays a chance-less outcome list if the secret buyer is a player, since we cannot predict their responses.
		if = {
			limit = {
				scope:buyer = {
					is_ai = no
				}
			}
			intrigue_scheming_4050_display_player_response_effect = {
				PAYMENT = flag:secret
			}
		}
		#Displays the likelyhood of the AI accepting this offer if the player proposes it.
		else = {
			random_list = {
				75 = {
					desc = intrigue_scheming.4050.success
					save_scope_value_as = {
						name = payment
						value = flag:secret
					}
					show_as_tooltip = {
						custom_tooltip = intrigue_scheming.4050.b.tt
						scope:secret = {
							reveal_to = scope:buyer
						}
						add_intrigue_lifestyle_xp = major_lifestyle_xp
					}
					trigger_event = {
						id = intrigue_scheming.4052
						days = { 5 7 }
					}

					compare_modifier = {
						value = scope:buyer.ai_rationality
						multiplier = 1
					}
					compare_modifier = {
						value = scope:buyer.ai_honor
						multiplier = -0.5
					}
				}
				25 = {
					intrigue_scheming_4050_offer_refused_effect = yes
					desc = intrigue_scheming.4050.failure

					modifier = {
						scope:buyer = {
							has_trait = paranoid
						}
						factor = 2
					}
				}
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = -1
			}
		}
	}
	
	#Exchange the secret for a favor from the buyer.
	option = {
		name = intrigue_scheming.4050.c
		trigger = {
			ai_will_give_favor_trigger = {
				CHAR1 = scope:buyer
				CHAR2 = root
			}
			can_add_hook = {
				target = scope:buyer #Matches the hook added by intrigue_scheming_4050_display_player_response_effect
				type = favor_hook
			}
		}

		#Displays a chance-less outcome list if the secret buyer is a player, since we cannot predict their responses.
		if = {
			limit = {
				scope:buyer = {
					is_ai = no
				}
			}
			intrigue_scheming_4050_display_player_response_effect = {
				PAYMENT = flag:favor
			}
		}
		#Displays the likelyhood of the AI accepting this offer if the player proposes it.
		else = {
			random_list = {
				75 = {
					desc = intrigue_scheming.4050.success
					save_scope_value_as = {
						name = payment
						value = flag:favor
					}
					show_as_tooltip = {
						scope:seller = {
							add_hook = {
								target = scope:buyer
								type = favor_hook
							}
						}
						scope:secret = {
							reveal_to = scope:buyer
						}
						add_intrigue_lifestyle_xp = major_lifestyle_xp
					}
					trigger_event = {
						id = intrigue_scheming.4052
						days = { 5 7 }
					}

					compare_modifier = {
						value = scope:buyer.ai_rationality
						multiplier = 0.25

					}
					compare_modifier = {
						value = scope:buyer.ai_compassion
						multiplier = -0.25

					}
					compare_modifier = {
						value = scope:buyer.ai_zeal
						multiplier = 0.25
					}
					modifier = {
						scope:buyer = {
							has_trait = paranoid
						}
						factor = 2
					}
				}
				25 = {
					intrigue_scheming_4050_offer_refused_effect = yes
					desc = intrigue_scheming.4050.failure
					modifier = {
						scope:buyer = {
							has_trait = trusting
						}
						factor = 2
					}
				}
			}
		}
		ai_chance = {
			base = 200
			ai_value_modifier = {
				ai_greed = 1
				ai_rationality = 1
			}
		}
	}

	#Offer the secret at a peace offering between you and a rival.
	option = {
		name = intrigue_scheming.4050.c.rival
		trigger = {
			has_relation_rival = scope:buyer
		}

		#Displays a chance-less outcome list if the secret buyer is a player, since we cannot predict their responses.
		if = {
			limit = {
				scope:buyer = {
					is_ai = no
				}
			}
			intrigue_scheming_4050_display_player_response_effect = {
				PAYMENT = flag:reconciliation
			}
		}
		#Displays the likelyhood of the AI accepting this offer if the player proposes it.
		else = {
			random_list = {
				75 = {
					desc = intrigue_scheming.4050.success
					save_scope_value_as = {
						name = payment
						value = flag:reconciliation
					}
					show_as_tooltip = {
						scope:buyer = {
							scope:buyer = {
								remove_relation_rival = scope:seller
							}
						}
						scope:secret = {
							reveal_to = scope:buyer
						}
						add_intrigue_lifestyle_xp = major_lifestyle_xp
					}
					trigger_event = {
						id = intrigue_scheming.4052
						days = { 5 7 }
					}

					compare_modifier = {
						value = scope:buyer.ai_rationality
						multiplier = 1
					}
					compare_modifier = {
						value = scope:buyer.ai_greed
						multiplier = 0.5
						min = 0
					}
					compare_modifier = {
						value = scope:buyer.ai_compassion
						multiplier = 0.5
						min = 0
					}
					compare_modifier = {
						value = scope:buyer.ai_vengefulness
						multiplier = -1
					}
					modifier = {
						scope:buyer = {
							has_trait = paranoid
						}
						factor = 2
					}

				}
				25 = {
					desc = intrigue_scheming.4050.failure
					intrigue_scheming_4050_offer_refused_effect = yes
					compare_modifier = {
						value = scope:buyer.ai_vengefulness
						multiplier = 1
					}
					modifier = {
						scope:buyer = {
							has_trait = trusting
						}
						factor = 2
					}
				}
			}
		}
		ai_chance = {
			base = 200
			ai_value_modifier = {
				ai_vengefulness = -3
				ai_greed = -0.5
			}
		}
	}

	#Offer the secret as an act of generosity, gaining a significant opinion boost.
	option = {
		name = intrigue_scheming.4050.c.opinion
		trigger = {
			NOR = {
				has_relation_rival = scope:buyer
				ai_will_give_favor_trigger = {
					CHAR1 = scope:buyer
					CHAR2 = root
				}
			}
		}

		#Displays a chance-less outcome list if the secret buyer is a player, since we cannot predict their responses.
		if = {
			limit = {
				scope:buyer = {
					is_ai = no
				}
			}
			intrigue_scheming_4050_display_player_response_effect = {
				PAYMENT = flag:opinion
			}
		}
		#Displays the likelyhood of the AI accepting this offer if the player proposes it.
		else = {
			random_list = {
				85 = {
					desc = intrigue_scheming.4050.success
					save_scope_value_as = {
						name = payment
						value = flag:opinion
					}
					show_as_tooltip = {
						scope:buyer = {
							add_opinion = {
								modifier = grateful_opinion
								target = scope:seller
								opinion = 30
							}
						}
						scope:secret = {
							reveal_to = scope:buyer
						}
						add_intrigue_lifestyle_xp = major_lifestyle_xp
					}
					trigger_event = {
						id = intrigue_scheming.4052
						days = { 5 7 }
					}


					compare_modifier = {
						value = scope:buyer.ai_rationality
						multiplier = 2
					}
					compare_modifier = {
						value = scope:buyer.ai_greed
						multiplier = 1
					}
					compare_modifier = {
						value = scope:buyer.ai_compassion
						multiplier = 1
					}
					compare_modifier = {
						value = scope:buyer.ai_zeal
						multiplier = 0.5
					}

					#Flip trusting and paranoid for the generous option - why would they give me the secret for free!?
					modifier = {
						scope:buyer = {
							has_trait = trusting
						}
						factor = 2
					}
				}
				15 = {
					desc = intrigue_scheming.4050.failure
					intrigue_scheming_4050_offer_refused_effect = yes


					modifier = {
						scope:buyer = {
							has_trait = paranoid
						}
						factor = 2
					}
				}
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 2
				ai_honor = 2
			}
		}
	}

	option = {
		name = intrigue_scheming.4050.d
		add_character_modifier = {
			modifier = intrigue_hoarding_secrets_modifier
			years = 5
		}
	}
}

intrigue_scheming.4051 = {
	type = character_event
	title = intrigue_scheming.4050.t
	desc = {
		desc = intrigue_scheming.4051.desc.start
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:secret = {
						secret_type = secret_lover
					}
				}
				desc = intrigue_scheming.4051.desc.lover
			}
			triggered_desc = {
				trigger = {
					scope:secret = {
						secret_type = secret_incest
					}
				}
				desc = intrigue_scheming.4051.desc.incest
			}
			triggered_desc = {
				trigger = {
					scope:secret = {
						secret_type = secret_disputed_heritage
						secret_type = secret_unmarried_illegitimate_child
					}
				}
				desc = intrigue_scheming.4051.desc.bastard
			}
			triggered_desc = {
				trigger = {
					scope:secret = {
						secret_type = secret_murder_attempt
						NOT = { secret_target = scope:buyer }
					}
				}
				desc = intrigue_scheming.4051.desc.murderattempt
			}
			triggered_desc = {
				trigger = {
					scope:secret = {
						secret_type = secret_murder_attempt
						secret_target = scope:buyer
					}
				}
				desc = intrigue_scheming.4051.desc.murderattemptself
			}
			triggered_desc = {
				trigger = {
					scope:secret = {
						secret_type = secret_murder
					}
				}
				desc = intrigue_scheming.4051.desc.murder
			}
		}
		desc = intrigue_scheming.4051.desc.middle
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:payment = flag:gold
				}
				desc = intrigue_scheming.4051.desc.gold
			}
			triggered_desc = {
				trigger = {
					scope:payment = flag:secret
				}
				desc = intrigue_scheming.4051.desc.secret
			}
			triggered_desc = {
				trigger = {
					scope:payment = flag:favor
				}
				desc = intrigue_scheming.4051.desc.favor
			}
			triggered_desc = {
				trigger = {
					scope:payment = flag:reconciliation
				}
				desc = intrigue_scheming.4051.desc.rival
			}
			triggered_desc = {
				trigger = {
					scope:payment = flag:opinion
				}
				desc = intrigue_scheming.4051.desc.opinion
			}
		}
	}
	
	theme = intrigue_skulduggery_focus
	left_portrait = {
		character = scope:seller
		animation = scheme
	}
	right_portrait = {
		character = scope:portrait
		animation = paranoia
	}

	immediate = {
		#We only want the right portrait to show up whent that character is a murder victim or attempted murder victim who is not the buyer.
		if = {
			limit = {
				scope:secret = {
					OR = {
						secret_type = secret_murder
						secret_type = secret_murder_attempt
					}
				}
				NOT = { scope:target = scope:buyer }
			}
			scope:target = {
				save_scope_as = portrait
			}
		}
	}

	option = {
		name = intrigue_scheming.4051.a
		trigger = {
			NOT = { scope:payment = flag:opinion }
		}
		if = {
			limit = {
				scope:payment = flag:gold
			}
			show_as_tooltip = {
				scope:buyer = {
					pay_short_term_gold = {
						target = scope:seller
						gold = scope:saved_gold_amount
					}
				}
				custom_tooltip = intrigue_scheming.4051.a.tt
			}
		}
		else_if = {
			limit = {
				scope:payment = flag:secret
			}
			show_as_tooltip = {
				scope:payment_secret = {
					reveal_to = scope:seller
				}
				custom_tooltip = intrigue_scheming.4051.a.tt
			}
		}
		else_if = {
			limit = {
				scope:payment = flag:favor
			}
			show_as_tooltip = {
				scope:seller = {
					add_hook = {
						target = scope:buyer
						type = favor_hook
					}
				}
				custom_tooltip = intrigue_scheming.4051.a.tt
			}
		}
		else = {
			show_as_tooltip = {
				scope:buyer = {
					remove_relation_rival = scope:seller
				}
				custom_tooltip = intrigue_scheming.4051.a.tt
			}
		}
		scope:seller = {
			trigger_event = intrigue_scheming.4052
		}
		trigger_event = intrigue_scheming.4054
	}

	option = {
		name = intrigue_scheming.4051.a.opinion
		trigger = {
			scope:payment = flag:opinion
		}
		show_as_tooltip = {
			scope:buyer = {
				add_opinion = {
					modifier = grateful_opinion
					target = scope:seller
					opinion = 30
				}
			}
			custom_tooltip = intrigue_scheming.4051.a.tt
		}
		scope:seller = {
			trigger_event = intrigue_scheming.4052
		}
		trigger_event = intrigue_scheming.4054
	}
	
	option = {
		name = intrigue_scheming.4051.b
		scope:seller = {
			add_opinion = {
				modifier = disappointed_opinion
				target = scope:buyer
				opinion = -10
			}
			trigger_event = intrigue_scheming.4053
		}
	}
}

intrigue_scheming.4052 = {
	type = character_event
	title = intrigue_scheming.4050.t
	desc = intrigue_scheming.4052.desc
	
	theme = intrigue_skulduggery_focus
	left_portrait = {
		character = scope:buyer
		animation = personality_greedy
	}
	right_portrait = {
		character = scope:owner
		animation = paranoia
	}
	lower_right_portrait = scope:target

	option = {
		name = intrigue_scheming.4052.a

		if = {
			limit = {
				scope:payment = flag:gold
			}
			scope:buyer = {
				pay_short_term_gold = {
					target = scope:seller
					gold = scope:saved_gold_amount
				}
			}
			scope:secret = {
				reveal_to = scope:buyer
			}
		}
		else_if = {
			limit = {
				scope:payment = flag:secret
			}
			scope:payment_secret = {
				reveal_to = scope:seller
			}
			scope:secret = {
				reveal_to = scope:buyer
			}
		}
		else_if = {
			limit = {
				scope:payment = flag:favor
			}
			scope:seller = {
				add_hook = {
					target = scope:buyer
					type = favor_hook
				}
			}
			scope:secret = {
				reveal_to = scope:buyer
			}
		}
		else_if = {
			limit = {
				scope:payment = flag:reconciliation
			}
			scope:buyer = {
				remove_relation_rival = scope:seller
			}
			scope:secret = {
				reveal_to = scope:buyer
			}
		}
		else_if = {
			limit = {
				scope:payment = flag:opinion
			}
			scope:buyer = {
				add_opinion = {
					modifier = grateful_opinion
					target = scope:seller
					opinion = 30
				}
			}
			scope:secret = {
				reveal_to = scope:buyer
			}
		}
	}

	after = {
		add_intrigue_lifestyle_xp = major_lifestyle_xp
	}
}

intrigue_scheming.4053 = {
	type = character_event
	title = intrigue_scheming.4050.t
	desc = intrigue_scheming.4053.desc
	
	theme = intrigue_skulduggery_focus
	left_portrait = {
		character = scope:buyer
		animation = disbelief
	}
	right_portrait = {
		character = scope:owner
		animation = disgust
	}
	lower_right_portrait = scope:target

	option = {
		name = intrigue_scheming.4053.a
		scope:buyer = {
			add_opinion = {
				modifier = insult_opinion
				target = scope:seller
				opinion = -10
			}
		}
	}
}

intrigue_scheming.4054 = {
	type = character_event
	title = intrigue_scheming.4050.t
	desc = {
		desc = intrigue_scheming.4054.desc.start
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:secret = {
						secret_type = secret_lover
					}
				}
				desc = intrigue_scheming.4054.desc.lover
			}
			triggered_desc = {
				trigger = {
					scope:secret = {
						secret_type = secret_incest
					}
				}
				desc = intrigue_scheming.4054.desc.incest
			}
			triggered_desc = {
				trigger = {
					scope:secret = {
						secret_type = secret_disputed_heritage
						secret_type = secret_unmarried_illegitimate_child
					}
				}
				desc = intrigue_scheming.4054.desc.bastard
			}
			triggered_desc = {
				trigger = {
					scope:secret = {
						secret_type = secret_murder_attempt
						NOT = { secret_target = scope:buyer }
					}
				}
				desc = intrigue_scheming.4054.desc.murderattempt
			}
			triggered_desc = {
				trigger = {
					scope:secret = {
						secret_type = secret_murder_attempt
						secret_target = scope:buyer
					}
				}
				desc = intrigue_scheming.4054.desc.murderattemptself
			}
			triggered_desc = {
				trigger = {
					scope:secret = {
						secret_type = secret_murder
					}
				}
				desc = intrigue_scheming.4054.desc.murder
			}
		}
	}
	
	theme = intrigue_skulduggery_focus
	left_portrait = {
		character = scope:seller
		animation = scheme
	}
	right_portrait = {
		character = scope:owner
		animation = worry
	}
	lower_right_portrait = scope:target

	immediate = {
		show_as_tooltip = {
			scope:secret = {
				reveal_to = scope:buyer
			}
		}
	}

	option = {
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = { scope:secret = { secret_type = secret_incest } }
						desc = {
							first_valid = {
								triggered_desc = {
									trigger = {
										is_deviant_trigger = yes
									}
									desc = intrigue_scheming.4054.a.incest.deviant
								}
								triggered_desc = {
									trigger = {
										has_negative_attitude_towards_trait_trigger = { TRAIT = incestuous GENDER_CHARACTER = scope:owner }
									}
									desc = intrigue_scheming.4054.a.incest.accepted
								}
								desc = intrigue_scheming.4054.a.incest
							}
						}
					}
					triggered_desc = {
						trigger = {
							scope:secret = {
								OR = {
									secret_type = secret_murder
									secret_type = secret_murder_attempt
								}
							}
						}
						desc = intrigue_scheming.4054.a.murder
					}
					triggered_desc = {
						trigger = {
							scope:secret = {
								OR = {
									secret_type = secret_lover
									secret_type = secret_disputed_heritage
									secret_type = secret_unmarried_illegitimate_child
								}
							}
						}
						desc = intrigue_scheming.4054.a.bastard
					}
				}
			}
		}
	}
}

##########################################################
# Special Chain - Convince Courtier to Share Spy-Secrets #
##########################################################

scripted_trigger intrigue_scheming_special_1001_potential_dynasty_trigger = {
	NOT = { this = root }
	is_close_family_or_spouse_of_root_trigger = no
	is_ai = yes
	is_adult = yes
	is_landed = no
	OR = {
		AND = {
			OR = {
				is_ai = no
				has_lifestyle = intrigue_lifestyle
			}
			intrigue >= medium_skill_rating
		}
		intrigue >= decent_skill_rating
	}
}

#Approach courtier or not?
intrigue_scheming_special.1001 = {
	type = character_event
	title = intrigue_scheming_special.1001.t
	desc = intrigue_scheming_special.1001.desc
	left_portrait = {
		character = scope:courtier_spy
		animation = scheme
	}
	theme = intrigue_skulduggery_focus
	
	trigger = {
		has_focus = intrigue_skulduggery_focus

		NOT = { has_character_flag = had_intrigue_scheming_special_1001_this_lifetime }
		OR = {
			NOT = { has_variable = last_intrigue_scheming_special_event }
			AND = {
				has_variable = last_intrigue_scheming_special_event
				NOT = { var:last_intrigue_scheming_special_event = flag:convince_courtier_spy }
			}
		}
		NOT = { has_character_flag = is_in_intrigue_special_event }
		num_of_relation_intrigue_mentor <= 0
		liege = {
			any_courtier_or_guest = {
				has_dynasty = yes
				dynasty = {
					any_dynasty_member = {
						intrigue_scheming_special_1001_potential_dynasty_trigger = yes
					}
				}
			}
		}
	}

	immediate = {
		play_music_cue = "mx_cue_murder"
		set_variable = {
			name = last_intrigue_scheming_special_event
			value = flag:convince_courtier_spy
		}
		add_character_flag = {
			flag = is_in_intrigue_special_event
			days = 100
		}
		add_character_flag = had_intrigue_scheming_special_1001_this_lifetime

		random_courtier_or_guest = {
			limit = {
				intrigue_scheming_special_1001_potential_dynasty_trigger = yes
			}
			save_scope_as = courtier_spy
		}
		if = {
			limit = {
				NOT = { exists = scope:courtier_spy }
			}
			liege = {
				random_courtier_or_guest = {
					limit = {
						intrigue_scheming_special_1001_potential_dynasty_trigger = yes
					}
					save_scope_as = courtier_spy
				}
			}
		}
		if = {
			limit = {
				NOT = { exists = scope:courtier_spy }
			}
			random_courtier = {
				limit = {
					has_dynasty = yes
					dynasty = {
						any_dynasty_member = {
							intrigue_scheming_special_1001_potential_dynasty_trigger = yes
						}
					}
				}
				dynasty = {
					random_dynasty_member = {
						limit = {
							intrigue_scheming_special_1001_potential_dynasty_trigger = yes
						}
						save_scope_as = courtier_spy
					}
				}
			}
		}
		if = {
			limit = {
				NOT = { exists = scope:courtier_spy }
			}
			random_courtier_or_guest = {
				limit = {
					has_dynasty = yes
					this.dynasty = {
						any_dynasty_member = {
							intrigue_scheming_special_1001_potential_dynasty_trigger = yes
						}
					}
				}
				dynasty = {
					random_dynasty_member = {
						limit = {
							intrigue_scheming_special_1001_potential_dynasty_trigger = yes
						}
						save_scope_as = courtier_spy
					}
				}
			}
		}
		if = {
			limit = {
				NOT = { exists = scope:courtier_spy }
			}
			random_vassal = {
				limit = {
					has_dynasty = yes
					this.dynasty = {
						any_dynasty_member = {
							intrigue_scheming_special_1001_potential_dynasty_trigger = yes
						}
					}
				}
				this.dynasty = {
					random_dynasty_member = {
						limit = {
							intrigue_scheming_special_1001_potential_dynasty_trigger = yes
						}
						save_scope_as = courtier_spy
					}
				}
			}
		}
		if = {
			limit = {
				NOT = { exists = scope:courtier_spy }
			}
			liege = {
				random_courtier_or_guest = {
					limit = {
						has_dynasty = yes
						this.dynasty = {
							any_dynasty_member = {
								intrigue_scheming_special_1001_potential_dynasty_trigger = yes
							}
						}
					}
					this.dynasty = {
						random_dynasty_member = {
							limit = {
								intrigue_scheming_special_1001_potential_dynasty_trigger = yes
							}
							save_scope_as = courtier_spy
						}
					}
				}
			}
		}
		if = {
			limit = {
				NOT = { exists = scope:courtier_spy }
			}
			liege = {
				random_courtier_or_guest = {
					limit = {
						this.dynasty = {
							any_dynasty_member = {
								intrigue_scheming_special_1001_potential_dynasty_trigger = yes
							}
						}
					}
					this.dynasty = {
						random_dynasty_member = {
							limit = {
								intrigue_scheming_special_1001_potential_dynasty_trigger = yes
							}
							save_scope_as = courtier_spy
						}
					}
				}
			}
		}
	}

	option = {
		name = intrigue_scheming_special.1001.a
		ai_chance = {
			base = 60
		}
		custom_tooltip = intrigue_lifestyle_perk_indication
		trigger_event = {
			id = intrigue_scheming_special.1002
			days = { 6 12 }
		}
	}

	option = {
		name = intrigue_scheming_special.1001.b
		ai_chance = {
			base = 40
			modifier = {
				add = 40
				has_trait = craven
			}
		}
		add_character_modifier = {
			modifier = more_vigilant_recistance_modifier
			days = 1825
		}
	}

	option = {#If you're paranoid you should not want them in your court
		name = intrigue_scheming_special.1001.c
		trigger = {
			has_trait = paranoid
		}
		trait = paranoid
		ai_chance = {
			base = 80
		}
		if = {
			limit = {
				scope:courtier_spy = {
					is_courtier_of = root
				}
			}
			remove_courtier_or_guest = scope:courtier_spy
		}
		else_if = {
			limit = {
				scope:courtier_spy = {
					is_foreign_court_guest_of = root
				}
			}
			scope:courtier_spy = {
				return_to_court = yes
			}
		}
		remove_character_flag = is_in_intrigue_special_event
	}
}

#You approach them and they present you with a scenario, how would you react?
intrigue_scheming_special.1002 = {
	type = character_event
	title = intrigue_scheming_special.1001.t
	desc = intrigue_scheming_special.1002.desc
	left_portrait = {
		character = scope:courtier_spy
		animation = personality_dishonorable
	}
	theme = intrigue_skulduggery_focus
	
	immediate = {
		decide_what_options_to_present_effect = yes #Effect used to choose which option to show, always one "correct" and two "wrong". You should try and choose the one that corresponds to the courtier!
		set_variable = {
			name = courtier_convinced
			value = 0
			days = 800
		}
	}

	option = {
		name = intrigue_scheming_special.1002.a
		trigger = {
			OR = {
				var:option_to_present = flag:malicious
				var:option_1_fail_to_present = flag:malicious
				var:option_2_fail_to_present = flag:malicious
			}
		}
		if = {
			limit = {
				var:option_to_present = flag:malicious
			}
			change_variable = {
				name = courtier_convinced
				add = 1
			}
		}
	}

	option = {
		name = intrigue_scheming_special.1002.b
		trigger = {
			OR = {
				var:option_to_present = flag:benevolent
				var:option_1_fail_to_present = flag:benevolent
				var:option_2_fail_to_present = flag:benevolent
			}
		}
		if = {
			limit = {
				var:option_to_present = flag:benevolent
			}
			change_variable = {
				name = courtier_convinced
				add = 1
			}
		}
	}
	
	option = {
		name = intrigue_scheming_special.1002.c
		trigger = {
			OR = {
				var:option_to_present = flag:dominant
				var:option_1_fail_to_present = flag:dominant
				var:option_2_fail_to_present = flag:dominant
			}
		}
		if = {
			limit = {
				var:option_to_present = flag:dominant
			}
			change_variable = {
				name = courtier_convinced
				add = 1
			}
		}
	}
	option = {
		name = intrigue_scheming_special.1002.d
		trigger = {
			OR = {
				var:option_to_present = flag:submissive
				var:option_1_fail_to_present = flag:submissive
				var:option_2_fail_to_present = flag:submissive
			}
		}
		if = {
			limit = {
				var:option_to_present = flag:submissive
			}
			change_variable = {
				name = courtier_convinced
				add = 1
			}
		}
	}
	option = {
		name = intrigue_scheming_special.1002.e
		trigger = {
			OR = {
				var:option_to_present = flag:extroverted
				var:option_1_fail_to_present = flag:extroverted
				var:option_2_fail_to_present = flag:extroverted
			}
		}
		if = {
			limit = {
				var:option_to_present = flag:extroverted
			}
			change_variable = {
				name = courtier_convinced
				add = 1
			}
		}
	}
	option = {
		name = intrigue_scheming_special.1002.f
		trigger = {
			OR = {
				var:option_to_present = flag:introverted
				var:option_1_fail_to_present = flag:introverted
				var:option_2_fail_to_present = flag:introverted
			}
		}
		if = {
			limit = {
				var:option_to_present = flag:introverted
			}
			change_variable = {
				name = courtier_convinced
				add = 1
			}
		}
	}
	option = {
		name = intrigue_scheming_special.1002.g
		trigger = {
			OR = {
				var:option_to_present = flag:emotional
				var:option_1_fail_to_present = flag:emotional
				var:option_2_fail_to_present = flag:emotional
			}
		}
		if = {
			limit = {
				var:option_to_present = flag:emotional
			}
			change_variable = {
				name = courtier_convinced
				add = 1
			}
		}
	}
	option = {
		name = intrigue_scheming_special.1002.h
		trigger = {
			OR = {
				var:option_to_present = flag:levelheaded
				var:option_1_fail_to_present = flag:levelheaded
				var:option_2_fail_to_present = flag:levelheaded
			}
		}
		if = {
			limit = {
				var:option_to_present = flag:levelheaded
			}
			change_variable = {
				name = courtier_convinced
				add = 1
			}
		}
	}
	after = {
		remove_variable = option_to_present
		remove_variable = option_1_fail_to_present
		remove_variable = option_2_fail_to_present
		trigger_event = {
			id = intrigue_scheming_special.1003
			days = { 6 12 }
		}
	}
}

#Next scenario is presented
intrigue_scheming_special.1003 = {
	type = character_event
	title = intrigue_scheming_special.1001.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					var:courtier_convinced >= 1
				}
				desc = intrigue_scheming_special.1003.desc_good
			}
			triggered_desc = {
				trigger = {
					var:courtier_convinced < 1
				}
				desc = intrigue_scheming_special.1003.desc_bad
			}
		}
		desc = intrigue_scheming_special.1003.desc
	}
	left_portrait = {
		character = scope:courtier_spy
		animation = personality_cynical
	}
	theme = intrigue_skulduggery_focus

	immediate = {
		decide_what_options_to_present_effect = yes
	}

	option = {
		name = intrigue_scheming_special.1003.a
		trigger = {
			OR = {
				var:option_to_present = flag:malicious
				var:option_1_fail_to_present = flag:malicious
				var:option_2_fail_to_present = flag:malicious
			}
		}
		if = {
			limit = {
				var:option_to_present = flag:malicious
			}
			change_variable = {
				name = courtier_convinced
				add = 1
			}
			add_character_flag = last_win
		}
	}

	option = {
		name = intrigue_scheming_special.1003.b
		trigger = {
			OR = {
				var:option_to_present = flag:benevolent
				var:option_1_fail_to_present = flag:benevolent
				var:option_2_fail_to_present = flag:benevolent
			}
		}
		if = {
			limit = {
				var:option_to_present = flag:benevolent
			}
			change_variable = {
				name = courtier_convinced
				add = 1
			}
			add_character_flag = last_win
		}
	}
	
	option = {
		name = intrigue_scheming_special.1003.c
		trigger = {
			OR = {
				var:option_to_present = flag:dominant
				var:option_1_fail_to_present = flag:dominant
				var:option_2_fail_to_present = flag:dominant
			}
		}
		if = {
			limit = {
				var:option_to_present = flag:dominant
			}
			change_variable = {
				name = courtier_convinced
				add = 1
			}
			add_character_flag = last_win
		}
	}
	option = {
		name = intrigue_scheming_special.1003.d
		trigger = {
			OR = {
				var:option_to_present = flag:submissive
				var:option_1_fail_to_present = flag:submissive
				var:option_2_fail_to_present = flag:submissive
			}
		}
		if = {
			limit = {
				var:option_to_present = flag:submissive
			}
			change_variable = {
				name = courtier_convinced
				add = 1
			}
			add_character_flag = last_win
		}
	}
	option = {
		name = intrigue_scheming_special.1003.e
		trigger = {
			OR = {
				var:option_to_present = flag:extroverted
				var:option_1_fail_to_present = flag:extroverted
				var:option_2_fail_to_present = flag:extroverted
			}
		}
		if = {
			limit = {
				var:option_to_present = flag:extroverted
			}
			change_variable = {
				name = courtier_convinced
				add = 1
			}
			add_character_flag = last_win
		}
	}
	option = {
		name = intrigue_scheming_special.1003.f
		trigger = {
			OR = {
				var:option_to_present = flag:introverted
				var:option_1_fail_to_present = flag:introverted
				var:option_2_fail_to_present = flag:introverted
			}
		}
		if = {
			limit = {
				var:option_to_present = flag:introverted
			}
			change_variable = {
				name = courtier_convinced
				add = 1
			}
			add_character_flag = last_win
		}
	}
	option = {
		name = intrigue_scheming_special.1003.g
		trigger = {
			OR = {
				var:option_to_present = flag:emotional
				var:option_1_fail_to_present = flag:emotional
				var:option_2_fail_to_present = flag:emotional
			}
		}
		if = {
			limit = {
				var:option_to_present = flag:emotional
			}
			change_variable = {
				name = courtier_convinced
				add = 1
			}
			add_character_flag = last_win
		}
	}
	option = {
		name = intrigue_scheming_special.1003.h
		trigger = {
			OR = {
				var:option_to_present = flag:levelheaded
				var:option_1_fail_to_present = flag:levelheaded
				var:option_2_fail_to_present = flag:levelheaded
			}
		}
		if = {
			limit = {
				var:option_to_present = flag:levelheaded
			}
			change_variable = {
				name = courtier_convinced
				add = 1
			}
			add_character_flag = last_win
		}
	}
	after = {
		remove_variable = option_to_present
		remove_variable = option_1_fail_to_present
		remove_variable = option_2_fail_to_present
		trigger_event = {
			id = intrigue_scheming_special.1004
			days = { 6 12 }
		}
	}
}

#Last scenario is presented
intrigue_scheming_special.1004 = {
	type = character_event
	title = intrigue_scheming_special.1001.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					has_character_flag = last_win
				}
				desc = intrigue_scheming_special.1004.desc_good
			}
			triggered_desc = {
				trigger = {
					NOT = { has_character_flag = last_win }
				}
				desc = intrigue_scheming_special.1004.desc_bad
			}
		}
		desc = intrigue_scheming_special.1004.desc
	}
	left_portrait = {
		character = scope:courtier_spy
		animation = scheme
	}
	theme = intrigue_skulduggery_focus

	immediate = {
		decide_what_options_to_present_effect = yes
	}

	option = {
		name = intrigue_scheming_special.1004.a
		trigger = {
			OR = {
				var:option_to_present = flag:malicious
				var:option_1_fail_to_present = flag:malicious
				var:option_2_fail_to_present = flag:malicious
			}
		}
		if = {
			limit = {
				var:option_to_present = flag:malicious
			}
			change_variable = {
				name = courtier_convinced
				add = 1
			}
		}
	}

	option = {
		name = intrigue_scheming_special.1004.b
		trigger = {
			OR = {
				var:option_to_present = flag:benevolent
				var:option_1_fail_to_present = flag:benevolent
				var:option_2_fail_to_present = flag:benevolent
			}
		}
		if = {
			limit = {
				var:option_to_present = flag:benevolent
			}
			change_variable = {
				name = courtier_convinced
				add = 1
			}
		}
	}
	
	option = {
		name = intrigue_scheming_special.1004.c
		trigger = {
			OR = {
				var:option_to_present = flag:dominant
				var:option_1_fail_to_present = flag:dominant
				var:option_2_fail_to_present = flag:dominant
			}
		}
		if = {
			limit = {
				var:option_to_present = flag:dominant
			}
			change_variable = {
				name = courtier_convinced
				add = 1
			}
		}
	}
	option = {
		name = intrigue_scheming_special.1004.d
		trigger = {
			OR = {
				var:option_to_present = flag:submissive
				var:option_1_fail_to_present = flag:submissive
				var:option_2_fail_to_present = flag:submissive
			}
		}
		if = {
			limit = {
				var:option_to_present = flag:submissive
			}
			change_variable = {
				name = courtier_convinced
				add = 1
			}
		}
	}
	option = {
		name = intrigue_scheming_special.1004.e
		trigger = {
			OR = {
				var:option_to_present = flag:extroverted
				var:option_1_fail_to_present = flag:extroverted
				var:option_2_fail_to_present = flag:extroverted
			}
		}
		if = {
			limit = {
				var:option_to_present = flag:extroverted
			}
			change_variable = {
				name = courtier_convinced
				add = 1
			}
		}
	}
	option = {
		name = intrigue_scheming_special.1004.f
		trigger = {
			OR = {
				var:option_to_present = flag:introverted
				var:option_1_fail_to_present = flag:introverted
				var:option_2_fail_to_present = flag:introverted
			}
		}
		if = {
			limit = {
				var:option_to_present = flag:introverted
			}
			change_variable = {
				name = courtier_convinced
				add = 1
			}
		}
	}
	option = {
		name = intrigue_scheming_special.1004.g
		trigger = {
			OR = {
				var:option_to_present = flag:emotional
				var:option_1_fail_to_present = flag:emotional
				var:option_2_fail_to_present = flag:emotional
			}
		}
		if = {
			limit = {
				var:option_to_present = flag:emotional
			}
			change_variable = {
				name = courtier_convinced
				add = 1
			}
		}
	}
	option = {
		name = intrigue_scheming_special.1004.h
		trigger = {
			OR = {
				var:option_to_present = flag:levelheaded
				var:option_1_fail_to_present = flag:levelheaded
				var:option_2_fail_to_present = flag:levelheaded
			}
		}
		if = {
			limit = {
				var:option_to_present = flag:levelheaded
			}
			change_variable = {
				name = courtier_convinced
				add = 1
			}
		}
	}
	after = {
		remove_character_flag = last_win
		remove_variable = option_to_present
		remove_variable = option_1_fail_to_present
		remove_variable = option_2_fail_to_present
		trigger_event = {
			id = intrigue_scheming_special.1099
			days = { 6 12 }
		}
	}
}


#END - Did you convince the courtier or not?
intrigue_scheming_special.1099 = {
	type = character_event
	title = intrigue_scheming_special.1001.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					var:courtier_convinced >= 2
				}
				desc = intrigue_scheming_special.1099.desc_won
			}
			triggered_desc = {
				trigger = {
					var:courtier_convinced < 2
				}
				desc = intrigue_scheming_special.1099.desc_lost
			}
		}
	}
	left_portrait = {
		character = scope:courtier_spy
		animation = personality_dishonorable
	}
	theme = intrigue_skulduggery_focus

	trigger = {
		scope:courtier_spy = { is_alive = yes }
	}

	on_trigger_fail = {
		remove_character_flag = is_in_intrigue_special_event
		remove_variable = courtier_convinced
	}

	immediate = {
		if = {
			limit = {
				root = { is_ai = no }
			}
			scope:courtier_spy = {
				assign_quirk_effect = yes
			}
		}
	}

	option = {
		name = intrigue_scheming_special.1099.a
		trigger = {
			var:courtier_convinced >= 2
		}
		add_intrigue_lifestyle_perk_points = 1
		hidden_effect = {
			set_relation_intrigue_mentor = scope:courtier_spy
		}
		set_relation_mentor = scope:courtier_spy
	}

	option = {
		name = intrigue_scheming_special.1099.b
		add_character_modifier = {
			modifier = read_people_power_modifier
			days = 1095
		}
		trigger = {
			var:courtier_convinced < 2
		}
	}
	after = {
		remove_character_flag = is_in_intrigue_special_event
		remove_variable = courtier_convinced
	}
}

##########################################################
# Special Chain - Root out secrets at your court #
# 1301 - 1399									#
# by Linnéa Thimrén							  #
##########################################################

#You suspect something might be going on.
intrigue_scheming_special.1301 = {
	type = character_event
	title = intrigue_scheming_special.1301.t
	desc = {
		desc = intrigue_scheming_special.1301.desc
		triggered_desc = {
			trigger = {
				exists = scope:mentor_or_other
			}
			desc = intrigue_scheming_special.1301.desc_mentor_or_other
		}
	}
	left_portrait = {
		character = root
		animation = paranoia
	}
	right_portrait = {
		character = scope:mentor_or_other
		animation = personality_dishonorable
	}
	theme = intrigue_skulduggery_focus
	
	trigger = {
		has_focus = intrigue_skulduggery_focus

		NOT = { has_character_flag = had_intrigue_scheming_special_1301_this_lifetime }
		OR = {
			NOT = { has_variable = last_intrigue_scheming_special_event }
			AND = {
				has_variable = last_intrigue_scheming_special_event
				NOT = { var:last_intrigue_scheming_special_event = flag:secrets_at_court }
			}
		}
		NOT = { has_character_flag = is_in_intrigue_special_event }
		any_courtier_or_guest = {
			is_available_healthy_ai_adult = yes
			is_landed = no
		}
	}

	weight_multiplier = {
		base = 1
		compare_modifier = {
			target = root
			value = stress
			offset = -25
			multiplier = 0.2
		}
		modifier = {
			add = 0.5
			has_trait = paranoid
		}
	}

	immediate = {
		set_variable = {
			name = last_intrigue_scheming_special_event
			value = flag:secrets_at_court
		}
		add_character_flag = {
			flag = is_in_intrigue_special_event
			days = 100
		}
		add_character_flag = had_intrigue_scheming_special_1301_this_lifetime
		if = {
			limit = {
				any_relation = {
					type = intrigue_mentor
					is_ai = yes
				}
			}
			random_relation = {
				type = intrigue_mentor
				limit = {
					is_ai = yes
				}
				save_scope_as = mentor_or_other
			}
		}
		else_if = {
			limit = {
				NOT = { exists = scope:mentor_or_other }
			}
			random_courtier_or_guest = {
				limit = {
					is_adult = yes
					has_relation_friend = root
					is_ai = yes
				}
				alternative_limit = {
					is_adult = yes
					is_close_family_or_spouse_of_root_trigger = yes
					is_ai = yes
					opinion = {
						target = root
						value > neutral_opinion
					}
				}
				alternative_limit = {
					is_adult = yes
					is_ai = yes
					has_lifestyle = intrigue_lifestyle
					opinion = {
						target = root
						value > neutral_opinion
					}
				}
				alternative_limit = {
					is_adult = yes
					is_ai = yes
					opinion = {
						target = root
						value > neutral_opinion
					}
				}
				save_scope_as = mentor_or_other
			}
		}
	}

	option = { #investigate the strange occurrences
		name = intrigue_scheming_special.1301.a
		custom_tooltip = intrigue_lifestyle_perk_indication
		trigger_event = {
			id = intrigue_scheming_special.1302
			days = { 10 30 }
		}
	}

	option = {
		name = intrigue_scheming_special.1301.b
		add_character_modifier = {
			modifier = more_vigilant_recistance_modifier
			years = 5
		}
		stress_impact = {
			paranoid = minor_stress_impact_gain
		}
	}
}

intrigue_scheming_special.1302 = {
	type = character_event
	title = intrigue_scheming_special.1301.t
	desc = intrigue_scheming_special.1302.desc
	left_portrait = {
		character = scope:sneaky_courtier
		animation = personality_dishonorable
	}
	theme = intrigue_skulduggery_focus

	immediate = {
		random_targeting_scheme = {
			if = {
				limit = {
					is_scheme_exposed = no
					scheme_owner = {
						is_in_the_same_court_as_or_guest = root
					}
				}
				save_scope_as = scheme_owner_found
			}
			else_if = {
				limit = {
					any_scheme_agent = {
						AND = {
							is_in_the_same_court_as_or_guest = root
							NOT = { is_agent_exposed_in_scheme = prev }
						}
					}
				}
				save_scope_as = scheme_agent_found
			}
		}
		if = {
			limit = {
				exists = scope:scheme_owner_found
			}
			scope:scheme_owner_found = {
				scheme_owner = {
					save_scope_as = owner
					hidden_effect = {
						random = {
							chance = 85
							save_scope_as = sneaky_courtier
						}
					}
				}
			}
		}
		else_if = {
			limit = {
				exists = scope:scheme_agent_found
			}
			scope:scheme_agent_found = {
				random_scheme_agent = {
					limit = {
						is_in_the_same_court_as_or_guest = root
					}
					save_scope_as = agent
					hidden_effect = {
						random = {
							chance = 85
							save_scope_as = sneaky_courtier
						}
					}
				}
			}
		}
		if = {
			limit = {
				NOT = {
					exists = scope:sneaky_courtier
				}
			}
			add_character_flag = {
				flag = no_scheme
				days = 100
			}
		}
		if = {
			limit = {
				has_character_flag = no_scheme
			}
			random_courtier_or_guest = {
				limit = {
					num_of_relation_lover >= 1
					is_ai = yes
				}
				alternative_limit = {
					is_close_family_or_spouse_of_root_trigger = no
					is_available_healthy_ai_adult = yes
					is_landed = no
					num_of_relation_lover >= 1
				}
				alternative_limit = {
					is_available_healthy_ai_adult = yes
					is_landed = no
					num_of_relation_lover >= 1
				}
				alternative_limit = {
					is_close_family_or_spouse_of_root_trigger = no
					is_available_healthy_ai_adult = yes
					is_landed = no
					opinion = {
						target = root
						value <= low_positive_opinion
					}
				}
				alternative_limit = {
					is_landed = no
					is_available_healthy_ai_adult = yes
					opinion = {
						target = root
						value <= low_positive_opinion
					}
				}
				alternative_limit = {
					is_close_family_or_spouse_of_root_trigger = no
					is_available_healthy_ai_adult = yes
					is_landed = no
					opinion = {
						target = root
						value <= 10
					}
				}
				alternative_limit = {
					is_available_healthy_ai_adult = yes
					is_landed = no
					opinion = {
						target = root
						value <= 10
					}
				}
				alternative_limit = {
					is_available_healthy_ai_adult = yes
					is_landed = no
					opinion = {
						target = root
						value <= neutral_opinion
					}
				}
				alternative_limit = {
					is_available_healthy_ai_adult = yes
					is_landed = no
				}
				save_scope_as = sneaky_courtier
			}
		}
		trigger_event = {
			id = intrigue_scheming_special.1350
			days = 14
		}
	}

	option = { #Fast route, confront them immediately!
		name = intrigue_scheming_special.1302.a
		custom_tooltip = intrigue_scheming_special.1302.a.tt
		if = {
			limit = {
				OR = {
					AND = {
					  exists = scope:owner
						scope:sneaky_courtier = scope:owner
						
					}
					AND = {
						exists = scope:agent
						scope:sneaky_courtier = scope:agent
						
					}
				}
			}
			trigger_event = {
				id = intrigue_scheming_special.1399
				days = { 10 14 }
			}
		}
		else_if = {
			limit = {
				has_character_flag = no_scheme
			}
			trigger_event = {
				id = intrigue_scheming_special.1398
				days = { 10 14 }
			}
		}
	}

	option = { #"Safe" route, continue following them
		name = intrigue_scheming_special.1302.b
		duel = {
			skill = intrigue
			target = scope:sneaky_courtier
			15 = {		
				compare_modifier = {
					value = scope:duel_value
					multiplier = 1
				}
				custom_tooltip = intrigue_scheming_special.1302.b.tt1
				add_character_flag = {
					flag = sneak_win
					days = 100
				}
			}
			15 = {		
				compare_modifier = {
					value = scope:duel_value
					multiplier = -0.5
				}
				custom_tooltip = intrigue_scheming_special.1302.b.tt2
				add_character_flag = {
					flag = sneak_fail
					days = 100
				}
			}
		}
		trigger_event = {
			id = intrigue_scheming_special.1303
			days = { 10 14 }
		}
	}
	option = { #Continue looking
		name = intrigue_scheming_special.1302.c
		custom_tooltip = intrigue_scheming_special.1302.c.tt
		trigger_event = {
			id = intrigue_scheming_special.1304
			days = { 10 14 }
		}
	}
}

#Continue following them - outcome
intrigue_scheming_special.1303 = {
	type = character_event
	title = intrigue_scheming_special.1301.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					has_character_flag = exposed
				}
				desc = intrigue_scheming_special.1303.desc_exposed
			}
			triggered_desc = {
				trigger = {
					NOT = { has_character_flag = exposed }
				}
				desc = {
					random_valid = {
						triggered_desc = {
							trigger = {
								has_character_flag = sneak_win
							}
							desc = {
								first_valid = {
									triggered_desc = {
										trigger = {
											NOT = {
												OR = {
													scope:sneaky_courtier = scope:owner
													scope:sneaky_courtier = scope:agent
												}
											}
										}
										desc = intrigue_scheming_special.1303.desc_sneak_win
									}
									triggered_desc = {
										trigger = {
											OR = {
												scope:sneaky_courtier = scope:owner
												scope:sneaky_courtier = scope:agent
											}
										}
										desc = intrigue_scheming_special.1303.desc_sneak_win_spy
									}
								}
							}
						}
						triggered_desc = {
							trigger = {
								has_character_flag = sneak_fail
							}
							desc = intrigue_scheming_special.1303.desc_sneak_fail
						}
					}
				}
			}
		}
	}
	left_portrait = {
		character = scope:sneaky_courtier
		animation = scheme
	}
	theme = intrigue_skulduggery_focus

	trigger = {
		exists = scope:sneaky_courtier
		scope:sneaky_courtier = { is_alive = yes }
	}

	immediate = {
		if = { #To check if the agent or owner has been discovered during the event chains running-time
			limit = {
				OR = {
					AND = {
						exists = scope:scheme_owner_found
						scope:scheme_owner_found = {
							is_scheme_exposed = yes
						}
					}
					AND = {
						exists = scope:scheme_agent_found
						scope:scheme_agent_found = {
							is_scheme_agent_exposed = scope:agent
						}
					}
				}
			}
			add_character_flag = {
				flag = exposed
				days = 10
			}
		}
		trigger_event = {
			id = intrigue_scheming_special.1350
			days = 9
		}
	}

	option = {
		name = intrigue_scheming_special.1303.a
		trigger = {
			OR = {
				AND = {
					exists = scope:owner
					scope:sneaky_courtier = scope:owner
				}
				AND = {
					exists = scope:agent
					scope:sneaky_courtier = scope:agent
				}
			}
			NOT = { has_character_flag = exposed }
			NOT = { has_character_flag = sneak_fail }
		}
		if = {
			limit = {
				OR = {
					AND = {
						exists = scope:owner
						scope:sneaky_courtier = scope:owner
					}
					AND = {
						exists = scope:agent
						scope:sneaky_courtier = scope:agent
					}
				}
			}
			trigger_event = {
				id = intrigue_scheming_special.1399
				days = { 3 9 }
			}
		}
		else_if = {
			limit = {
				has_character_flag = no_scheme
			}
			trigger_event = {
				id = intrigue_scheming_special.1398
				days = { 3 9 }
			}
		}
	}

	option = {
		name = intrigue_scheming_special.1303.b
		trigger = {
			NOT = { has_character_flag = exposed }
			has_character_flag = sneak_fail
		}
		add_character_modifier = {
			modifier = more_vigilant_recistance_modifier
			years = 5
		}
		add_intrigue_lifestyle_xp = miniscule_lifestyle_xp
		remove_character_flag = no_scheme
		remove_character_flag = is_in_intrigue_special_event
		remove_character_flag = sneak_win
		remove_character_flag = sneak_fail
	}

	option = {
		name = intrigue_scheming_special.1303.c
		trigger = {
			NOT = { has_character_flag = exposed }
			has_character_flag = sneak_win
			NOT = {
				OR = {
					AND = {
						exists = scope:owner
						scope:sneaky_courtier = scope:owner
					}
					AND = {
						exists = scope:agent
						scope:sneaky_courtier = scope:agent
					}
				}
			}
		}
		custom_tooltip = intrigue_scheming_special.1303.c.tt
		add_intrigue_lifestyle_perk_points = 1
		remove_character_flag = no_scheme
		remove_character_flag = is_in_intrigue_special_event
		remove_character_flag = sneak_win
		remove_character_flag = sneak_fail
	}
	option = {
		name = intrigue_scheming_special.1303.d
		trigger = {
			has_character_flag = exposed
		}
		add_intrigue_lifestyle_xp = medium_lifestyle_xp
	}
}

#Continue looking for spy
intrigue_scheming_special.1304 = {
	type = character_event
	title = intrigue_scheming_special.1301.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					NOT = { has_character_flag = not_found }
				}
				desc = intrigue_scheming_special.1304.desc_found
			}
			triggered_desc = {
				trigger = {
					has_character_flag = not_found
				}
				desc = intrigue_scheming_special.1304.desc_not_found
			}
		}
	}
	left_portrait = {
		character = scope:sneaky_courtier
		animation = scheme
	}
	theme = intrigue_skulduggery_focus

	trigger = {
		exists = scope:sneaky_courtier
		scope:sneaky_courtier = { is_alive = yes }
	}

	immediate = {
		if = {
			limit = {
				exists = scope:scheme_owner_found
				NOT = { scope:sneaky_courtier = scope:owner }
			}
			hidden_effect = {
				random = {
					chance = 85
					scope:scheme_owner_found = {
						scheme_owner = {
							save_scope_as = sneaky_courtier
						}
					}
				}
			}
		}
		else_if = {
			limit = {
				exists = scope:scheme_agent_found
				NOT = { scope:sneaky_courtier = scope:agent }
			}
			hidden_effect = {
				random = {
					chance = 85
					scope:scheme_agent_found = {
						random_scheme_agent = {
							limit = {
								is_in_the_same_court_as_or_guest = root
							}
							save_scope_as = sneaky_courtier
						}
					}
				}
			}
		}
		else = {
			add_character_flag = {
				flag = not_found
				days = 100
			}
		}
	}

	option = {
		name = intrigue_scheming_special.1304.a
		trigger = {
			NOT = { has_character_flag = not_found }
		}
		add_intrigue_lifestyle_xp = massive_lifestyle_xp
		if = {
			limit = {
				exists = scope:scheme_owner_found
			}
			scope:scheme_owner_found = {
				expose_scheme_agent = scope:owner
			}
		}
		if = {
			limit = {
				exists = scope:scheme_agent_found
			}
			scope:scheme_agent_found = {
				expose_scheme_agent = scope:agent
			}
		}
	}

	option = {
		name = intrigue_scheming_special.1304.b
		trigger = {
			has_character_flag = not_found
		}
		add_intrigue_lifestyle_xp = miniscule_lifestyle_xp
		remove_character_flag = no_scheme
		remove_character_flag = is_in_intrigue_special_event
		remove_character_flag = sneak_win
		remove_character_flag = sneak_fail
	}
}

#The sneaky_courtier died during the chain
intrigue_scheming_special.1350 = {
	type = character_event
	title = intrigue_scheming_special.1301.t
	desc = intrigue_scheming_special.1350.desc
	left_portrait = {
		character = scope:sneaky_courtier
		animation = fear
	}
	theme = intrigue_skulduggery_focus
	
	trigger = {
		exists = scope:sneaky_courtier
		scope:sneaky_courtier = { is_alive = no }
	}

	option = {
		name = intrigue_scheming_special.1350.a
		add_intrigue_lifestyle_xp = minor_lifestyle_xp
	}

	after = {
		remove_character_flag = no_scheme
		remove_character_flag = is_in_intrigue_special_event
		remove_character_flag = sneak_win
		remove_character_flag = sneak_fail
	}
}

#END, bad
intrigue_scheming_special.1398 = {
	type = character_event
	title = intrigue_scheming_special.1301.t
	desc = intrigue_scheming_special.1398.desc
	left_portrait = {
		character = scope:sneaky_courtier
		animation = shock
	}
	theme = intrigue_skulduggery_focus

	trigger = {
		exists = scope:sneaky_courtier
		scope:sneaky_courtier = { is_alive = yes }
	}

	option = {
		name = intrigue_scheming_special.1398.a
		add_intrigue_lifestyle_xp = miniscule_lifestyle_xp
		scope:sneaky_courtier = {
			add_opinion = {
				modifier = falsely_accused
				target = root
			}
		}
	}

	after = {
		remove_character_flag = no_scheme
		remove_character_flag = is_in_intrigue_special_event
		remove_character_flag = sneak_win
		remove_character_flag = sneak_fail
	}
}

#END, good
intrigue_scheming_special.1399 = {
	type = character_event
	title = intrigue_scheming_special.1301.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					has_character_flag = exposed
				}
				desc = intrigue_scheming_special.1303.desc_exposed
			}
			triggered_desc = {
				trigger = {
					NOT = { has_character_flag = exposed }
				}
				desc = intrigue_scheming_special.1399.desc
			}
		}
	}
	left_portrait = {
		character = scope:sneaky_courtier
		animation = personality_dishonorable
	}
	theme = intrigue_skulduggery_focus

	trigger = {
		exists = scope:sneaky_courtier
		scope:sneaky_courtier = { is_alive = yes }
	}

	immediate = {
		if = { #To check if the agent or owner has been discovered during the event chains running-time
			limit = {
				OR = {
					AND = {
						exists = scope:scheme_owner_found
						scope:scheme_owner_found = {
							is_scheme_exposed = yes
						}
					}
					AND = {
						exists = scope:scheme_agent_found
						scope:scheme_agent_found = {
							is_scheme_agent_exposed = scope:agent
						}
					}
				}
			}
			add_character_flag = {
				flag = exposed
				days = 10
			}
		}
		if = {
			limit = {
				exists = scope:scheme_owner_found
			}
			scope:scheme_owner_found = {
				expose_scheme_agent = scope:owner
			}
		}
		if = {
			limit = {
				exists = scope:scheme_agent_found
			}
			scope:scheme_agent_found = {
				expose_scheme_agent = scope:agent
			}
		}
	}

	option = {
		name = intrigue_scheming_special.1304.a
		add_intrigue_lifestyle_perk_points = 1
	}

	after = {
		remove_character_flag = no_scheme
		remove_character_flag = is_in_intrigue_special_event
		remove_character_flag = sneak_win
		remove_character_flag = sneak_fail
	}
}