#Events related to the Spouse Councillor's diplomacy task

namespace = councillor_spouse_intrigue

# Notifications events (0001-0999)
	#0001 - Spouse increases your Spymaster's opinion of you
	#0002 - Spouse Uncovers a Scheme against you
	#0003 - Spouse uncovers a vassal's Secret
	#0004 - Spouse adds progress to an Intrigue Scheme
	#0005 - Gain a Manipulation Hook on a courtier or vassal


# Events (1001-1999)
	#1001 - Your spouse discovers your spymaster is scheming against you!
	#1002 - Your spouse suspects a character of major importance has a secret
	#1003 - Your spouse discovers a vassal in a plot against you, removing them and giving you a hook on them
	#1004 - Discover a Secret of a powerful vassal in a faction against you.
	#1005 - A vassal leaves a faction and starts dispising a faction leader.
	#1006 - Gain a Hook on a courtier and send them to another court as a plant.


#######################
# Notification Events
# 0001-0999
#######################

#Spouse increases your Spymaster's opinion of you
# by Petter Vilberg
councillor_spouse_intrigue.0001 = {
	hidden = yes

	trigger = {
		valid_spouse_councillor_trigger = yes
		exists = cp:councillor_spymaster
		NOT = { cp:councillor_spymaster = scope:councillor }
		scope:councillor = {
			is_available_healthy_ai_adult = yes
		}
		spouse_intrigue_tier_2_trigger = yes
		NOT = {
			has_character_flag = had_councillor_spouse_intrigue_0001_event
		}
		NOT = {
			reverse_opinion = {
				target = cp:councillor_spymaster
				value > 50
			}
		}
	}

	weight_multiplier = {
		base = 1
		councillor_spouse_limited_skill_rating_modifier = {
			SKILL = intrigue
			SCALE = 1
			SKILL_RATING = spouse_skill_rating_2
		}
		opinion_modifier = { #More likely to fire the less the Spymaster likes you
			trigger = {
				exists = cp:councillor_spymaster
			}
			who = cp:councillor_spymaster
			opinion_target = root
			multiplier = -0.02
		}
	}

	immediate = {
		cp:councillor_spouse = {
			save_scope_as = active_councillor
		}
		add_character_flag = {
			flag = had_councillor_spouse_intrigue_0001_event
			years = 3
		}

		cp:councillor_spymaster = {
			save_scope_as = spymaster
			add_opinion = {
				target = scope:councillor
				modifier = respect_opinion
				opinion = 20
			}
		}

		#Small chance of the two characters becoming lovers
		if = {
			limit = {
				scope:councillor = {
					mgr_can_seduce = yes
					is_ai = yes
				}
				scope:spymaster = {
					is_ai = yes
				}
				possible_mutual_interest_trigger = {
					CHARACTER_1 = scope:councillor
					CHARACTER_2 = scope:spymaster
				}
			}
			random = {
				chance = 0.25
				modifier = {
					add = 0.5
					has_trait = lustful
				}
				scope:councillor = {
					set_relation_lover = scope:spymaster
				}
			}
		}

		send_interface_message = {
			type = event_spouse_task_good
			title = councillor_spouse_intrigue.0001.message
			desc = {
				triggered_desc = {
					trigger = {
						scope:active_councillor = { intrigue < average_skill_level }
					}
					desc = task_intrigue_good_unskilled_notification_tooltip
				}
				triggered_desc = {
					trigger = {
						scope:active_councillor = { intrigue >= average_skill_level }
					}
					desc = task_intrigue_good_skilled_notification_tooltip
				}
			}
			right_icon = scope:councillor
			left_icon = scope:spymaster

			scope:spymaster = {
				add_opinion = {
					target = root
					modifier = respect_opinion
					opinion = 30
				}
			}
		}
	}
}


#Spouse Uncovers a Scheme against you
# by Petter Vilberg
councillor_spouse_intrigue.0002 = {
	hidden = yes

	trigger = {
		valid_spouse_councillor_trigger = yes
		scope:councillor = {
			is_available_healthy_ai_adult = yes
			intrigue >= mediocre_skill_rating
		}
		NOT = {
			has_character_flag = had_event_councillor_spouse_intrigue_0002
		}
		any_targeting_scheme = {
			is_scheme_exposed = no
			hostile_scheme_trigger = yes
			NOR = {
				scheme_owner = {
					this = scope:councillor
				}
				any_scheme_agent = {
					this = scope:councillor
				}
			}
		}
	}

	weight_multiplier = {
		base = 1
		councillor_spouse_limited_skill_rating_modifier = {
			SKILL = intrigue
			SCALE = 1
			SKILL_RATING = spouse_skill_rating_1
		}
	}

	immediate = {
		cp:councillor_spouse = {
			save_scope_as = active_councillor
		}
		add_character_flag = {
			flag = had_event_councillor_spouse_intrigue_0002
			years = 3
		}
		random_targeting_scheme = {
			limit = {
				is_scheme_exposed = no
				hostile_scheme_trigger = yes
				NOR = {
					scheme_owner = {
						this = scope:councillor
					}
					any_scheme_agent = {
						this = scope:councillor
					}
				}
			}
			save_scope_as = scheme
		}

		send_interface_message = {
			type = event_spouse_task_good
			title = councillor_spouse_intrigue.0002.message
			desc = {
				triggered_desc = {
					trigger = {
						scope:active_councillor = { intrigue < average_skill_level }
					}
					desc = task_intrigue_good_unskilled_notification_tooltip
				}
				triggered_desc = {
					trigger = {
						scope:active_councillor = { intrigue >= average_skill_level }
					}
					desc = task_intrigue_good_skilled_notification_tooltip
				}
			}
			
			right_icon = scope:councillor

			scope:scheme = {
				expose_scheme = yes
			}
		}
	}
}


#Spouse uncovers a Secret
# by Petter Vilberg
scripted_trigger councillor_spouse_intrigue_0003_secret_trigger = {
	NOT = { is_known_by = root }
}

scripted_trigger councillor_spouse_intrigue_0003_character_trigger = {
	NOT = { this = scope:councillor }
	any_secret = {
		councillor_spouse_intrigue_0003_secret_trigger = yes
	}
}

councillor_spouse_intrigue.0003 = {
	hidden = yes

	trigger = {
		valid_spouse_councillor_trigger = yes
		NOT = {
			has_character_flag = had_event_councillor_spouse_intrigue_0003
		}
		scope:councillor = {
			is_available_healthy_ai_adult = yes
		}
		OR = {
			AND = {
				any_vassal = {
					NOT = { is_powerful_vassal_of = root }
					councillor_spouse_intrigue_0003_character_trigger = yes
				}
				scope:councillor = {
					has_intrigue_lifestyle_trait_trigger = yes
				}
			}
			AND = {
				any_vassal = {
					is_powerful_vassal_of = root
					councillor_spouse_intrigue_0003_character_trigger = yes
				}
				scope:councillor = {
					has_trait = schemer
				}
			}
			any_courtier = {
				councillor_spouse_intrigue_0003_character_trigger = yes
			}
		}
	}

	weight_multiplier = {
		base = 1
		councillor_spouse_limited_skill_rating_modifier = {
			SKILL = intrigue
			SCALE = 1
			SKILL_RATING = spouse_skill_rating_1
		}
	}

	immediate = {
		cp:councillor_spouse = {
			save_scope_as = active_councillor
		}
		add_character_flag = {
			flag = had_event_councillor_spouse_intrigue_0003
			years = 3
		}

		every_courtier = {
			limit = {
				councillor_spouse_intrigue_0003_character_trigger = yes
			}
			add_to_temporary_list = potential_secret_holders
		}
		if = {
			limit = {
				scope:councillor = {
					has_intrigue_lifestyle_trait_trigger = yes
				}
			}
			every_vassal = {
				limit = {
					councillor_spouse_intrigue_0003_character_trigger = yes
					NOT = { is_powerful_vassal_of = root }
					NOT = { is_in_list = potential_secret_holders }
				}
				add_to_temporary_list = potential_secret_holder
			}
		}
		if = {
			limit = {
				scope:councillor = {
					has_intrigue_lifestyle_trait_trigger = yes
				}
			}
			every_vassal = {
				limit = {
					councillor_spouse_intrigue_0003_character_trigger = yes
					is_powerful_vassal_of = root
					NOT = { is_in_list = potential_secret_holders }
				}
				add_to_temporary_list = potential_secret_holder
			}
		}
		random_in_list = {
			list = potential_secret_holder
			limit = {
				any_secret = {
					councillor_spouse_intrigue_0003_secret_trigger = yes
				}
			}
			weight = {
				base = 1
				modifier = {
					add = 3
					is_landed = yes
				}
				modifier = {
					add = 3
					is_powerful_vassal_of = root
				}
			}
			random_secret = {
				limit = {
					councillor_spouse_intrigue_0003_secret_trigger = yes
				}
				weight = {
					base = 1
					modifier = {
						add = 1
						NOT ={ is_criminal_for = secret_owner }
					}
				}
				save_scope_as = secret
				if = {
					limit = {
						NOT = { is_known_by = scope:councillor }
					}
					reveal_to = scope:councillor
				}
			}
			save_scope_as = secret_holder
		}
		if = {
			limit = {
				exists = scope:secret
				scope:secret = { NOT = { is_known_by = root } }
			}
			send_interface_message = {
				type = event_spouse_task_good
				title = councillor_spouse_intrigue.0003.message
				desc = {
					triggered_desc = {
						trigger = {
							scope:active_councillor = { intrigue < average_skill_level }
						}
						desc = task_intrigue_good_unskilled_notification_tooltip
					}
					triggered_desc = {
						trigger = {
							scope:active_councillor = { intrigue >= average_skill_level }
						}
						desc = task_intrigue_good_skilled_notification_tooltip
					}
				}
				
				right_icon = scope:councillor
				left_icon = scope:secret_holder

				scope:secret = {
					reveal_to = root
				}
			}
		}
	}
}


#Spouse adds progress to an Intrigue Scheme
scripted_trigger councillor_spouse_intrigue_0004_trigger = {
	scheme_skill = intrigue
	NOT = { scheme_target = scope:councillor }
	scheme_power_resistance_ratio > 0
}

councillor_spouse_intrigue.0004 = {
	hidden = yes

	trigger = {
		valid_spouse_councillor_trigger = yes
		NOT = {
			has_character_flag = had_event_councillor_spouse_intrigue_0004
		}
		spouse_intrigue_tier_2_trigger = yes
		scope:councillor = {
			is_available_healthy_ai_adult = yes
			intrigue >= medium_skill_rating
		}

		any_scheme = {
			councillor_spouse_intrigue_0004_trigger = yes
		}
	}

	weight_multiplier = {
		base = 1
		councillor_spouse_limited_skill_rating_modifier = {
			SKILL = intrigue
			SCALE = 1
			SKILL_RATING = spouse_skill_rating_2
		}
	}

	immediate = {
		cp:councillor_spouse = {
			save_scope_as = active_councillor
		}
		if = {
			limit = {
				scope:councillor = {
					has_trait = schemer
				}
			}
			add_character_flag = {
				flag = had_event_councillor_spouse_intrigue_0004
				years = 1
			}
		}
		else_if = {
			limit = {
				scope:councillor = {
					has_intrigue_lifestyle_trait_trigger = yes
				}
			}
			add_character_flag = {
				flag = had_event_councillor_spouse_intrigue_0004
				months = 30
			}
		}
		else = {
			add_character_flag = {
				flag = had_event_councillor_spouse_intrigue_0004
				years = 3
			}
		}

		random_scheme = {
			limit = {
				councillor_spouse_intrigue_0004_trigger = yes
			}
			weight = {
				base = 1
				modifier = {
					add = 3
					scope:councillor = {
						has_trait = schemer
					}
					scheme_type = murder
				}
			}
			save_scope_as = scheme
			scheme_target = {
				save_scope_as = target
			}
		}

		send_interface_message = {
			type = event_spouse_task_good
			title = councillor_spouse_intrigue.0004.message
			desc = {
				triggered_desc = {
					trigger = {
						scope:active_councillor = { intrigue < average_skill_level }
					}
					desc = task_intrigue_good_unskilled_notification_tooltip
				}
				triggered_desc = {
					trigger = {
						scope:active_councillor = { intrigue >= average_skill_level }
					}
					desc = task_intrigue_good_skilled_notification_tooltip
				}
			}
			
			right_icon = scope:councillor
			left_icon = scope:target

			scope:scheme = {
				add_scheme_progress = scheme_progress_gain
			}
		}
	}
}


#Gain a Manipulation Hook on a courtier or vassal
scripted_trigger councillor_spouse_intrigue_0005_target_trigger = {
	is_available_healthy_adult = yes
	is_ai = yes
	NOT = { this = scope:councillor }
	root = {
		can_add_hook = {
			target = prev
			type = manipulation_hook
		}
	}
	OR = {
		is_courtier_of = root
		AND = {
			is_vassal_of = root
			NOT = { is_powerful_vassal_of = root }
			scope:councillor = {
				has_trait = schemer
			}
		}
		AND = {
			is_powerful_vassal_of = root
			scope:councillor = {
				has_trait = schemer
			}
		}
	}
}

councillor_spouse_intrigue.0005 = {
	hidden = yes

	trigger = {
		valid_spouse_councillor_trigger = yes
		spouse_intrigue_tier_2_trigger = yes
		NOT = {
			has_character_flag = had_event_councillor_spouse_intrigue_0005
		}
		OR = {
			any_courtier = {
				councillor_spouse_intrigue_0005_target_trigger = yes
			}
			any_vassal = {
				councillor_spouse_intrigue_0005_target_trigger = yes
			}
		}
	}

	weight_multiplier = {
		base = 1
		councillor_spouse_limited_skill_rating_modifier = {
			SKILL = intrigue
			SCALE = 1
			SKILL_RATING = spouse_skill_rating_2
		}
	}

	immediate = {
		cp:councillor_spouse = {
			save_scope_as = active_councillor
		}
		add_character_flag = {
			flag = had_event_councillor_spouse_intrigue_0005
			years = 5
		}
		every_courtier = {
			limit = {
				councillor_spouse_intrigue_0005_target_trigger = yes
			}
			add_to_list = potential_targets
		}
		every_vassal = {
			limit = {
				councillor_spouse_intrigue_0005_target_trigger = yes	
			}
			add_to_list = potential_targets
		}

		random_in_list = {
			list = potential_targets
			weight = {
				base = 1
				modifier = {
					add = 5
					is_vassal_of = root
				}
				modifier = {
					add = 3
					is_powerful_vassal_of = root
				}
			}
			save_scope_as = target
		}

		#Hook for councillor...
		scope:councillor = {
			if = {
				limit = {
					can_add_hook = {
						target = scope:target
						type = manipulation_hook	
					}
				}
				add_hook = {
					target = scope:target
					type = manipulation_hook
				}
			}
		}

		#... and hook for liege
		send_interface_message = {
			type = event_spouse_task_good
			title = councillor_spouse_intrigue.0005.message
			desc = {
				triggered_desc = {
					trigger = {
						scope:active_councillor = { intrigue < average_skill_level }
					}
					desc = task_intrigue_good_unskilled_notification_tooltip
				}
				triggered_desc = {
					trigger = {
						scope:active_councillor = { intrigue >= average_skill_level }
					}
					desc = task_intrigue_good_skilled_notification_tooltip
				}
			}
			
			left_icon = scope:target
			right_icon = scope:councillor

			add_hook = {
				target = scope:target
				type = manipulation_hook
			}
		}
	}
}

#Spouse loses Trusting after involvement in intrigue, by Sean Hughes
councillor_spouse_intrigue.0006 = {
	hidden = yes
	
	trigger = {
		valid_spouse_councillor_trigger = yes
		scope:councillor = {
			is_performing_council_task = task_court_intrigue
			
			has_trait = trusting
			NOT = { has_trait = gregarious }
			number_of_personality_traits >= 3
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = 0.5
			scope:councillor = {
				number_of_personality_traits = 4
			}
		}
		modifier = {
			add = 0.25
			scope:councillor = {
				has_trait = schemer
			}
		}
	}

	immediate = {
		cp:councillor_spouse = {
			save_scope_as = active_councillor
		}
		send_interface_message = {
			type = event_spouse_task_good
			title = councillor_spouse_intrigue.0006.message
			desc = {
				triggered_desc = {
					trigger = {
						scope:active_councillor = { intrigue < average_skill_level }
					}
					desc = task_intrigue_good_unskilled_notification_tooltip
				}
				triggered_desc = {
					trigger = {
						scope:active_councillor = { intrigue >= average_skill_level }
					}
					desc = task_intrigue_good_skilled_notification_tooltip
				}
			}
			
			left_icon = scope:councillor

			scope:councillor = {
				remove_trait = trusting
			}
		}
	}
}

#Spouse gains Deceitful after involvement in intrigue, by Sean Hughes
councillor_spouse_intrigue.0007 = {
	hidden = yes
	
	trigger = {
		valid_spouse_councillor_trigger = yes
		scope:councillor = {
			is_performing_council_task = task_court_intrigue

			NOR = {
				has_trait = honest
				has_trait = deceitful
			}
			number_of_personality_traits <= 3
		}
	}

	weight_multiplier = {
		base = 0.5
		modifier = {
			add = 0.5
			scope:councillor = {
				number_of_personality_traits <= 2
			}
		}
		modifier = {
			add = 0.25
			scope:councillor = {
				has_trait = schemer
			}
		}
	}

	immediate = {
		cp:councillor_spouse = {
			save_scope_as = active_councillor
		}
		send_interface_message = {
			type = event_spouse_task_good
			title = councillor_spouse_intrigue.0007.message
			desc = {
				triggered_desc = {
					trigger = {
						scope:active_councillor = { intrigue < average_skill_level }
					}
					desc = task_intrigue_good_unskilled_notification_tooltip
				}
				triggered_desc = {
					trigger = {
						scope:active_councillor = { intrigue >= average_skill_level }
					}
					desc = task_intrigue_good_skilled_notification_tooltip
				}
			}
			
			left_icon = scope:councillor
			
			scope:councillor = {
				add_trait = deceitful
			}
		}
	}
}


#######################
# Character Events
# 1001-1999
#######################


#Your Spymaster is Scheming against you
# by Petter Vilberg
scripted_trigger councillor_spouse_intrigue_1001_scheme_trigger = {
	scheme_skill = intrigue
	OR = {
		AND = {
			is_scheme_exposed = no
			hostile_scheme_trigger = yes
			scheme_owner = root.cp:councillor_spymaster
		}
		AND = {
			hostile_scheme_trigger = yes
			any_scheme_agent = {
				this = root.cp:councillor_spymaster
			}
			is_scheme_agent_exposed = root.cp:councillor_spymaster
		}
	}
}

councillor_spouse_intrigue.1001 = {
	type = character_event
	title = councillor_spouse_intrigue.1001.t
	desc = councillor_spouse_intrigue.1001.desc
	theme = intrigue
	left_portrait = {
		character = scope:councillor
		animation = shock
	}
	right_portrait = {
		character = scope:spymaster
		animation = scheme
	}
	
	trigger = {
		valid_spouse_councillor_trigger = yes
		spouse_intrigue_tier_2_trigger = yes
		exists = cp:councillor_spymaster
		NOT = {
			cp:councillor_spymaster = scope:councillor
		}
		NOT = {
			has_character_flag = had_event_councillor_spouse_intrigue_1001
		}
		scope:councillor = {
			is_available_healthy_adult = yes
		}

		any_targeting_scheme = {
			councillor_spouse_intrigue_1001_scheme_trigger = yes
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = 2
			any_targeting_scheme = {
				councillor_spouse_intrigue_1001_scheme_trigger = yes
				scheme_progress > 50	
			}
		}
		councillor_spouse_limited_skill_rating_modifier = {
			SKILL = intrigue
			SCALE = 1
			SKILL_RATING = spouse_skill_rating_2
		}
	}

	immediate = {
		add_character_flag = {
			flag = had_event_councillor_spouse_intrigue_1001
			years = 5
		}

		random_targeting_scheme = {
			limit = {
				councillor_spouse_intrigue_1001_scheme_trigger = yes
			}
			save_scope_as = scheme
			if = {
				limit = {
					is_scheme_exposed = no
					hostile_scheme_trigger = yes
				}
				expose_scheme = yes
			}
		}

		cp:councillor_spymaster = {
			save_scope_as = spymaster
		}
	}

	option = {
		name = councillor_spouse_intrigue.1001.a
		scope:scheme = {
			expose_scheme_agent = scope:spymaster
		}
	}
}



#A character of major importance has a Secret
# by Petter Vilberg
scripted_trigger councillor_spouse_intrigue_1002_secret_trigger = {
	NOT = { is_known_by = root }
}

scripted_trigger councillor_spouse_intrigue_1002_character_trigger = {
	NOT = { this = scope:councillor }
	any_secret = {
		councillor_spouse_intrigue_1002_secret_trigger = yes
	}
}

councillor_spouse_intrigue.1002 = {
	type = character_event
	title = councillor_spouse_intrigue.1002.t
	desc = councillor_spouse_intrigue.1002.desc
	theme = intrigue
	left_portrait = {
		character = scope:councillor
		animation = scheme
	}
	right_portrait = {
		character = scope:target
		animation = worry
	}
	
	trigger = {
		valid_spouse_councillor_trigger = yes
		OR = { # Expensive, so we restrict the AI use of this
			is_ai = no
			highest_held_title_tier > tier_county
		}
		spouse_intrigue_tier_2_trigger = yes
		NOT = {
			has_character_flag = had_event_councillor_spouse_intrigue_1002
		}
		get_characters_of_major_interest_trigger = {
			LISTNAME = major_characters
		}
		any_in_list = {
			list = major_characters
			count >= 1
			councillor_spouse_intrigue_1002_character_trigger = yes
		}
	}

	weight_multiplier = {
		base = 1
		councillor_spouse_limited_skill_rating_modifier = {
			SKILL = intrigue
			SCALE = 1
			SKILL_RATING = spouse_skill_rating_2
		}
	}

	immediate = {
		add_character_flag = {
			flag = had_event_councillor_spouse_intrigue_1002
			years = 3
		}

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

		get_characters_of_major_interest_effect = {
			LISTNAME = major_characters
		}
		random_in_list = {
			list = major_characters
			limit = {
				councillor_spouse_intrigue_1002_character_trigger = yes
			}
			weight = {
				base = 1
				modifier = {
					add = 5
					any_secret = {
						councillor_spouse_intrigue_1002_secret_trigger = yes
						is_criminal_for = secret_owner
					}
				}
			}
			save_scope_as = target
		}
	}

	option = { #Figure it out now!
		name = {
			trigger = {
				opinion = {
					target = scope:councillor
					value >= 50
				}
			}
			text = councillor_spouse_intrigue.1002.a
		}
		name = {
			trigger = {
				opinion = {
					target = scope:councillor
					value < 50
				}
			}
			text = councillor_spouse_intrigue.1002.b
		}
		#TODO_CD: Replace with other types of discovery
		#if = {
			#limit = {			
				#can_start_scheme = {
					#type = spy_on_scheme
					#target = scope:target
				#}
			#}
			#start_scheme = {
				#type = spy_on_scheme
				#target = scope:target
			#}
		#}
		add_character_modifier = {
			modifier = digging_for_secrets_modifier
			years = 1
		}
	}

	option = { #Hm, I should protect myself
		name = councillor_spouse_intrigue.1002.c
		add_character_modifier = {
			modifier = watchful_modifier
			days = watchful_modifier_duration
		}
	}
}



#A vassal in a Scheme is removed, and you gain a hook on them instead
scripted_trigger councillor_spouse_intrigue_1003_scheme_agent_trigger = {
	NOT = { is_agent_exposed_in_scheme = scope:scheme }
	NOT = { this = scope:councillor }
	OR = {
		is_courtier_of = root
		AND = {
			root.cp:councillor_spouse = {
				has_trait = schemer
			}
			is_vassal_of = root
			NOT = { is_powerful_vassal_of = root }
		}
		AND = {
			root.cp:councillor_spouse = {
				has_trait = schemer
			}
			is_powerful_vassal_of = root	
		}
	}
	is_ai = yes
	root = {
		can_add_hook = {
			type = threat_hook
			target = prev
		}
	}
}

scripted_trigger councillor_spouse_intrigue_1003_scheme_trigger = {
	scheme_owner = {
		is_ai = yes
		NOT = { this = scope:councillor }
	}
	is_scheme_exposed = yes
	hostile_scheme_trigger = yes
	scheme_power_resistance_ratio > 1
	save_temporary_scope_as = scheme
	any_scheme_agent = {
		councillor_spouse_intrigue_1003_scheme_agent_trigger = yes
	}
}


councillor_spouse_intrigue.1003 = {
	type = character_event
	title = councillor_spouse_intrigue.1003.t
	desc = councillor_spouse_intrigue.1003.desc
	theme = intrigue
	left_portrait = {
		character = scope:councillor
		animation = scheme
	}
	right_portrait = {
		character = scope:agent
		animation = fear
	}
	lower_right_portrait = scope:known_owner
	
	trigger = {
		valid_spouse_councillor_trigger = yes
		spouse_intrigue_tier_2_trigger = yes
		NOT = {
			has_character_flag = had_event_councillor_spouse_intrigue_1003
		}
		any_targeting_scheme = {
			councillor_spouse_intrigue_1003_scheme_trigger = yes
		}
	}

	weight_multiplier = {
		base = 1
		councillor_spouse_limited_skill_rating_modifier = {
			SKILL = intrigue
			SCALE = 1
			SKILL_RATING = spouse_skill_rating_2
		}
	}

	immediate = {
		add_character_flag = {
			flag = had_event_councillor_spouse_intrigue_1003
			years = 3
		}
		random_targeting_scheme = {
			limit = {
				councillor_spouse_intrigue_1003_scheme_trigger = yes
			}
			weight = {
				base = 1
				modifier = {
					add = 5
					any_scheme_agent = {
						councillor_spouse_intrigue_1003_scheme_agent_trigger = yes
						is_vassal_of = root
					}
				}
				modifier = {
					add = 5
					any_scheme_agent = {
						councillor_spouse_intrigue_1003_scheme_agent_trigger = yes
						is_powerful_vassal_of = root
					}
				}
			}
			save_scope_as = scheme
			random_scheme_agent = {
				limit = {
					councillor_spouse_intrigue_1003_scheme_agent_trigger = yes
				}
				weight = {
					base = 1
					modifier = {
						add = 5
						is_vassal_of = root
					}
					modifier = {
						add = 5
						is_powerful_vassal_of = root
					}
				}
				save_scope_as = agent
			}
			if = {
				limit = {
					is_scheme_exposed = yes
				}
				scheme_owner = {
					save_scope_as = known_owner
				}
			}
		}
		hidden_effect = {
			scope:councillor = {
				if = {
					limit = {
						can_add_hook = {
							target = scope:agent
							type = manipulation_hook
						}
					}
					add_hook = {
						target = scope:agent
						type = manipulation_hook
					}
				}
			}
		}
	}

	option = {
		name = councillor_spouse_intrigue.1003.a
		scope:agent = {
			forbid_from_scheme = scope:scheme
		}
		add_hook = {
			type = threat_hook
			target = scope:agent
		}
	}

	option = {
		name = councillor_spouse_intrigue.1003.b
		trigger = {
			scope:scheme = {
				is_scheme_exposed = no
				hostile_scheme_trigger = yes
			}
		}
		scope:scheme = {
			expose_scheme = yes
		}
	}

	option = {
		name = councillor_spouse_intrigue.1003.c
		scope:scheme = {
			add_scheme_modifier = {
				type = councillor_spouse_defuses_scheme_modifier
				days = 730
			}
		}
	}
}



#Uncover a Secret on a powerful vassal in a faction
# by Petter Vilberg
scripted_trigger councillor_spouse_intrigue_1004_secret_trigger = {
	NOT = { is_known_by = root }
	is_blackmailable_secret_trigger = {
		BLACKMAILER = root
		PARTICIPANT = $PARTICIPANT$
	}
	trigger_if = {
		limit = {
			exists = secret_target
		}
		NOT = {
			secret_is_incriminating_trigger = {
				TARGET = scope:councillor
			}
		}
	}
}

scripted_trigger councillor_spouse_intrigue_1004_faction_member_trigger = {
	is_ai = yes
	is_powerful_vassal_of = root
	save_temporary_scope_as = faction_member
	any_secret = {
		councillor_spouse_intrigue_1004_secret_trigger = { PARTICIPANT = scope:faction_member }
	}
	root = {
		NOT = {
			has_hook_of_type = {
				target = prev
				type = weak_blackmail_hook
			}
		}
	}
}


councillor_spouse_intrigue.1004 = {
	type = character_event
	title = councillor_spouse_intrigue.1004.t
	desc = councillor_spouse_intrigue.1004.desc
	theme = intrigue
	left_portrait = {
		character = scope:councillor
		animation = scheme
	}
	right_portrait = {
		character = scope:secret_holder
		animation = fear
	}
	
	trigger = {
		valid_spouse_councillor_trigger = yes
		spouse_intrigue_tier_2_trigger = yes
		NOT = {
			has_character_flag = had_event_councillor_spouse_intrigue_1004
		}
		cp:councillor_spouse = {
			OR = {
				has_trait = schemer
				intrigue >= high_skill_rating
			}
		}
		any_targeting_faction = {
			any_faction_member = {
				councillor_spouse_intrigue_1004_faction_member_trigger = yes
			}
		}
	}

	weight_multiplier = {
		base = 1
		councillor_spouse_limited_skill_rating_modifier = {
			SKILL = intrigue
			SCALE = 1
			SKILL_RATING = spouse_skill_rating_2
		}
	}

	immediate = {
		add_character_flag = {
			flag = had_event_councillor_spouse_intrigue_1004
			years = 3
		}
		random_targeting_faction = {
			limit = {
				any_faction_member = {
					councillor_spouse_intrigue_1004_faction_member_trigger = yes
				}
			}
			save_scope_as = faction
			random_faction_member = {
				limit = {
					councillor_spouse_intrigue_1004_faction_member_trigger = yes
				}
				save_scope_as = secret_holder
				random_secret = {
					limit = {
						councillor_spouse_intrigue_1004_secret_trigger = { PARTICIPANT = scope:secret_holder }
					}
					save_scope_as = secret
					reveal_to = root
					hidden_effect = {
						if = {
							limit = {
								NOT = { is_known_by = scope:councillor }
							}
							reveal_to = scope:councillor
						}
					}
				}
			}
		}
	}

	option = {
		name = councillor_spouse_intrigue.1004.a
		scope:secret_holder = {
			leave_faction_with_cooldown_effect = {
				FACTION = scope:faction
				YEARS = 20
			}
		}
		
		blackmail_target_with_secret_effect = { #Secret being blackmailable is checked in councillor_spouse_intrigue_1004_secret_trigger
			TARGET = scope:secret_holder
			SECRET = scope:secret
		}

		scope:secret_holder = {
			add_opinion = {
				modifier = blackmailing_me_opinion
				target = root
			}
		}
	}

	option = {
		name = councillor_spouse_intrigue.1004.b
		scope:secret = {
			expose_secret = root
		}
	}
	
	option = {
		name = councillor_spouse_intrigue.1004.c
		custom_tooltip = councillor_spouse_intrigue.1004.c.tt
	}
}


#A vassal leaves a faction and starts desipising the faction leader
# by Petter Vilberg
scripted_trigger councillor_spouse_intrigue_1005_faction_member_trigger = {
	NOT = { this = scope:faction.faction_leader }
	NOT = { this = scope:councillor }
}

scripted_trigger councillor_spouse_intrigue_1005_faction_trigger = {
	save_temporary_scope_as = faction
	exists = faction_leader
	any_faction_member = {
		councillor_spouse_intrigue_1005_faction_member_trigger = yes
	}
}

councillor_spouse_intrigue.1005 = {
	type = character_event
	title = councillor_spouse_intrigue.1005.t
	desc = councillor_spouse_intrigue.1005.desc
	theme = intrigue
	left_portrait = scope:councillor
	right_portrait = scope:faction_member
	lower_right_portrait = scope:leader
	
	trigger = {
		valid_spouse_councillor_trigger = yes
		any_targeting_faction = {
			councillor_spouse_intrigue_1005_faction_trigger = yes
		}
		NOT = { has_character_flag = had_event_councillor_spouse_intrigue_1005 }
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		add_character_flag = {
			flag = had_event_councillor_spouse_intrigue_1005
			years = 10
		}
		random_targeting_faction = {
			limit = {
				councillor_spouse_intrigue_1005_faction_trigger = yes
			}
			save_scope_as = faction
			random_faction_member = {
				limit = {
					councillor_spouse_intrigue_1005_faction_member_trigger = yes
				}
				save_scope_as = faction_member
			}
			faction_leader = {
				save_scope_as = leader
			}
		}
		hidden_effect = {
			scope:faction_member = {
				add_opinion = {
					target = scope:councillor
					modifier = respect_opinion
					opinion = 20
				}
				if = {
					limit = {
						NOT = {
							has_any_scripted_relation = scope:councillor
						}
					}
					random = {
						chance = 40
						set_relation_potential_friend = scope:councillor
					}
				}
			}
		}
	}

	option = {
		name = councillor_spouse_intrigue.1005.a
		scope:faction_member = {
			leave_faction_with_cooldown_effect = {
				FACTION = scope:faction
				YEARS = 20
			}
			add_opinion = {
				target = scope:leader
				modifier = reputation_opinion
				opinion = -50
			}
		}
	}

	option = {
		name = councillor_spouse_intrigue.1005.b
		reverse_add_opinion = {
			target = scope:faction_member
			modifier = reputation_opinion
			opinion = 30
		}
	}
}


#A Hooked Courtier gets sent as a plant
# by Petter Vilberg
scripted_trigger councillor_spouse_intrigue_1006_plant_trigger = {
	is_available_healthy_ai_adult = yes
	NOT = { this = scope:councillor }
	NOT = {
		is_of_major_interest_trigger = {
			CHARACTER = root
		}
	}
	NOT = {
		is_of_minor_interest_trigger = {
			CHARACTER = root
		}
	}
	intrigue >= mediocre_skill_rating
}

scripted_trigger councillor_spouse_intrigue_1006_scheme_target_trigger = {
	court_owner = {
		NOT = { this = scope:councillor }
	}
}

scripted_trigger councillor_spouse_intrigue_1006_scheme_trigger = {
	scheme_skill = intrigue
	hostile_scheme_trigger = yes
	scheme_target = {
		councillor_spouse_intrigue_1006_scheme_target_trigger = yes
	}
}


councillor_spouse_intrigue.1006 = {
	type = character_event
	title = councillor_spouse_intrigue.1006.t
	desc = councillor_spouse_intrigue.1006.desc
	theme = intrigue
	left_portrait = scope:councillor
	right_portrait = scope:target
	lower_right_portrait = scope:other_court_owner
	
	trigger = {
		valid_spouse_councillor_trigger = yes
		spouse_intrigue_tier_3_trigger = yes
		NOT = { has_character_flag = had_event_councillor_spouse_intrigue_1006 }
		any_scheme = {
			councillor_spouse_intrigue_1006_scheme_trigger = yes
		}
		any_courtier = {
			councillor_spouse_intrigue_1006_plant_trigger = yes
		}
	}

	weight_multiplier = {
		base = 1
		councillor_spouse_limited_skill_rating_modifier = {
			SKILL = intrigue
			SCALE = 1
			SKILL_RATING = spouse_skill_rating_3
		}
	}

	immediate = {
		add_character_flag = {
			flag = had_event_councillor_spouse_intrigue_1006
			years = 5
		}
		random_scheme = {
			limit = {
				councillor_spouse_intrigue_1006_scheme_trigger = yes
			}
			scheme_target = {
				save_scope_as = target
			}
		}
		if = {
			limit = {
				NOT = { scope:target = scope:target.court_owner }
			}
			scope:target.court_owner = {
				save_scope_as = other_court_owner
				save_scope_as = court_owner
			}
		}
		else = {
			scope:target = {
				save_scope_as = court_owner
			}
		}
		random_courtier = {
			limit = {
				councillor_spouse_intrigue_1006_plant_trigger = yes
			}
			save_scope_as = plant
		}
	}

	option = {
		name = councillor_spouse_intrigue.1006.a
		pay_short_term_gold = {
			target = scope:plant
			gold = minor_gold_value
		}
		if = {
			limit = {
				can_add_hook = {
					target = scope:plant
					type = favor_hook				
				}
			}
			add_hook = {
				target = scope:plant
				type = favor_hook
			}
		}
		scope:plant = {
			add_character_modifier = {
				modifier = councillor_spouse_espionage_support_modifier
				years = 5
			}
		}
		scope:target.court_owner = {
			add_visiting_courtier = scope:plant
		}
	}

	option = {
		name = councillor_spouse_intrigue.1006.b
		add_hook = {
			target = scope:plant
			type = favor_hook
		}
	}
}