##############################
# SPYMASTER
#
# Job: action_uncover_plots
#	929: The Spymaster discovers a chance to undermine a faction member
#
# Job: action_study_technology
# 	932: The Spymaster studies foreign technology
# 	933: The Spymaster is discovered by the local count - chance of imprisonment
#
# Job: action_organize_spies
# 	935: Spy Network Increase
# 	936: Spy Netwrok Decrease
#
##############################

##############################
# SPYMASTER
# JOB: action_uncover_plots
##############################
# 929: Spymaster undermines faction member
character_event = {
	id = 929
	title = EVTNAME929
	picture = GFX_evt_council
	border = GFX_event_normal_frame_intrigue
	
	desc = {
		text = EVTDESC929_COURT
		trigger = {
			event_target:faction_member = { OR = { leads_faction = faction_court in_faction = faction_court } }
		}
	}
	desc = {
		text = EVTDESC929_PROSPERITY
		trigger = {
			event_target:faction_member = { OR = { leads_faction = faction_prosperity in_faction = faction_prosperity } }
		}
	}
	desc = {
		text = EVTDESC929_GLORY
		trigger = {
			event_target:faction_member = { OR = { leads_faction = faction_glory in_faction = faction_glory } }
		}
	}
	desc = {
		text = EVTDESC929_TRADITION
		trigger = {
			event_target:faction_member = { OR = { leads_faction = faction_tradition in_faction = faction_tradition } }
		}
	}

	min_age = 16
	capable_only = yes
	prisoner = no
	
	immediate = {
		location = {
			owner = {
				save_event_target_as = faction_member
			}
		}
	}
	
	trigger = {
		OR = {
			has_job_action = action_uncover_plots_offmap
			has_job_action = action_uncover_plots
		}
		NOT = { has_character_modifier = in_seclusion }
		
		location = {
			owner = {
				same_liege = ROOT
				independent = no
				primary_title = { higher_tier_than = BARON }
				OR = {
					NOT = { has_character_flag = faction_undermine }
					had_character_flag = { flag = faction_undermine days = 1825 }
				}
				NOR = {
					is_liege_of = ROOT
					character = ROOT
					has_opinion_modifier = { who = liege modifier = opinion_coerced_into_leaving_faction }
				}
				OR = {
					AND = {
						OR = {
							leads_faction = faction_court
							in_faction = faction_court
						}
						liege = {
							any_vassal = {
								NOT = { character = PREVPREV }
								higher_tier_than = BARON
								OR = {
									leads_faction = faction_court
									in_faction = faction_court
								}
							}
						}
					}
					AND = {
						OR = {
							leads_faction = faction_prosperity
							in_faction = faction_prosperity
						}
						liege = {
							any_vassal = {
								NOT = { character = PREVPREV }
								higher_tier_than = BARON
								OR = {
									leads_faction = faction_prosperity
									in_faction = faction_prosperity
								}
							}
						}
					}
					AND = {
						OR = {
							leads_faction = faction_glory
							in_faction = faction_glory
						}
						liege = {
							any_vassal = {
								NOT = { character = PREVPREV }
								higher_tier_than = BARON
								OR = {
									leads_faction = faction_glory
									in_faction = faction_glory
								}
							}
						}
					}
					AND = {
						OR = {
							leads_faction = faction_tradition
							in_faction = faction_tradition
						}
						liege = {
							any_vassal = {
								NOT = { character = PREVPREV }
								higher_tier_than = BARON
								OR = {
									leads_faction = faction_tradition
									in_faction = faction_tradition
								}
							}
						}
					}
				}
			}
		}
		liege = {
			NOR = {
				has_character_flag = faction_court_war
				has_character_flag = faction_prosperity_war
				has_character_flag = faction_glory_war
				has_character_flag = faction_tradition_war
				has_character_flag = faction_pretender_war
				has_character_flag = faction_separatist_war
				has_character_flag = faction_religious_war
				has_character_flag = faction_succession_war
			}
		}
	}
	
	mean_time_to_happen = {
		months = 100	
		modifier = {
			factor = 1.2
			NOT = { intrigue = 2 }
		}
		modifier = {
			factor = 1.2
			NOT = { intrigue = 3 }
		}
		modifier = {
			factor = 1.2
			NOT = { intrigue = 4 }
		}
		modifier = {
			factor = 1.2
			NOT = { intrigue = 5 }
		}
		modifier = {
			factor = 1.2
			NOT = { intrigue = 6 }
		}
		modifier = {
			factor = 1.2
			NOT = { intrigue = 7 }
		}
		modifier = {
			factor = 1.2
			NOT = { intrigue = 8 }
		}
		modifier = {
			factor = 0.8
			intrigue = 10
		}
		modifier = {
			factor = 0.8
			intrigue = 12
		}
		modifier = {
			factor = 0.8
			intrigue = 14
		}
		modifier = {
			factor = 0.8
			intrigue = 16
		}
		modifier = {
			factor = 0.8
			intrigue = 18
		}
		modifier = {
			factor = 0.8
			intrigue = 20
		}
	}

	option = {
		name = EVTOPTA929 #Report it to the liege
		hidden_tooltip = {
			event_target:faction_member = { set_character_flag = faction_undermine }
		}
		liege = { letter_event = { id = PlusFaction.135 tooltip = INFORM_LIEGE_UNDERMINE } }
	}
	option = {
		name = EVTOPTB929 #Ignore it
		trigger = { ai = no }
		if = {
			limit = {
				NOT = { trait = diligent }
				NOT = { trait = slothful }
			}
			random = {
				chance = 50
				add_trait = slothful
			}
		}
		if = {
			limit = { trait = diligent }
			random = {
				chance = 50
				remove_trait = diligent
			}
		}
	}
}	


# 931: The Spymaster is attacked by a Noble's thugs (Gets away, Is wounded, Is maimed, Is killed)
character_event = {
	id = 931
	title = "EVTNAME931"
	desc = "EVTDESC931"
	picture = GFX_evt_peasants
	border = GFX_event_normal_frame_intrigue

	min_age = 16
	capable_only = yes
	prisoner = no
	
	trigger = {
		OR = {
			has_job_action = action_uncover_plots
			has_job_action = action_organize_spies_mystics
		}
		NOT = { has_character_modifier = in_seclusion }
		location = {
			any_province_lord = {
				NOT = { is_liege_of = ROOT }
				NOT = { character = ROOT }
				OR = {
					has_plot = plot_kill_character
					has_plot = plot_kill_spouse
					has_plot = plot_weaken_fellow_vassal
					has_plot = plot_gain_liege_title
					has_plot = plot_gain_fellow_vassal_title
				}
			}
		}
	}
	
	immediate = {
		location = {
			random_province_lord = {
				limit = {
					NOT = { is_liege_of = ROOT }
					NOT = { character = ROOT }
					OR = {
						has_plot = plot_kill_character
						has_plot = plot_kill_spouse
						has_plot = plot_weaken_fellow_vassal
						has_plot = plot_gain_liege_title
						has_plot = plot_gain_fellow_vassal_title
					}
				}
				save_event_target_as = killer_target
			}
		}
	}
	
	mean_time_to_happen = {
		months = 120
		
		modifier = {
			factor = 0.75
			NOT = { intrigue = 2 }
		}
		modifier = {
			factor = 0.75
			NOT = { intrigue = 3 }
		}
		modifier = {
			factor = 0.75
			NOT = { intrigue = 4 }
		}
		modifier = {
			factor = 0.75
			NOT = { intrigue = 5 }
		}
		modifier = {
			factor = 1.25
			intrigue = 10
		}
		modifier = {
			factor = 1.25
			intrigue = 11
		}
		modifier = {
			factor = 1.25
			intrigue = 12
		}
		modifier = {
			factor = 1.25
			intrigue = 13
		}
	}
	
	option = {
		name = "EVTOPTA902"
		trigger = {
			NOT = { martial = 5 }
		}
		random_list = {
			25 = { character_event = { id = 20310 tooltip = "EVTTOOLTIP20310" } }
			50 = { character_event = { id = 20311 tooltip = "EVTTOOLTIP20311" } }
			25 = {
				hidden_tooltip = {
					liege = { character_event = { id = 20313 } }
				}
				death = {
					death_reason = death_murder_unknown
					killer = event_target:killer_target
				}
			}
		}
	}
	option = {
		name = "EVTOPTA902"
		tooltip_info = martial
		trigger = {
			martial = 5
			NOT = { martial = 10 }
		}
		random_list = {
			35 = { character_event = { id = 20310 tooltip = "EVTTOOLTIP20310" } }
			50 = { character_event = { id = 20311 tooltip = "EVTTOOLTIP20311" } }
			15 = {
				hidden_tooltip = {
					liege = { character_event = { id = 20313 } }
				}
				death = {
					death_reason = death_murder_unknown
					killer = event_target:killer_target
				}
			}
		}
	}
	option = {
		name = "EVTOPTA902"
		tooltip_info = martial
		trigger = {
			martial = 10
		}
		random_list = {
			50 = { character_event = { id = 20310 tooltip = "EVTTOOLTIP20310" } }
			40 = { character_event = { id = 20311 tooltip = "EVTTOOLTIP20311" } }
			10 = {
				hidden_tooltip = {
					liege = { character_event = { id = 20313 } }
				}
				death = {
					death_reason = death_murder_unknown
					killer = event_target:killer_target
				}
			}
		}
	}
}

# 20310: Spymaster gets away
character_event = {
	id = 20310
	desc = "EVTDESC20310"
	picture = GFX_evt_courier
	border = GFX_event_normal_frame_intrigue
	
	is_triggered_only = yes
	
	option = {
		name = "EVTOPTA20310"
		prestige = -10
	}
}

# 20311: Spymaster gets wounded
character_event = {
	id = 20311
	desc = "EVTDESC20311"
	picture = GFX_evt_illness
	border = GFX_event_normal_frame_intrigue
	
	is_triggered_only = yes
	
	option = {
		name = "EVTOPTA20311"
		add_trait = wounded
		liege = { letter_event = { id = 20312 tooltip = "EVTTOOLTIP20022" } }
	}
}

# 20312: Inform the Liege about wounding
letter_event = {
	id = 20312
	desc = "EVTDESC20312"
	border = GFX_event_letter_frame_intrigue
	
	is_triggered_only = yes
	
	option = {
		name = "EVTOPTA20312"
		prestige = -10
	}
}

# 20313: Inform the Liege about death
character_event = {
	id = 20313
	desc = "EVTDESC20313"
	picture = GFX_evt_death
	border = GFX_event_normal_frame_intrigue
	
	is_triggered_only = yes
	
	option = {
		name = "EVTOPTA20313"
		prestige = -15
	}
}

## 9000: Faction Prevention - Spymaster finds Faction Member
character_event = {
	id = 9000
	title = "EVTNAME9000"
	desc = "EVTDESC9000"
	picture = GFX_evt_council
	border = GFX_event_normal_frame_intrigue
	
	min_age = 16
	capable_only = yes
	prisoner = no
	
	trigger = {
		OR = {
			has_job_action = action_uncover_plots
			has_job_action = action_organize_spies_mystics
		}
		NOT = { has_character_modifier = in_seclusion }
		location = {
			OR = {
				owner = {
					same_liege = ROOT
					independent = no
					NOT = { is_liege_of = ROOT }
					NOT = { character = ROOT }
					NOT = { trait = incapable }
					NOT = { has_opinion_modifier = { who = liege modifier = opinion_coerced_into_leaving_faction } }
					NOT = { has_character_flag = faction_member }
					age = 16
					prisoner = no
					primary_title = { higher_tier_than = BARON }
				}
				owner = {
					liege = { same_liege = ROOT }
					independent = no
					NOT = { is_liege_of = ROOT }
					NOT = { character = ROOT }
					liege = {
						independent = no
						NOT = { is_liege_of = ROOT }
						NOT = { character = ROOT }
						NOT = { trait = incapable }
						NOT = { has_opinion_modifier = { who = liege modifier = opinion_coerced_into_leaving_faction } }
						NOT = { has_character_flag = faction_member }
						age = 16
						prisoner = no
						primary_title = { higher_tier_than = BARON }
					}
				}
			}
		}
	}
	
	mean_time_to_happen = {
		months = 110
		
		modifier = {
			factor = 1.25
			NOT = { intrigue = 2 }
		}
		modifier = {
			factor = 1.25
			NOT = { intrigue = 3 }
		}
		modifier = {
			factor = 1.25
			NOT = { intrigue = 4 }
		}
		modifier = {
			factor = 1.25
			NOT = { intrigue = 5 }
		}
		modifier = {
			factor = 0.75
			intrigue = 10
		}
		modifier = {
			factor = 0.75
			intrigue = 11
		}
		modifier = {
			factor = 0.75
			intrigue = 12
		}
		modifier = {
			factor = 0.75
			intrigue = 13
		}
		modifier = {
			factor = 0.75
			intrigue = 16
		}
	}
	
	immediate = {
		IF = {
			limit = {
				location = {
					owner = {
						same_liege = ROOT
					}
				}
			}
			location = { owner = { set_character_flag = faction_member } }
		}
		IF = {
			limit = {
				location = {
					owner = {
						liege = { same_liege = ROOT }
					}
				}
			}
			location = { 
				owner = { liege = { set_character_flag = faction_member } }
			}
		}
	}
	
	option = {
		name = "EVTOPTA9000"
		liege = { letter_event = { id = 9001 tooltip = EVTTOOLTIP9001 } }
	}
}

# Liege is informed
letter_event = {
	id = 9001
	desc = "EVTDESC9001"
	border = GFX_event_letter_frame_intrigue
	
	is_triggered_only = yes
	
	option = { # Blackmail
		name = "EVTOPTA9001"
		trigger = {
			any_vassal = {
				has_character_flag = faction_member
				OR = {
					trait = homosexual
					trait = impaler
					trait = lustful
					trait = drunkard
					trait = hedonist
					trait = syphilitic
				}
			}
		}
		ai_chance = {
			factor = 10000
		}
		random_vassal = {
			limit = { has_character_flag = faction_member }
			letter_event = { id = 9002 tooltip = EVTTOOLTIP9002 }
		}	
	}
	option = { # Legalism
		name = "EVTOPTB9001"
		trigger = {
			any_vassal = {
				has_character_flag = faction_member
				OR = {
					trait = just
					trait = honest
					trait = trusting
					trait = content
					trait = kind
				}
			}
		}
		ai_chance = {
			factor = 10000
		}
		random_vassal = {
			limit = { has_character_flag = faction_member }
			letter_event = { id = 9005 tooltip = EVTTOOLTIP9005 }
		}	
	}
	option = { # Threaten
		name = "EVTOPTC9001"
		trigger = {
			any_vassal = {
				has_character_flag = faction_member
				OR = {
					trait = craven
					trait = paranoid
					trait = cynical
					trait = humble
					trait = slothful
				}
			}
		}
		ai_chance = {
			factor = 10000
		}
		random_vassal = {
			limit = { has_character_flag = faction_member }
			letter_event = { id = 9008 tooltip = EVTTOOLTIP9008 }
		}	
	}
	option = { # Ask Nicely
		name = "EVTOPTD9001"
		trigger = {
			any_vassal = {
				has_character_flag = faction_member
				NOT = {
					OR = {
						trait = craven
						trait = paranoid
						trait = cynical
						trait = humble
						trait = slothful
						trait = just
						trait = honest
						trait = trusting
						trait = content
						trait = kind
						trait = homosexual
						trait = impaler
						trait = lustful
						trait = drunkard
						trait = hedonist
						trait = syphilitic
					}
				}
			}
		}
		ai_chance = {
			factor = 100
		}
		random_vassal = {
			limit = { has_character_flag = faction_member }
			letter_event = { id = 9003 tooltip = EVTTOOLTIP9023 }
		}	
	}
	option = { # Do Nothing
		name = "EVTOPTE9001"
		ai_chance = {
			factor = 1
		}
		random_vassal = {
			limit = { has_character_flag = faction_member }
			clr_character_flag = faction_member
		}	
	}
}

# Faction Member Confronted: Blackmail
letter_event = {
	id = 9002
	desc = "EVTDESC9002"
	border = GFX_event_letter_frame_intrigue
	
	is_triggered_only = yes
	
	option = { # Agree (Homosexual)
		name = "EVTOPTA9002"
		tooltip_info = homosexual
		trigger = { trait = homosexual }
		FROM = {
			opinion = {
				modifier = opinion_pleased
				who = ROOT
				years = 2
			}
		}
		custom_tooltip = {
			text = EVTTOOLTIP9004
			hidden_tooltip = {
				FROM = {
					letter_event = { id = 9004 days = 7 }
				}
			}
		}
	}
	option = { # Agree (Impaler)
		name = "EVTOPTB9002"
		tooltip_info = impaler
		trigger = { trait = impaler }
		FROM = {
			opinion = {
				modifier = opinion_pleased
				who = ROOT
				years = 2
			}
		}
		custom_tooltip = {
			text = EVTTOOLTIP9004
			hidden_tooltip = {
				FROM = {
					letter_event = { id = 9004 days = 7 }
				}
			}
		}
	}
	option = { # Agree (Lustful)
		name = "EVTOPTC9002"
		tooltip_info = lustful
		trigger = { trait = lustful }
		FROM = {
			opinion = {
				modifier = opinion_pleased
				who = ROOT
				years = 2
			}
		}
		custom_tooltip = {
			text = EVTTOOLTIP9004
			hidden_tooltip = {
				FROM = {
					letter_event = { id = 9004 days = 7 }
				}
			}
		}
	}
	option = { # Agree (Drunkard)
		name = "EVTOPTD9002"
		tooltip_info = drunkard
		trigger = { trait = drunkard }
		FROM = {
			opinion = {
				modifier = opinion_pleased
				who = ROOT
				years = 2
			}
		}
		custom_tooltip = {
			text = EVTTOOLTIP9004
			hidden_tooltip = {
				FROM = {
					letter_event = { id = 9004 days = 7 }
				}
			}
		}
	}
	option = { # Agree (Hedonist)
		name = "EVTOPTE9002"
		tooltip_info = hedonist
		trigger = { trait = hedonist }
		FROM = {
			opinion = {
				modifier = opinion_pleased
				who = ROOT
				years = 2
			}
		}
		custom_tooltip = {
			text = EVTTOOLTIP9004
			hidden_tooltip = {
				FROM = {
					letter_event = { id = 9004 days = 7 }
				}
			}
		}
	}
	option = { # Agree (Syphilis)
		name = "EVTOPTF9002"
		tooltip_info = syphilitic
		trigger = { trait = syphilitic }
		FROM = {
			opinion = {
				modifier = opinion_pleased
				who = ROOT
				years = 2
			}
		}
		custom_tooltip = {
			text = EVTTOOLTIP9004
			hidden_tooltip = {
				FROM = {
					letter_event = { id = 9004 days = 7 }
				}
			}
		}
	}
}

# Faction Member Confronted: Ask Nicely
letter_event = {
	id = 9003
	desc = "EVTDESC9003"
	border = GFX_event_letter_frame_intrigue
	
	is_triggered_only = yes
	
	option = { # Agree
		name = "EVTOPTA9003"
		FROM = {
			opinion = {
				modifier = opinion_pleased
				who = ROOT
				years = 2
			}
		}
		custom_tooltip = {
			text = EVTTOOLTIP9004
			hidden_tooltip = {
				FROM = {
					letter_event = { id = 9007 days = 7 }
				}
			}
		}
	}
	option = { # Never!
		name = "EVTOPTB9003"
		FROM = {
			opinion = {
				modifier = opinion_angry
				who = ROOT
				years = 2
			}
		}
		custom_tooltip = {
			text = EVTTOOLTIP9003
			hidden_tooltip = {
				FROM = {
					letter_event = { id = 9006 days = 7 }
				}
			}
		}
	}
}

# Liege Informed: Successful Blackmail
letter_event = {
	id = 9004
	desc = "EVTDESC9004"
	border = GFX_event_letter_frame_intrigue
	
	is_triggered_only = yes
	
	option = {
		name = "EVTOPTA9004"
		FROM = {
			opinion = {
				modifier = opinion_coerced_into_leaving_faction
				who = ROOT
			}
			clr_character_flag = faction_member
		}
		custom_tooltip = { text = leaving_faction }
	}
}

# Faction Member Confronted: Legalism
letter_event = {
	id = 9005
	desc = "EVTDESC9005"
	border = GFX_event_letter_frame_intrigue
	
	is_triggered_only = yes
	
		option = { # Agree (Just)
		name = "EVTOPTA9005"
		tooltip_info = just
		trigger = { trait = just }
		FROM = {
			opinion = {
				modifier = opinion_pleased
				who = ROOT
				years = 2
			}
		}
		custom_tooltip = {
			text = EVTTOOLTIP9004
			hidden_tooltip = {
				FROM = {
					letter_event = { id = 9007 days = 7 }
				}
			}
		}
	}
	option = { # Agree (Honest)
		name = "EVTOPTB9005"
		tooltip_info = honest
		trigger = { trait = honest }
		FROM = {
			opinion = {
				modifier = opinion_pleased
				who = ROOT
				years = 2
			}
		}
		custom_tooltip = {
			text = EVTTOOLTIP9004
			hidden_tooltip = {
				FROM = {
					letter_event = { id = 9007 days = 7 }
				}
			}
		}
	}
	option = { # Agree (Trusting)
		name = "EVTOPTC9005"
		tooltip_info = trusting
		trigger = { trait = trusting }
		FROM = {
			opinion = {
				modifier = opinion_pleased
				who = ROOT
				years = 2
			}
		}
		custom_tooltip = {
			text = EVTTOOLTIP9004
			hidden_tooltip = {
				FROM = {
					letter_event = { id = 9007 days = 7 }
				}
			}
		}
	}
	option = { # Agree (Content)
		name = "EVTOPTD9005"
		tooltip_info = content
		trigger = { trait = content }
		FROM = {
			opinion = {
				modifier = opinion_pleased
				who = ROOT
				years = 2
			}
		}
		custom_tooltip = {
			text = EVTTOOLTIP9004
			hidden_tooltip = {
				FROM = {
					letter_event = { id = 9007 days = 7 }
				}
			}
		}
	}
	option = { # Agree (Kind)
		name = "EVTOPTE9005"
		tooltip_info = kind
		trigger = { trait = kind }
		FROM = {
			opinion = {
				modifier = opinion_pleased
				who = ROOT
				years = 2
			}
		}
		custom_tooltip = {
			text = EVTTOOLTIP9004
			hidden_tooltip = {
				FROM = {
					letter_event = { id = 9007 days = 7 }
				}
			}
		}
	}
}

# Liege Informed: Failed Request
letter_event = {
	id = 9006
	desc = "EVTDESC9006"
	border = GFX_event_letter_frame_intrigue
	
	is_triggered_only = yes
	
	option = {
		name = "EVTOPTA9006"
		FROM = {
			opinion = {
				modifier = opinion_angry
				who = ROOT
				years = 2
			}
			clr_character_flag = faction_member
		}
	}
}

# Liege Informed: Successful Legalism
letter_event = {
	id = 9007
	desc = "EVTDESC9007"
	border = GFX_event_letter_frame_intrigue
	
	is_triggered_only = yes
	
	option = {
		name = "EVTOPTA9007"
		FROM = {
			opinion = {
				modifier = opinion_coerced_into_leaving_faction
				who = ROOT
			}
			clr_character_flag = faction_member
		}
		custom_tooltip = { text = leaving_faction }
	}
}

# Faction Member Confronted: Threaten
letter_event = {
	id = 9008
	desc = "EVTDESC9008"
	border = GFX_event_letter_frame_intrigue
	
	is_triggered_only = yes
	
		option = { # Agree (Craven)
		name = "EVTOPTA9008"
		tooltip_info = craven
		trigger = { trait = craven }
		FROM = {
			opinion = {
				modifier = opinion_pleased
				who = ROOT
				years = 2
			}
		}
		custom_tooltip = {
			text = EVTTOOLTIP9004
			hidden_tooltip = {
				FROM = {
					letter_event = { id = 9010 days = 7 }
				}
			}
		}
	}
	option = { # Agree (Paranoid)
		name = "EVTOPTB9008"
		tooltip_info = paranoid
		trigger = { trait = paranoid }
		FROM = {
			opinion = {
				modifier = opinion_pleased
				who = ROOT
				years = 2
			}
		}
		custom_tooltip = {
			text = EVTTOOLTIP9004
			hidden_tooltip = {
				FROM = {
					letter_event = { id = 9010 days = 7 }
				}
			}
		}
	}
	option = { # Agree (Cynical)
		name = "EVTOPTC9008"
		tooltip_info = cynical
		trigger = { trait = cynical }
		FROM = {
			opinion = {
				modifier = opinion_pleased
				who = ROOT
				years = 2
			}
		}
		custom_tooltip = {
			text = EVTTOOLTIP9004
			hidden_tooltip = {
				FROM = {
					letter_event = { id = 9010 days = 7 }
				}
			}
		}
	}
	option = { # Agree (Humble)
		name = "EVTOPTD9008"
		tooltip_info = humble
		trigger = { trait = humble }
		FROM = {
			opinion = {
				modifier = opinion_pleased
				who = ROOT
				years = 2
			}
		}
		custom_tooltip = {
			text = EVTTOOLTIP9004
			hidden_tooltip = {
				FROM = {
					letter_event = { id = 9010 days = 7 }
				}
			}
		}
	}
	option = { # Agree (Slothful)
		name = "EVTOPTE9008"
		tooltip_info = slothful
		trigger = { trait = slothful }
		FROM = {
			opinion = {
				modifier = opinion_pleased
				who = ROOT
				years = 2
			}
		}
		custom_tooltip = {
			text = EVTTOOLTIP9004
			hidden_tooltip = {
				FROM = {
					letter_event = { id = 9010 days = 7 }
				}
			}
		}
	}
}

# Liege Informed: Successful Threat
letter_event = {
	id = 9010
	desc = "EVTDESC9010"
	border = GFX_event_letter_frame_intrigue
	
	is_triggered_only = yes
	
	option = {
		name = "EVTOPTA9010"
		FROM = {
			opinion = {
				modifier = opinion_coerced_into_leaving_faction
				who = ROOT
			}
			clr_character_flag = faction_member
		}
		custom_tooltip = { text = leaving_faction }
	}
}

### 9020: Faction Recruitment - Spymaster finds Faction Member
character_event = {
	id = 9020
	title = "EVTNAME9020"
	desc = "EVTDESC9020"
	picture = GFX_evt_council
	border = GFX_event_normal_frame_intrigue
	
	min_age = 16
	capable_only = yes
	prisoner = no
	
	trigger = {
		OR = {
			has_job_action = action_uncover_plots
			has_job_action = action_organize_spies_mystics
		}
		NOT = { has_character_modifier = in_seclusion }
		liege = { in_faction = yes }
		location = {
			owner = {
				ROOT = {
					liege = {
						same_liege = PREVPREV
					}
				}
				ai = yes
				independent = no
				NOT = { is_liege_of = ROOT }
				NOT = { character = ROOT }
				NOT = { trait = incapable }
				ROOT = {
					liege = {
						NOT = { reverse_has_opinion_modifier = { who = PREVPREV modifier = opinion_coerced_into_joining_faction } }
					}
				}
				NOT = { has_character_flag = faction_recruit }
				in_faction = no
				age = 16
				prisoner = no
				primary_title = { higher_tier_than = BARON }
			}
		}
	}
	
	mean_time_to_happen = {
		months = 110
		
		modifier = {
			factor = 1.25
			NOT = { intrigue = 2 }
		}
		modifier = {
			factor = 1.25
			NOT = { intrigue = 3 }
		}
		modifier = {
			factor = 1.25
			NOT = { intrigue = 4 }
		}
		modifier = {
			factor = 1.25
			NOT = { intrigue = 5 }
		}
		modifier = {
			factor = 0.75
			intrigue = 10
		}
		modifier = {
			factor = 0.75
			intrigue = 11
		}
		modifier = {
			factor = 0.75
			intrigue = 12
		}
		modifier = {
			factor = 0.75
			intrigue = 13
		}
		modifier = {
			factor = 0.75
			intrigue = 16
		}
	}
	
	immediate = {
		location = { owner = { set_character_flag = faction_recruit } }
	}
	
	option = {
		name = "EVTOPTA9020"
		liege = { letter_event = { id = 9021 tooltip = EVTTOOLTIP9001 } }
	}
}

# Liege is informed
letter_event = {
	id = 9021
	desc = EVTDESC9021
	border = GFX_event_letter_frame_intrigue
	
	is_triggered_only = yes
	
	option = { # Blackmail
		name = EVTOPTA9021
		trigger = {
			liege = {
				any_vassal = {
					has_character_flag = faction_recruit
					OR = {
						trait = homosexual
						trait = impaler
						trait = lustful
						trait = drunkard
						trait = hedonist
						trait = syphilitic
					}
				}
			}
		}
		liege = {
			any_vassal = {
				limit = { has_character_flag = faction_recruit }
				letter_event = { id = 9022 tooltip = EVTTOOLTIP9022 }
			}
		}
	}
	option = { # Threaten
		name = "EVTOPTC9021"
		trigger = {
			liege = {
				any_vassal = {
					has_character_flag = faction_recruit
					OR = {
						trait = craven
						trait = paranoid
						trait = cynical
						trait = humble
						trait = slothful
					}
				}
			}
		}
		liege = {
			any_vassal = {
				limit = { has_character_flag = faction_recruit }
				letter_event = { id = 9028 tooltip = EVTTOOLTIP9028 }
			}
		}
	}
	option = { # Ask nicely
		name = "EVTOPTD9001"
		trigger = {
			liege = {
				any_vassal = {
					has_character_flag = faction_recruit
					NOT = {
						OR = {
							trait = craven
							trait = paranoid
							trait = cynical
							trait = humble
							trait = slothful
							trait = homosexual
							trait = impaler
							trait = lustful
							trait = drunkard
							trait = hedonist
							trait = syphilitic
						}
					}
				}
			}
		}
		liege = {
			any_vassal = {
				limit = { has_character_flag = faction_recruit }
				letter_event = { id = 9023 tooltip = EVTTOOLTIP9023 }
			}
		}
	}
	option = { # Do Nothing
		name = "EVTOPTD9021"
		liege = {
			any_vassal = {
				limit = { has_character_flag = faction_recruit }
				clr_character_flag = faction_recruit
			}
		}
	}
}

# Faction Member Confronted: Blackmail
letter_event = {
	id = 9022
	desc = EVTDESC9002
	border = GFX_event_letter_frame_intrigue
	
	is_triggered_only = yes
	
	option = { # Agree (Homosexual)
		name = EVTOPTA9002
		tooltip_info = homosexual
		trigger = { trait = homosexual }
		FROM = {
			opinion = {
				modifier = opinion_pleased
				who = ROOT
				years = 2
			}
		}
		custom_tooltip = {
			text = EVTTOOLTIP9004
			hidden_tooltip = {
				FROM = {
					letter_event = { id = 9024 days = 7 }
				}
			}
		}
	}
	option = { # Agree (Impaler)
		name = EVTOPTB9002
		tooltip_info = impaler
		trigger = { trait = impaler }
		FROM = {
			opinion = {
				modifier = opinion_pleased
				who = ROOT
				years = 2
			}
		}
		custom_tooltip = {
			text = EVTTOOLTIP9004
			hidden_tooltip = {
				FROM = {
					letter_event = { id = 9024 days = 7 }
				}
			}
		}
	}
	option = { # Agree (Lustful)
		name = EVTOPTC9002
		tooltip_info = lustful
		trigger = { trait = lustful }
		FROM = {
			opinion = {
				modifier = opinion_pleased
				who = ROOT
				years = 2
			}
		}
		custom_tooltip = {
			text = EVTTOOLTIP9004
			hidden_tooltip = {
				FROM = {
					letter_event = { id = 9024 days = 7 }
				}
			}
		}
	}
	option = { # Agree (Drunkard)
		name = EVTOPTD9002
		tooltip_info = drunkard
		trigger = { trait = drunkard }
		FROM = {
			opinion = {
				modifier = opinion_pleased
				who = ROOT
				years = 2
			}
		}
		custom_tooltip = {
			text = EVTTOOLTIP9004
			hidden_tooltip = {
				FROM = {
					letter_event = { id = 9024 days = 7 }
				}
			}
		}
	}
	option = { # Agree (Hedonist)
		name = EVTOPTE9002
		tooltip_info = hedonist
		trigger = { trait = hedonist }
		FROM = {
			opinion = {
				modifier = opinion_pleased
				who = ROOT
				years = 2
			}
		}
		custom_tooltip = {
			text = EVTTOOLTIP9004
			hidden_tooltip = {
				FROM = {
					letter_event = { id = 9024 days = 7 }
				}
			}
		}
	}
	option = { # Agree (Syphilis)
		name = EVTOPTF9002
		tooltip_info = syphilitic
		trigger = { trait = syphilitic }
		FROM = {
			opinion = {
				modifier = opinion_pleased
				who = ROOT
				years = 2
			}
		}
		custom_tooltip = { 
			text = EVTTOOLTIP9004
			hidden_tooltip = {
				FROM = {
					letter_event = { id = 9024 days = 7 }
				}
			}
		}
	}
}

# Faction Member Confronted: Ask Nicely (AI Only)
letter_event = {
	id = 9023
	desc = EVTDESC9003
	border = GFX_event_letter_frame_intrigue
	
	is_triggered_only = yes
	
	option = { # Agree
		name = EVTOPTA9004
		FROM = {
			opinion = {
				modifier = opinion_pleased
				who = ROOT
				years = 2
			}
		}
		hidden_tooltip = {
			FROM = {
				letter_event = { id = 9027 days = 7 }
			}
		}
	}
	option = { # Never!
		name = EVTOPTA9004
		FROM = {
			opinion = {
				modifier = opinion_angry
				who = ROOT
				years = 2
			}
		}
		hidden_tooltip = {
			FROM = {
				letter_event = { id = 9026 days = 7 }
			}
		}
	}
}

# Liege Informed: Successful Request
letter_event = {
	id = 9027
	desc = EVTDESC9027
	border = GFX_event_letter_frame_intrigue
	
	is_triggered_only = yes
	
	option = {
		name = EVTOPTA9004
		FROM = {
			opinion = {
				modifier = opinion_coerced_into_joining_faction
				who = ROOT
			}
			clr_character_flag = faction_recruit
		}
		custom_tooltip = { text = joining_faction }
	}
}

# Liege Informed: Successful Blackmail
letter_event = {
	id = 9024
	desc = EVTDESC9024
	border = GFX_event_letter_frame_intrigue
	
	is_triggered_only = yes
	
	option = {
		name = EVTOPTA9004
		FROM = {
			opinion = {
				modifier = opinion_coerced_into_joining_faction
				who = ROOT
			}
			clr_character_flag = faction_recruit
		}
		custom_tooltip = { text = joining_faction }
	}
}

# Liege Informed: Failed Request
letter_event = {
	id = 9026
	desc = "EVTDESC9026"
	border = GFX_event_letter_frame_intrigue
	
	is_triggered_only = yes
	
	option = {
		name = "EVTOPTA9006"
		FROM = {
			opinion = {
				modifier = opinion_angry
				who = ROOT
				years = 2
			}
			clr_character_flag = faction_recruit
		}
	}
}

# Faction Member Confronted: Threaten
letter_event = {
	id = 9028
	desc = "EVTDESC9008"
	border = GFX_event_letter_frame_intrigue
	
	is_triggered_only = yes
	
	option = { # Agree (Paranoid)
		name = "EVTOPTB9008"
		tooltip_info = paranoid
		trigger = { trait = paranoid }
		FROM = {
			opinion = {
				modifier = opinion_pleased
				who = ROOT
				years = 2
			}
		}
		custom_tooltip = {
			text = EVTTOOLTIP9004
			hidden_tooltip = {
				FROM = {
					letter_event = { id = 9030 days = 7 }
				}
			}
		}
	}
	option = { # Agree (Cynical)
		name = "EVTOPTC9008"
		tooltip_info = cynical
		trigger = { trait = cynical }
		FROM = {
			opinion = {
				modifier = opinion_pleased
				who = ROOT
				years = 2
			}
		}
		custom_tooltip = {
			text = EVTTOOLTIP9004
			hidden_tooltip = {
				FROM = {
					letter_event = { id = 9030 days = 7 }
				}
			}
		}
	}
	option = { # Agree (Humble)
		name = "EVTOPTD9008"
		tooltip_info = humble
		trigger = { trait = humble }
		FROM = {
			opinion = {
				modifier = opinion_pleased
				who = ROOT
				years = 2
			}
		}
		custom_tooltip = {
			text = EVTTOOLTIP9004
			hidden_tooltip = {
				FROM = {
					letter_event = { id = 9030 days = 7 }
				}
			}
		}
	}
	option = { # Agree (Slothful)
		name = "EVTOPTE9008"
		tooltip_info = slothful
		trigger = { trait = slothful }
		FROM = {
			opinion = {
				modifier = opinion_pleased
				who = ROOT
				years = 2
			}
		}
		custom_tooltip = {
			text = EVTTOOLTIP9004
			hidden_tooltip = {
				FROM = {
					letter_event = { id = 9030 days = 7 }
				}
			}
		}
	}
}

# Liege Informed: Successful Threat
letter_event = {
	id = 9030
	desc = "EVTDESC9030"
	border = GFX_event_letter_frame_intrigue
	
	is_triggered_only = yes
	
	option = {
		name = "EVTOPTA9030"
		FROM = {
			opinion = {
				modifier = opinion_coerced_into_joining_faction
				who = ROOT
			}
			clr_character_flag = faction_recruit
		}
		custom_tooltip = { text = joining_faction }
	}
}

	
##############################
# SPYMASTER
# JOB: action_study_technology
##############################

# 932: The Spymaster studies foreign technology
character_event = {
	id = 932
	title = "EVTNAME932"
	desc = "EVTDESC932"
	picture = GFX_evt_library
	border = GFX_event_normal_frame_intrigue

	min_age = 16
	capable_only = yes
	prisoner = no

	trigger = {
		has_job_action = action_study_technology
		NOT = { has_character_modifier = in_seclusion }
		location = { has_higher_tech_than = ROOT }
	}

	mean_time_to_happen = {
		months = 240
		modifier = {
			factor = 0.5
			OR = {
				has_focus = focus_scholarship
				liege = { has_focus = focus_scholarship }
			}
		}
		modifier = {
			factor = 1.1
			NOT = { opinion = { who = liege value = -100 } }
		}
		modifier = {
			factor = 1.1
			NOT = { opinion = { who = liege value = -75 } }
		}
		modifier = {
			factor = 1.1
			NOT = { opinion = { who = liege value = -50 } }
		}
		modifier = {
			factor = 1.1
			NOT = { opinion = { who = liege value = -25 } }
		}
		modifier = {
			factor = 0.95
			opinion = { who = liege value = 25 }
		}
		modifier = {
			factor = 0.95
			opinion = { who = liege value = 50 }
		}
		modifier = {
			factor = 0.95
			opinion = { who = liege value = 75 }
		}
		modifier = {
			factor = 0.95
			opinion = { who = liege value = 100 }
		}
		modifier = {
			factor = 1.05
			NOT = { intrigue = 1 }
		}
		modifier = {
			factor = 1.05
			NOT = { intrigue = 2 }
		}
		modifier = {
			factor = 1.05
			NOT = { intrigue = 3 }
		}
		modifier = {
			factor = 1.05
			NOT = { intrigue = 4 }
		}
		modifier = {
			factor = 1.05
			NOT = { intrigue = 5 }
		}
		modifier = {
			factor = 1.05
			NOT = { intrigue = 6 }
		}
		modifier = {
			factor = 1.05
			NOT = { intrigue = 7 }
		}
		modifier = {
			factor = 1.05
			NOT = { intrigue = 8 }
		}
		modifier = {
			factor = 1.05
			NOT = { intrigue = 9 }
		}
		modifier = {
			factor = 0.95
			intrigue = 10
		}
		modifier = {
			factor = 0.95
			intrigue = 11
		}
		modifier = {
			factor = 0.95
			intrigue = 12
		}
		modifier = {
			factor = 0.95
			intrigue = 13
		}
		modifier = {
			factor = 0.95
			intrigue = 14
		}
		modifier = {
			factor = 0.95
			intrigue = 15
		}
		modifier = {
			factor = 0.95
			intrigue = 16
		}
		modifier = {
			factor = 0.95
			intrigue = 17
		}
		modifier = {
			factor = 0.95
			intrigue = 18
		}
	}

	option = {
		name = "EVTOPTA932"
		liege = { letter_event = { id = 20320 tooltip = "EVTTOOLTIP20320" } }
	}
}

# The Spymaster informs his liege of the success
letter_event = {
	id = 20320
	desc = "EVTDESC20320"
	border = GFX_event_letter_frame_intrigue

	is_triggered_only = yes

	option = {
		name = "EVTOPTA20320"
		random_list = {
			33 = { military_techpoints = 50 }
			33 = { economy_techpoints = 50 }
			33 = { culture_techpoints = 50 }
		}
		if = {
			limit = {
				has_dlc = "Reapers"
			}
			custom_tooltip = {
				text = capital_prospers_custom_tooltip
				hidden_tooltip = {
					capital_scope = {
						change_variable = { which = prosperity_value value = 6 }
					}
				}
			}
		}
	}
}

# 933: The Spymaster is discovered by the local count - chance of imprisonment
character_event = {
	id = 933
	title = "EVTNAME933"
	desc = "EVTDESC933"
	picture = GFX_evt_spymaster
	border = GFX_event_normal_frame_intrigue

	min_age = 16
	capable_only = yes
	prisoner = no

	trigger = {
		OR = {
			has_job_action = action_study_technology
			has_job_action = action_sabotage_province
		}
		OR = {
			location = { has_higher_tech_than = ROOT }
			has_job_action = action_sabotage_province
		}
		NOT = { has_character_modifier = in_seclusion }
		location = {
			any_province_lord = {
				NOT = { is_liege_of = ROOT }
				NOT = { character = ROOT }
				OR = {
					intrigue = 10
					job_spymaster = {
						intrigue = 10
					}
				}
			}
		}
	}

	mean_time_to_happen = {
		months = 360

		modifier = {
			factor = 0.75
			NOT = { intrigue = 2 }
		}
		modifier = {
			factor = 0.75
			NOT = { intrigue = 3 }
		}
		modifier = {
			factor = 0.75
			NOT = { intrigue = 4 }
		}
		modifier = {
			factor = 0.75
			NOT = { intrigue = 5 }
		}
		modifier = {
			factor = 1.25
			intrigue = 10
		}
		modifier = {
			factor = 1.25
			intrigue = 11
		}
		modifier = {
			factor = 1.25
			intrigue = 12
		}
		modifier = {
			factor = 1.25
			intrigue = 13
		}
	}

	option = {
		name = "EVTOPTA933"
		location = {
			random_province_lord = {
				limit = {
					NOT = { is_liege_of = ROOT }
					NOT = { character = ROOT }
					job_spymaster = {
						intrigue = 10
					}
				}
				character_event = { id = 20330 days = 2 tooltip = "EVTTOOLTIP20330" }
			}
		}
	}
}

#20330: Local noble reacts
character_event = {
	id = 20330
	desc = "EVTDESC20330"
	picture = GFX_evt_spymaster
	border = GFX_event_normal_frame_intrigue

	is_triggered_only = yes

	option = {
		name = "EVOPTA20330"
		ai_chance = { factor = 75 }
		FROM = {
			imprison = ROOT
			liege = {
				letter_event = { id = 20331 tooltip = "EVTTOOLTIP20331" }
				opinion = {
					modifier = opinion_furious
					who = ROOT
					years = 2
				}
			}
		}
	}
	option = {
		name = "EVOPTB20330"
		ai_chance = {
			factor = 25
			modifier = {
				factor = 0
				FROM = { has_character_flag = spymaster_found_spying }
			}
		}
		prestige = 15
		FROM = {
			set_character_flag = spymaster_found_spying
			letter_event = { id = 20332 days = 7 tooltip = "EVTTOOLTIP20332" }
		}
	}
}

#20331: Liege get the news - Chancellor Imprisoned
letter_event = {
	id = 20331
	desc = "EVTDESC20331"
	border = GFX_event_letter_frame_intrigue

	is_triggered_only = yes

	option = {
		name = "EVTOPTA20331"
		FROM = {
			opinion = {
				modifier = opinion_dishonorable_scum
				who = ROOT
				years = 2
			}
		}
	}
}

#20332: Spymaster get the news: is free to go
letter_event = {
	id = 20332
	desc = "EVTDESC20332"
	border = GFX_event_letter_frame_intrigue

	is_triggered_only = yes

	option = {
		name = "EVTOPTA20332"
		reverse_opinion = {
			modifier = opinion_grateful
			who = FROM
			years = 5
		}
	}
}

##############################
# SPYMASTER
# JOB: action_organize_spies
##############################

# 935: Building spy network value
character_event = {
	id = 935
	title = EVTNAME935
	desc = EVTDESC935
	picture = GFX_evt_spymaster
	border = GFX_event_normal_frame_intrigue
	
	min_age = 16
	capable_only = yes
	prisoner = no
	
	trigger = {
		OR = {
			has_job_action = action_organize_spies
			has_job_action = action_organize_spies_mystics
		}
		NOT = { has_character_modifier = in_seclusion }
	}
	
	mean_time_to_happen = {
		months = 180
		modifier = {
			factor = 1.5
			liege = { is_tribal = yes }
		}
		modifier = {
			factor = 2.0
			liege = { is_nomadic = yes }
		}
		modifier = {
			factor = 1.2
			NOT = { intrigue = 2 }
		}
		modifier = {
			factor = 1.2
			NOT = { intrigue = 3 }
		}
		modifier = {
			factor = 1.2
			NOT = { intrigue = 4 }
		}
		modifier = {
			factor = 1.2
			NOT = { intrigue = 5 }
		}
		modifier = {
			factor = 1.2
			NOT = { intrigue = 6 }
		}
		modifier = {
			factor = 1.2
			NOT = { intrigue = 7 }
		}
		modifier = {
			factor = 1.2
			NOT = { intrigue = 8 }
		}
		modifier = {
			factor = 0.8
			intrigue = 10
		}
		modifier = {
			factor = 0.8
			intrigue = 12
		}
		modifier = {
			factor = 0.8
			intrigue = 14
		}
		modifier = {
			factor = 0.8
			intrigue = 16
		}
		modifier = {
			factor = 0.8
			intrigue = 18
		}
		modifier = {
			factor = 0.8
			intrigue = 20
		}
		modifier = {
			factor = 1.1
			liege = { NOT = { intrigue = 2 } }
		}
		modifier = {
			factor = 1.1
			liege = { NOT = { intrigue = 4 } }
		}
		modifier = {
			factor = 1.1
			liege = { NOT = { intrigue = 6 } }
		}
		modifier = {
			factor = 1.1
			liege = { NOT = { intrigue = 8 } }
		}
		modifier = {
			factor = 0.9
			liege = { intrigue = 10 }
		}
		modifier = {
			factor = 0.9
			liege = { intrigue = 12 }
		}
		modifier = {
			factor = 0.9
			liege = { intrigue = 14 }
		}
		modifier = {
			factor = 0.9
			liege = { intrigue = 16 }
		}
		modifier = {
			factor = 0.9
			liege = { intrigue = 18 }
		}
		modifier = {
			factor = 0.9
			liege = { intrigue = 20 }
		}
		modifier = {
			factor = 0.8
			trait = schemer
		}
		modifier = {
			factor = 0.9
			OR = {
				trait = quick
				trait = shrewd
			}
		}
		modifier = {
			factor = 0.8
			trait = genius
		}
		modifier = {
			factor = 0.9
			trait = patient
		}
		modifier = {
			factor = 0.9
			trait = diligent
		}
		modifier = {
			factor = 1.1
			trait = slothful
		}
		modifier = {
			factor = 0.9
			trait = deceitful
		}
		modifier = {
			factor = 1.1
			trait = honest
		}
		modifier = {
			factor = 0.9
			trait = paranoid
		}
		modifier = {
			factor = 1.1
			trait = trusting
		}
		modifier = {
			factor = 0.8
			liege = { NOT = { check_variable = { which = "personal_spy_network" value = 10 } } }
		}
		modifier = {
			factor = 1.2
			liege = { check_variable = { which = "personal_spy_network" value = 20 } }
		}
		modifier = {
			factor = 1.2
			liege = { check_variable = { which = "personal_spy_network" value = 30 } }
		}
		modifier = {
			factor = 1.2
			liege = { check_variable = { which = "personal_spy_network" value = 40 } }
		}
		modifier = {
			factor = 1.2
			liege = { check_variable = { which = "personal_spy_network" value = 50 } }
		}
		modifier = {
			factor = 1.4
			liege = { check_variable = { which = "personal_spy_network" value = 60 } }
		}
		modifier = {
			factor = 1.4
			liege = { check_variable = { which = "personal_spy_network" value = 70 } }
		}
		modifier = {
			factor = 1.4
			liege = { check_variable = { which = "personal_spy_network" value = 80 } }
		}
		modifier = {
			factor = 2.0
			liege = { check_variable = { which = "personal_spy_network" value = 90 } }
		}
	}

	option = {
		name = EXCELLENT
		set_character_flag = has_personal_spy_network
		custom_tooltip = {
			text = SPYNETWORK_INCREASE_5
			hidden_tooltip = { change_variable = { which = "personal_spy_network" value = 5 } }
		}
		liege = {
			custom_tooltip = { text = SPYNETWORK_INCREASE_10_LIEGE }
			hidden_tooltip = { character_event = { id = 20350 } }
		}
	}
}

# 20350: Liege informed of network increase
character_event = {
	id = 20350
	desc = EVTDESC20350
	picture = GFX_evt_spymaster

	is_triggered_only = yes
	notification = yes
	
	immediate = {
		set_character_flag = has_personal_spy_network
		change_variable = { which = "personal_spy_network" value = 10 }
	}
	
	option = {
		name = OK
	}
}

# 936: Spy Network setback
character_event = {
	id = 936
	title = EVTNAME936
	desc = EVTDESC936
	picture = GFX_evt_spymaster
	border = GFX_event_normal_frame_intrigue
	
	min_age = 16
	capable_only = yes
	prisoner = no
	
	trigger = {
		OR = {
			has_job_action = action_organize_spies
			has_job_action = action_organize_spies_mystics
		}		
		liege = { check_variable = { which = "personal_spy_network" value = 9 } }
		NOT = { has_character_modifier = in_seclusion }
	}
	
	mean_time_to_happen = {
		months = 320
		modifier = {
			factor = 0.8
			NOT = { intrigue = 2 }
		}
		modifier = {
			factor = 0.8
			NOT = { intrigue = 4 }
		}
		modifier = {
			factor = 0.8
			NOT = { intrigue = 6 }
		}
		modifier = {
			factor = 0.8
			NOT = { intrigue = 8 }
		}
		modifier = {
			factor = 1.2
			intrigue = 10
		}
		modifier = {
			factor = 1.2
			intrigue = 12
		}
		modifier = {
			factor = 1.2
			intrigue = 14
		}
		modifier = {
			factor = 1.2
			intrigue = 16
		}
		modifier = {
			factor = 1.2
			intrigue = 18
		}
		modifier = {
			factor = 1.2
			intrigue = 20
		}
		modifier = {
			factor = 0.9
			liege = { NOT = { intrigue = 2 } }
		}
		modifier = {
			factor = 0.9
			liege = { NOT = { intrigue = 4 } }
		}
		modifier = {
			factor = 0.9
			liege = { NOT = { intrigue = 6 } }
		}
		modifier = {
			factor = 0.9
			liege = { NOT = { intrigue = 8 } }
		}
		modifier = {
			factor = 1.1
			liege = { intrigue = 10 }
		}
		modifier = {
			factor = 1.1
			liege = { intrigue = 12 }
		}
		modifier = {
			factor = 1.1
			liege = { intrigue = 14 }
		}
		modifier = {
			factor = 1.1
			liege = { intrigue = 16 }
		}
		modifier = {
			factor = 1.1
			liege = { intrigue = 18 }
		}
		modifier = {
			factor = 1.1
			liege = { intrigue = 20 }
		}
		modifier = {
			factor = 1.2
			trait = schemer
		}
		modifier = {
			factor = 1.1
			OR = {
				trait = quick
				trait = shrewd
			}
		}
		modifier = {
			factor = 1.2
			trait = genius
		}
		modifier = {
			factor = 1.1
			trait = patient
		}
		modifier = {
			factor = 1.1
			trait = diligent
		}
		modifier = {
			factor = 0.9
			trait = slothful
		}
		modifier = {
			factor = 1.1
			trait = deceitful
		}
		modifier = {
			factor = 0.9
			trait = honest
		}
		modifier = {
			factor = 1.1
			trait = paranoid
		}
		modifier = {
			factor = 0.9
			trait = trusting
		}
		modifier = {
			factor = 0.9
			liege = { check_variable = { which = "personal_spy_network" value = 20 } }
		}
		modifier = {
			factor = 0.9
			liege = { check_variable = { which = "personal_spy_network" value = 40 } }
		}
		modifier = {
			factor = 0.8
			liege = { check_variable = { which = "personal_spy_network" value = 60 } }
		}
		modifier = {
			factor = 0.8
			liege = { check_variable = { which = "personal_spy_network" value = 80 } }
		}
		modifier = {
			factor = 0.5
			liege = { check_variable = { which = "personal_spy_network" value = 90 } }
		}
	}

	option = {
		name = CURSES
		if = {
			limit = { check_variable = { which = "personal_spy_network" value = 1 } }
			custom_tooltip = {
				text = SPYNETWORK_DECREASE_5
				hidden_tooltip = { change_variable = { which = "personal_spy_network" value = -5 } }
			}
		}
		if = {
			limit = { NOT = { check_variable = { which = "personal_spy_network" value = 1 } } }
			hidden_tooltip = {
				set_variable = { which = "personal_spy_network" value = 0 }
				clr_character_flag = has_personal_spy_network
			}
		}
		liege = {
			custom_tooltip = { text = SPYNETWORK_DECREASE_10_LIEGE }
			hidden_tooltip = { letter_event = { id = 20352 } }
		}
	}
}

# 20352: Liege informed of network decrease
letter_event = {
	id = 20352
	desc = EVTDESC20352
	border = GFX_event_letter_frame_intrigue

	is_triggered_only = yes
	
	immediate = {
		change_variable = { which = "personal_spy_network" value = -10 }
		if = {
			limit = { NOT = { check_variable = { which = "personal_spy_network" value = 1 } } }
			hidden_tooltip = {
				set_variable = { which = "personal_spy_network" value = 0 }
				clr_character_flag = has_personal_spy_network
			}
		}
	}
	
	option = {
		name = CURSES
		custom_tooltip = { text = SPYNETWORK_DECREASE_10 }
	}
}

# 20354: Remove Spy Network from invalid characters
character_event = {
	id = 20354
	
	hide_window = yes
	has_character_flag = has_personal_spy_network
	
	trigger = {
		OR = {
			NOT = { check_variable = { which = "personal_spy_network" value = 1 } }
			NOR = {
				is_ruler = yes
				has_job_title = job_spymaster
				intrigue = 12
			}
		}
	}
	
	mean_time_to_happen = {
		months = 6
	}
	
	immediate = {
		clr_character_flag = has_personal_spy_network
		set_variable = { which = "personal_spy_network" value = 0 }
	}
}

# 20355: Heir inherits half of the spy network value
character_event = {
	id = 20355
	
	hide_window = yes
	is_triggered_only = yes

	has_character_flag = has_personal_spy_network
	
	trigger = {
		check_variable = { which = "personal_spy_network" value = 9 }
		has_character_flag = has_personal_spy_network
	}
	
	immediate = {
		multiply_variable = { which = "personal_spy_network" value = 0.5 }
		if = {
			limit = { is_ruler = yes }
			current_heir = {
				set_character_flag = has_personal_spy_network
				change_variable = { which = "personal_spy_network" which = ROOT }
			}
		}
		if = {
			limit = { is_ruler = no }
			random_child = {
				limit = {
					NOT = { trait = bastard }
					OR = {
						is_female = no
						liege = { has_law = true_cognatic_succession }
						liege = { has_law = enatic_succession }
						liege = { has_law = enatic_cognatic_succession }
						AND = {
							liege = { has_law = cognatic_succession }
							NOT = {
								any_sibling = {
									is_female = no
									NOT = { trait = bastard }
								}
							}
						}
					}
					OR = {
						is_female = yes
						liege = { has_law = agnatic_succession }
						liege = { has_law = cognatic_succession }
						liege = { has_law = true_cognatic_succession }
						AND = {
							liege = { has_law = enatic_cognatic_succession }
							NOT = {
								any_sibling = {
									is_female = yes
									NOT = { trait = bastard }
								}
							}
						}
					}
					NOT = {
						any_sibling = {
							is_older_than = PREV
							NOT = { trait = bastard }
							OR = {
								is_female = no
								ROOT = { liege = { has_law = true_cognatic_succession } }
								ROOT = { liege = { has_law = enatic_succession } }
								ROOT = { liege = { has_law = enatic_cognatic_succession } }
								AND = {
									ROOT = { liege = { has_law = cognatic_succession } }
									NOT = {
										any_sibling = {
											is_female = no
											NOT = { trait = bastard }
										}
									}
								}
							}
							OR = {
								is_female = yes
								ROOT = { liege = { has_law = agnatic_succession } }
								ROOT = { liege = { has_law = cognatic_succession }
								ROOT = { liege = { has_law = true_cognatic_succession } } }
								AND = {
									ROOT = { liege = { has_law = enatic_cognatic_succession } }
									NOT = {
										any_sibling = {
											is_female = yes
											NOT = { trait = bastard }
										}
									}
								}
							}
						}
					}
				}
				set_character_flag = has_personal_spy_network
				change_variable = { which = "personal_spy_network" which = ROOT }
			}
		}
	}
}
			
# 20356; Attempt to dismantle network was discovered
character_event = {
	id = 20356
	picture = GFX_evt_spymaster
	border = GFX_event_normal_frame_intrigue

	desc = {
		text = EVTDESC20356_nothing
		trigger = {
			FROM = {
				NOR = {
					has_character_flag = small_network_decrease
					has_character_flag = med_network_decrease
					has_character_flag = large_network_decrease
				}
			}
		}
	}	
	desc = {
		text = EVTDESC20356_small
		trigger = { FROM = { has_character_flag = small_network_decrease } }
	}
	desc = {
		text = EVTDESC20356_med
		trigger = { FROM = { has_character_flag = med_network_decrease } }
	}
	desc = {
		text = EVTDESC20356_large
		trigger = { FROM = { has_character_flag = large_network_decrease } }
	}
	
	is_triggered_only = yes
	hide_from = yes
	
	option = {
		name = {
			text = EVTOPTA_20356
			trigger = {
				FROM = {
					NOR = {
						has_character_flag = small_network_decrease
						has_character_flag = med_network_decrease
						has_character_flag = large_network_decrease
					}
				}
			}
		}
		name = {
			text = EVTOPTB_20356
			trigger = {
				FROM = {
					OR = {
						has_character_flag = small_network_decrease
						has_character_flag = med_network_decrease
						has_character_flag = large_network_decrease
					}
				}
			}
		}
		prestige = -100
		if = {
			limit = {
				NOT = { is_rival = FROM }
			}
			tooltip = { add_rival = FROM }
		}
	}
}

# 20357; Attempt to dismantle network was discovered - Target Informed
character_event = {
	id = 20357
	picture = GFX_evt_spymaster
	border = GFX_event_normal_frame_intrigue

	desc = {
		text = EVTDESC20357_nothing
		trigger = {
			ROOT = {
				NOR = {
					has_character_flag = small_network_decrease
					has_character_flag = med_network_decrease
					has_character_flag = large_network_decrease
				}
			}
		}
	}	
	desc = {
		text = EVTDESC20357_small
		trigger = { ROOT = { has_character_flag = small_network_decrease } }
	}
	desc = {
		text = EVTDESC20357_med
		trigger = { ROOT = { has_character_flag = med_network_decrease } }
	}
	desc = {
		text = EVTDESC20357_large
		trigger = { ROOT = { has_character_flag = large_network_decrease } }
	}
	
	is_triggered_only = yes
	show_from_from = yes
	
	option = {
		name = EVTOPTA_20357
		clr_character_flag = small_network_decrease
		clr_character_flag = med_network_decrease
		clr_character_flag = large_network_decrease
		if = {
			limit = {
				NOT = { is_rival = FROMFROM }
			}
			add_rival = FROMFROM
		}
	}
}

# 20358; Attempt to dismantle network was not discovered
character_event = {
	id = 20358
	picture = GFX_evt_spymaster
	border = GFX_event_normal_frame_intrigue

	desc = {
		text = EVTDESC20358_nothing
		trigger = {
			FROM = {
				NOR = {
					has_character_flag = small_network_decrease
					has_character_flag = med_network_decrease
					has_character_flag = large_network_decrease
				}
			}
		}
	}	
	desc = {
		text = EVTDESC20358_small
		trigger = { FROM = { has_character_flag = small_network_decrease } }
	}
	desc = {
		text = EVTDESC20358_med
		trigger = { FROM = { has_character_flag = med_network_decrease } }
	}
	desc = {
		text = EVTDESC20358_large
		trigger = { FROM = { has_character_flag = large_network_decrease } }
	}
	
	is_triggered_only = yes
	hide_from = yes
	
	option = {
		name = {
			text = EVTOPTA_20358
			trigger = {
				FROM = {
					NOR = {
						has_character_flag = small_network_decrease
						has_character_flag = med_network_decrease
						has_character_flag = large_network_decrease
					}
				}
			}
		}
		name = {
			text = EVTOPTB_20358
			trigger = {
				FROM = {
					OR = {
						has_character_flag = small_network_decrease
						has_character_flag = med_network_decrease
						has_character_flag = large_network_decrease
					}
				}
			}
		}
	}
}

# 20359; Attempt to dismantle network was not discovered - Target Informed
character_event = {
	id = 20359
	picture = GFX_evt_spymaster
	border = GFX_event_normal_frame_intrigue

	desc = {
		text = EVTDESC20359_nothing
		trigger = {
			ROOT = {
				NOR = {
					has_character_flag = small_network_decrease
					has_character_flag = med_network_decrease
					has_character_flag = large_network_decrease
				}
			}
		}
	}	
	desc = {
		text = EVTDESC20359_small
		trigger = { ROOT = { has_character_flag = small_network_decrease } }
	}
	desc = {
		text = EVTDESC20359_med
		trigger = { ROOT = { has_character_flag = med_network_decrease } }
	}
	desc = {
		text = EVTDESC20359_large
		trigger = { ROOT = { has_character_flag = large_network_decrease } }
	}
	
	is_triggered_only = yes
	hide_from = yes
	
	option = {
		name = CURSES
		clr_character_flag = small_network_decrease
		clr_character_flag = med_network_decrease
		clr_character_flag = large_network_decrease
	}
}

