﻿choose_appropriate_support_schemes_action = {
	first_valid_on_action = {
		sas_spy_network_task_support_schemes_side_effects
		task_support_schemes_side_effects
	}
}

sas_spy_network_task_support_schemes_side_effects = {
	trigger = {
		NOT = { has_variable = had_spymaster_task_side_effect }
		exists = cp:councillor_spymaster
		can_use_spy_network = yes
	}

	random_events = {
		chance_to_happen = 1
		1000 = 0
		#Bad side effects
		100 = spymaster_task.2001 #Loss of Piety
		100 = spymaster_task.2002 #Loss of prestige
		50 = spymaster_task.2003 #Scheme Fails
		#Good side effects
		100 = spymaster_task.2101 #Discovery of a minor secret
		25 = spymaster_task.2104 #Discovery of a major secret, modified from 50 to account for spy network
	}
}

sas_spy_network_task_disrupt_schemes_side_effects = {
	trigger = {
		NOT = { has_variable = had_spymaster_task_side_effect }
		exists = cp:councillor_spymaster
	}

	random_events = {
		chance_to_happen = 2
		#The chance for the vanilla events must stay 1% while adding the "discover spy" event
		chance_of_no_event = {
			value = 0
			if = {
				limit = {
					NOT = {
						any_courtier = {
							NOT = { this = root.cp:councillor_spymaster }
							any_ruler = {
								is_target_in_variable_list = {
									name = spy_network_members
									target = prev
								}
								NOT = { this = root }
								NOT = { this = root.cp:councillor_spymaster }
							}
						}
					}
				}
				add = 67
			}
		}
		800 = agot_spy_network.0500 #Discover spy; 12% chance per year: 12 * 1% * 0,67 * 1,5
		# Bad side effects
		25 = spymaster_task.1001 #Spymaster reveals one of your secrets to a powerful vassal
		100 = spymaster_task.1003 #Spymaster reveals a Courtier's secrets to a powerful vassal
		#Good side effects
		100 = spymaster_task.1101 #Hostile Scheme is interrupted
		100 = spymaster_task.2101 #Discovery of a minor secret
		50 = spymaster_task.2104 #Discovery of a major secret
	}
}

sas_spy_network_task_find_secrets_outcome = {
	random_events = {
		# SAS Change
		# 100 = spymaster_task.0301 #Find minor secret
		# 50 = spymaster_task.0302 #Find major secret
		# 10 = spymaster_task.0381 # Fabricate a Hook (if you have Truth is Relative) - Fired both here and if no secrets exist
		20 = spymaster_task.0301 #Find minor secret
		10 = spymaster_task.0302 #Find major secret
		10 = spymaster_task.0381 # Fabricate a Hook (if you have Truth is Relative) - Fired both here and if no secrets exist
		120 = agot_spy_network.0400 # Recruit spy
		# SAS Change End
	}
}
