﻿task_find_secrets_side_effects_obf = {

	on_actions = {
		task_find_secrets_side_effects
		task_find_secrets_flag_target
		delay = { days = 7 }
		task_find_secrets_side_effects_player	
	}
}

task_find_secrets_side_effects_ai = { #was used for testing

	trigger = {
		NOT = { has_variable = had_spymaster_task_side_effect }
		exists = cp:councillor_spymaster
		scope:councillor_liege = {is_ai = yes}
	}

	random_events = {
		chance_to_happen = 1
		500 = 0
		100 = spymaster_task.0399 #Nothing is found
		100 = spymaster_task.3001 #Caught snooping on vassal
		100 = spymaster_task.3004 #Caught snooping on liege
		100 = spymaster_task.3007 #Caught snooping on foreign ruler
		100 = spymaster_task.3010 #Caught snooping on foreign ruler's vassal
	}
}

task_find_secrets_side_effects_player = {

	trigger = {
		exists = cp:councillor_spymaster
		scope:councillor_liege = {is_ai = no}
	}

	random_events = {
		chance_to_happen = 50
		550 = 0
		100 = spy_ongoing.1000 #Someone wants to talk
		100 = spy_ongoing.1002 #blackmail
		200 = spy_ongoing.1003 #Spymaster gathers info
		50 = spy_ongoing.1004 #Spymaster discovers faction
	}
}

task_find_secrets_exposed = {

	trigger = {
		NOT = { has_variable = had_spymaster_task_side_effect }
		exists = cp:councillor_spymaster
		scope:councillor_liege = {is_ai = no}
	}

	random_events = {
		chance_to_happen = 30
		100 = spymaster_task.3001 #Caught snooping on vassal
		100 = spymaster_task.3004 #Caught snooping on liege
		100 = spymaster_task.3007 #Caught snooping on foreign ruler
		100 = spymaster_task.3010 #Caught snooping on foreign ruler's vassal
	}
}

task_find_secrets_exposed_by_blackmail = {

	trigger = {
		NOT = { has_variable = had_spymaster_task_side_effect }
		exists = cp:councillor_spymaster
		scope:councillor_liege = {is_ai = no}
	}

	random_events = {
		chance_to_happen = 100
		100 = spymaster_task.3001 #Caught snooping on vassal
		100 = spymaster_task.3004 #Caught snooping on liege
		100 = spymaster_task.3007 #Caught snooping on foreign ruler
		100 = spymaster_task.3010 #Caught snooping on foreign ruler's vassal
	}
}

task_find_secrets_flag_target = {

	trigger = {
		exists = cp:councillor_spymaster
		scope:councillor_liege = {is_ai = no}
	}

	effect = {
	scope:target_character = {
	add_character_flag = {
	flag = spymaster_is_in_the_court
	days = 35
			}
	
		}
	}
}