#Scripted effects relating to the Rapta Maritus Scheme

#####################################################################
# EFFECT LIST
#####################################################################
# !!! Remember to add all new effects with a short description here !!!

#rapta_maritus_outcome_roll_effect
#rapta_maritus_success_effect
#rapta_maritus_failure_effect

######################################################################
# EFFECTS
######################################################################

#Sets up the Outcome Roll values
rapta_maritus_outcome_roll_setup_effect = {
	#Discovery Roll setup
	save_scope_value_as = {
		name = discovery_chance
		value = {
			value = 100
			subtract = scope:scheme.scheme_secrecy
		}
	}
}

#Roll to check whether a rapta_maritus Scheme is a success or a failure, and whether the owner is discovered
rapta_maritus_outcome_roll_effect = {
	#SUCCESS ROLL
	random = {
		chance = scope:scheme.scheme_success_chance
		custom_tooltip = rapta_maritus_successful_roll_tt
		save_scope_value_as = {
			name = scheme_successful
			value = yes
		}
	}
	### End Success roll
	#DISCOVERY ROLL
	custom_label = rapta_maritus_success_discovery_tt
	random = {
		chance = scope:discovery_chance
		custom_tooltip = rapta_maritus_become_discovered_roll_tt
		save_scope_value_as = {
			name = scheme_discovered
			value = yes
		}
	}
	### End Discovery roll

	hidden_effect = {
		#FIRE CORRECT ON ACTIONS
		if = {
			limit = {
				exists = scope:scheme_successful
			}
			trigger_event = {
				on_action = rapta_maritus_succeeded
			}
		}
		else = {
			trigger_event = {
				on_action = rapta_maritus_failed
			}
		}
	}
}


#Used in the immediate aftermath of the Scheme Owner's success event
rapta_maritus_success_effect = {
	scope:target = {
		add_character_flag = {
			flag = was_abducted_block_notification_event
			days = 2
		}
		trigger_event = rapta_maritus_outcome.5001
	}

	global_var:magister_character = {
		trigger_event = rapta_maritus_outcome.7001 # Letter event for magister.
	}

	hard_imprison_character_effect = {  # This decides where the kidnapped person goes.  May need a saved scope:magister.
		TARGET = scope:target
		IMPRISONER = global_var:magister_character
	}
}


rapta_maritus_failure_effect = {
	#Add Watchful Modifier to the target
	scope:target = {
		show_as_tooltip = {
			add_character_modifier = {
				modifier = watchful_modifier
				days = watchful_modifier_duration
			}
		}
	}

	global_var:magister_character = {
		trigger_event = rapta_maritus_outcome.7002 # Letter event for magister.
	}


	scope:target = {
		trigger_event = rapta_maritus_outcome.5002
	}
}

successful_rapta_maritus_outcome_event_option_effect = {
	if = {
		limit = {
			faith = {
				has_doctrine_parameter = piety_gain_from_successful_intrigue_schemes
			}	
		}
		add_piety = minor_piety_gain
	}

	scope:scheme = {
		end_scheme = yes
	}
}