﻿celestial_siphon_treasury = {
	# Basic Setup
	skill = intrigue
	desc = "celestial_siphon_treasury_desc_general"
	success_desc = "celestial_siphon_treasury_SUCCESS_DESC"
	discovery_desc = "celestial_siphon_treasury_DISCOVERY_DESC"
	icon = intrigue
	illustration = "gfx/interface/illustrations/event_scenes/corridor.dds"
	category = hostile
	target_type = title
	cooldown = { years = 5 }

	# Parameters
	speed_per_skill_point = t2_spsp_owner_value
	speed_per_target_skill_point = t2_spsp_target_value
	spymaster_speed_per_skill_point = t2_spsp_owner_spy_value
	target_spymaster_speed_per_skill_point = t2_spsp_target_spy_value
	tier_speed = 1
	base_progress_goal = t3_base_phase_length_value
	maximum_secrecy = 95
	base_maximum_success = t2_base_max_success_value
	phases_per_agent_charge = 1
	success_chance_growth_per_skill_point = t3_scgpsp_value

	is_secret = yes
	maximum_breaches = 5

	# Core Triggers
	allow = {
		is_adult = yes
		is_imprisoned = no
		has_treasury = yes
		scope:target = {
			holder ?= {
				has_treasury = yes
				OR = {
					is_landed = yes
					tgp_is_any_minister = yes
				}
				top_liege = scope:owner.top_liege
			}
		}
	}

	valid = {
		scope:owner = {
			has_treasury = yes
		}
		scope:target = {
			holder ?= {
				has_treasury = yes
				OR = {
					is_landed = yes
					tgp_is_any_minister = yes
				}
				top_liege = scope:owner.top_liege
			}
		}
	}

	# Agents
	agent_leave_threshold = -25
	agent_join_chance = {
		base = 0
		ai_agent_join_chance_basic_suite_modifier = yes
		# House
		modifier = {
			add = -50
			scope:recipient.house ?= scope:target.holder.house
			scope:owner.house != scope:target.holder.house
			desc = TARGET_IS_MY_HOUSE_MEMBER
		}
	}

	valid_agent = { is_valid_agent_standard_trigger = yes }
	agent_groups_owner_perspective = { courtiers councillors scripted_relations }

	odds_prediction = {
		add = hostile_scheme_base_odds_prediction_target_is_title_value
		add = odds_skill_contribution_intrigue_title_value
		add = agent_groups_owner_perspective_value
		add = odds_celestial_siphon_treasury_scheme_misc_value
		min = 0
	}

	# Base Chances
	base_success_chance = {
		base = 0
		scheme_type_skill_success_chance_modifier = { SKILL = STEWARDSHIP }
		hostile_scheme_title_base_chance_modifier = yes

		# Spiritual Head of Faith
		modifier = {
			add = -30
			desc = "SCHEME_VS_SPIRITUAL_HOF_HOLDER"
			scope:target.holder.faith ?= {
				this = scope:owner.faith
				has_doctrine = doctrine_spiritual_head
				religious_head ?= scope:target.holder
			}
		}
		# Family Feud
		house_feud_title_hostile_scheme_success_modifier = yes #Unop: Use this in-house modifier: The original modifier expects character target, but this scheme has title target
		# Diarchs are better at schemes within their liege's realm
		diarch_scheming_title_within_realm_bonus_modifier = yes
		# Modifiers
		# Context
		modifier = {
			scope:target.holder.domicile.domicile_location.county ?= {
				county_held_or_vassal_to_target_trigger = { TARGET = scope:owner }
			}
			desc = celestial_siphon_treasury_IN_SUBREALM_DESC
			add = 10
		}
		modifier = {
			exists = scope:target.holder.house
			scope:actor.top_liege.house ?= scope:target.holder.house
			scope:owner != scope:target.holder
			desc = celestial_siphon_treasury_TOP_LIEGE_DESC
			add = -25
		}
		# House
		modifier = {
			scope:owner.house = {
				is_powerful_family = yes
				is_dominant_family = no
			}
			scope:owner != scope:target.holder
			desc = OWNER_POWERFUL_FAMILY_DESC
			add = 10
		}
		modifier = {
			scope:target.holder.house ?= {
				is_powerful_family = yes
				is_dominant_family = no
			}
			scope:owner != scope:target.holder
			desc = TARGET_HOLDER_POWERFUL_FAMILY_DESC
			add = -10
		}
		modifier = {
			scope:owner.house = { is_dominant_family = yes }
			scope:owner != scope:target.holder
			desc = OWNER_DOMINANT_FAMILY_DESC
			add = 20
		}
		modifier = {
			scope:target.holder.house ?= { is_dominant_family = yes }
			scope:owner != scope:target.holder
			desc = TARGET_HOLDER_DOMINANT_FAMILY_DESC
			add = -20
		}
		# Influence
		modifier = {
			desc = OWNER_INFLUENCE_LEVEL_DESC
			add = {
				value = scope:owner.influence_level
				multiply = 5
			}
		}
		modifier = {
			exists = scope:target.holder
			scope:owner != scope:target.holder
			desc = TARGET_HOLDER_INFLUENCE_LEVEL_DESC
			add = {
				value = scope:target.holder.influence_level
				multiply = -5
			}
		}
		modifier = {
			add = 10
			desc = eparch_scheme_bonus_with_value_desc
			scope:owner = { has_court_position = eparch_court_position }
			scope:target.holder ?= {
				domicile ?= { domicile_location = owner.top_liege.capital_province }
			}
		}
		modifier = { # Minister of Revenue
			add = 50
			desc = minister_of_revenue_desc_with_value
			scope:owner = {
				has_title = title:e_minister_of_revenue
				liege = {
					tgp_has_access_to_ministry_trigger = yes
				}
			}
		}
		# Family attributes
		modifier = {
			add = improved_siphon_treasury_scheme_3_value
			desc = family_attribute_desc_with_value
			scope:owner ?= {
				house ?= {
					has_house_aspiration_parameter = improved_siphon_treasury_scheme_3
				}
			}
		}
		modifier = {
			add = improved_siphon_treasury_scheme_2_value
			desc = family_attribute_desc_with_value
			scope:owner ?= {
				house ?= {
					has_house_aspiration_parameter = improved_siphon_treasury_scheme_2
				}
			}
		}
		modifier = {
			add = improved_siphon_treasury_scheme_1_value
			desc = family_attribute_desc_with_value
			scope:owner ?= {
				house ?= {
					has_house_aspiration_parameter = improved_siphon_treasury_scheme_1
				}
			}
		}
		###
	}
	base_secrecy = {
		add = secrecy_base_value
		add = countermeasure_apply_secrecy_maluses_value
		add = eparch_scheme_secrecy_bonus_value
		if = {
			limit = { # Minister of Revenue
				scope:owner ?= {
					has_title = title:e_minister_of_revenue
					liege = {
						tgp_has_access_to_ministry_trigger = yes
					}
				}
			}
			add = {
				value = 10
				desc = minister_of_revenue_desc
			}
		}
		# Family attributes
		scope:owner ?= {
			if = {
				limit = {
					exists = house
				}
				house = {
					add = {
						value = 0
						if = {
							limit = {
								has_house_aspiration_parameter = improved_siphon_treasury_scheme_3
							}
							add = improved_siphon_treasury_scheme_3_value
						}
						else_if = {
							limit = {
								has_house_aspiration_parameter = improved_siphon_treasury_scheme_2
							}
							add = improved_siphon_treasury_scheme_2_value
						}
						else_if = {
							limit = {
								has_house_aspiration_parameter = improved_siphon_treasury_scheme_1
							}
							add = improved_siphon_treasury_scheme_1_value
						}
						desc = family_attribute_desc
					}
				}
			}
		}
	}

	# On Actions
	on_start = {
		set_variable = {
			name = apply_countermeasures
			value = flag:calculating
		}
		add_scheme_starting_opportunities_intrigue_effect = yes
		# Fallback agents — a balanced config if you start the scheme from script.
		if = {
			limit = {
				scheme_owner = {
					NOT = { has_variable = agents_added }
				}
			}
			add_agent_slot = agent_scout
			add_agent_slot = agent_scout
			add_agent_slot = agent_muscle
			add_agent_slot = agent_infiltrator
			add_agent_slot = agent_lookout
		}
		if = {
			limit = {
				scheme_owner != scheme_target_title.holder
			}
			scheme_owner = {
				trigger_event = tgp_interaction_event.0020
			}
		}
	}
	on_phase_completed = {
		suppress_scheme_follow_up_event_till_input_given_effect = yes
		celestial_siphon_treasury_prep_effect = yes
		cap_schemes_and_fire_reminders_effect = yes
		scope:scheme.scheme_target_title.holder = {
			save_scope_as = recipient
		}
		scheme_owner = {
			duel = {
				skills = { stewardship intrigue }
				value = medium_skill_rating
				50 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = 3.5
					}
					send_interface_message = {
						type = siphon_scheme_good_message
						title = celestial_siphon_treasury_interaction.tt.success
						left_icon = scope:scheme.scheme_target_title
						scope:scheme = {
							change_variable = {
								name = embezzlement_stake
								add = var:embezzlement_stake_initial
							}
							add_scheme_modifier = { type = tgp_monthly_siphon_treasury_failure_scheme_modifier }
						}
						save_scope_value_as = {
							name = embezzlement_stake_tooltip
							value = scope:scheme.var:embezzlement_stake_initial
						}
						if = {
							limit = {
								scope:scheme.var:siphon_destination ?= flag:treasury
							}
							custom_tooltip = celestial_siphon_treasury_gained_treasury_tt
							hidden_effect = {
								add_treasury = scope:scheme.var:embezzlement_stake_initial
							}
						}
						else = {
							custom_tooltip = celestial_siphon_treasury_gained_gold_tt
							hidden_effect = {
								add_gold = scope:scheme.var:embezzlement_stake_initial
							}
						}
						hidden_effect = {
							scope:recipient = {
								remove_treasury = scope:scheme.var:embezzlement_stake_initial
							}
						}
					}
					scope:recipient = {
						if = {
							limit = {
								this != scope:scheme.scheme_owner
							}
							send_interface_message = {
								type = siphon_scheme_bad_message
								title = celestial_siphon_treasury_interaction.tt.suspicion
								left_icon = scope:scheme.scheme_target_title
								show_as_tooltip = {
									remove_treasury = scope:scheme.var:embezzlement_stake_initial
								}
							}
						}
					}
				}
				50 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = -3.5
					}
					send_interface_message = {
						type = siphon_scheme_bad_message
						title = celestial_siphon_treasury_interaction.tt.failure
						left_icon = scope:scheme.scheme_target_title
						scope:scheme = {
							add_scheme_modifier = { type = tgp_monthly_siphon_treasury_scheme_modifier }
						}
					}
				}
				50 = {
				}
			}
		}
	}
	on_hud_click  = { celestial_siphon_treasury_prep_effect = yes }
	on_semiyearly = {
		if = {
			limit = {
				scheme_owner = { is_ai = yes }
			}
			celestial_siphon_treasury_prep_effect = yes
		}
	}
	on_monthly = {
		hostile_scheme_monthly_discovery_chance_effect = yes
	}

	## Invalidation
	on_invalidated = {
		scheme_target_title = {
			holder = { save_scope_as = target }
		}
		scheme_owner = {
			save_scope_as = owner
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = celestial_siphon_treasury_invalidated_title
				left_icon = scope:target
				if = {
					limit = {
						has_treasury = no
					}
					custom_tooltip = celestial_siphon_treasury_invalidated_owner
				}
				else_if = {
					limit = {
						scope:target = {
							has_treasury = no
						}
					}
					custom_tooltip = celestial_siphon_treasury_invalidated_target
				}
				if = {
					limit = {
						scope:scheme.var:embezzlement_stake > 0
						is_alive = yes
					}
					add_secret = {
						type = secret_siphoned_treasury
						target = scope:target
					}
					random_secret = {
						limit = {
							secret_type = secret_siphoned_treasury
							secret_target = scope:target
						}
						set_variable = {
							name = embezzlement_stake
							value = scope:scheme.var:embezzlement_stake
						}
					}
				}
			}
		}
	}
}

celestial_movement_power_promote = {
	# Basic Setup
	skill = diplomacy
	desc = "celestial_movement_power_promote_desc_general"
	success_desc = "celestial_movement_power_promote_SUCCESS_DESC"
	icon = diplomacy
	illustration = "gfx/interface/illustrations/event_scenes/corridor.dds"
	category = political
	target_type = character
	cooldown = { years = 10 }

	# Parameters
	speed_per_skill_point = t2_spsp_owner_value
	speed_per_target_skill_point = t2_spsp_target_value
	spymaster_speed_per_skill_point = t2_spsp_owner_spy_value
	target_spymaster_speed_per_skill_point = t2_spsp_target_spy_value
	tier_speed = 1
	base_progress_goal = t3_base_phase_length_value
	maximum_secrecy = 95
	base_maximum_success = t2_base_max_success_value
	phases_per_agent_charge = 1
	success_chance_growth_per_skill_point = t3_scgpsp_value

	is_secret = no

	# Core Triggers
	allow = {
		is_adult = yes
		is_imprisoned = no
		scope:target = {
			any_character_situation = {
				situation_type = dynastic_cycle
			}
		}
	}

	valid = {
		scope:target = {
			any_character_situation = {
				situation_type = dynastic_cycle
			}
		}
	}

	# Agents
	agent_leave_threshold = -25
	agent_join_chance = {
		base = 0
		ai_agent_join_chance_basic_suite_modifier = yes
		# House
		modifier = {
			add = -50
			scope:recipient.house ?= scope:target.house
			scope:owner.house != scope:target.house
			desc = TARGET_IS_MY_HOUSE_MEMBER
		}
	}

	valid_agent = { is_valid_agent_standard_trigger = yes }
	agent_groups_owner_perspective = { courtiers councillors scripted_relations }

	odds_prediction = {
		add = base_odds_prediction_target_is_char_value
		add = odds_skill_contribution_diplomacy_value
		add = agent_groups_owner_perspective_value
		min = 0
	}

	# Base Chances
	base_success_chance = {
		base = 0
		scheme_type_skill_success_chance_modifier = { SKILL = DIPLOMACY }

		# Spiritual Head of Faith
		modifier = {
			add = -30
			desc = "SCHEME_VS_SPIRITUAL_HOF"
			scope:target.faith ?= {
				this = scope:owner.faith
				has_doctrine = doctrine_spiritual_head
				religious_head ?= scope:target
			}
		}
		# Diarchs are better at schemes within their liege's realm
		diarch_scheming_within_realm_bonus_modifier = yes
		# Modifiers
		# House
		modifier = {
			scope:owner.house ?= {
				is_powerful_family = yes
				is_dominant_family = no
			}
			scope:owner != scope:target
			desc = OWNER_POWERFUL_FAMILY_DESC
			add = 10
		}
		modifier = {
			scope:target.house ?= {
				is_powerful_family = yes
				is_dominant_family = no
			}
			scope:owner != scope:target
			desc = TARGET_POWERFUL_FAMILY_DESC
			add = -10
		}
		modifier = {
			scope:owner = {
				has_title = title:e_minister_of_rites
			}
			desc = OWNER_MINISTER_OF_RITES_DESC
			add = 15
		}
		modifier = {
			scope:target = {
				has_title = title:e_minister_of_rites
			}
			NOT = {
				scope:owner = {
					has_title = title:e_minister_of_rites
				}
			}
			desc = TARGET_MINISTER_OF_RITES_DESC
			add = -15
		}
		modifier = {
			scope:owner.house ?= { is_dominant_family = yes }
			scope:owner != scope:target
			desc = OWNER_DOMINANT_FAMILY_DESC
			add = 20
		}
		modifier = {
			scope:target.house ?= { is_dominant_family = yes }
			scope:owner != scope:target
			desc = TARGET_DOMINANT_FAMILY_DESC
			add = -20
		}
		# Influence
		modifier = {
			desc = OWNER_INFLUENCE_LEVEL_DESC
			add = {
				value = scope:owner.influence_level
				multiply = 5
			}
		}
		modifier = {
			exists = scope:target
			scope:owner != scope:target
			desc = TARGET_INFLUENCE_LEVEL_DESC
			add = {
				value = scope:target.influence_level
				multiply = -5
			}
		}
		modifier = {
			add = 10
			desc = eparch_scheme_bonus_with_value_desc
			scope:owner = { has_court_position = eparch_court_position }
			scope:target ?= {
				domicile ?= { domicile_location = owner.top_liege.capital_province }
			}
		}
	}

	# On Actions
	on_start = {
		save_scope_as = scheme
		set_variable = {
			name = apply_countermeasures
			value = flag:calculating
		}
		# Fallback agents — a balanced config if you start the scheme from script.
		if = {
			limit = {
				scheme_owner = {
					NOT = { has_variable = agents_added }
				}
			}
			add_agent_slot = agent_proponent
			add_agent_slot = agent_sycophant
			add_agent_slot = agent_eunuch
			add_agent_slot = agent_gabbler
			add_agent_slot = agent_herald
		}
		#save the target's movement
		situation:dynastic_cycle ?= {
			random_participant_group = {
				limit = {
					participant_group_has_character = scope:scheme.scheme_target_character
				}
				save_scope_as = targets_movement
			}
		}
		set_variable = {
			name = targets_movement
			value = scope:targets_movement
		}
	}
	on_phase_completed = {
		suppress_scheme_follow_up_event_till_input_given_effect = yes
		celestial_movement_power_promote_prep_effect = yes
		cap_schemes_and_fire_reminders_effect = yes
	}
	on_hud_click  = { celestial_movement_power_promote_prep_effect = yes }
	on_semiyearly = {
		if = {
			limit = {
				scheme_owner = { is_ai = yes }
			}
			celestial_movement_power_promote_prep_effect = yes
		}
	}

	## Invalidation
	on_invalidated = {
		scheme_target_character = {
			save_scope_as = target
		}
		scheme_owner = {
			save_scope_as = owner
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = celestial_movement_power_promote_invalidated_title
				left_icon = scope:target
				if = {
					limit = {
						situation:dynastic_cycle ?= {
							any_participant_group = {
								participant_group_has_character = scope:target
							}
						}
					}
					custom_tooltip = celestial_movement_power_promote_invalidated
				}
				else = {
					custom_tooltip = celestial_movement_power_promote_invalidated_target
				}
			}
		}
	}
}
celestial_movement_power_slander = {
	# Basic Setup
	skill = diplomacy
	desc = "celestial_movement_power_slander_desc_general"
	success_desc = "celestial_movement_power_slander_SUCCESS_DESC"
	icon = diplomacy
	illustration = "gfx/interface/illustrations/event_scenes/corridor.dds"
	category = political
	target_type = character
	cooldown = { years = 10 }

	# Parameters
	speed_per_skill_point = t2_spsp_owner_value
	speed_per_target_skill_point = t2_spsp_target_value
	spymaster_speed_per_skill_point = t2_spsp_owner_spy_value
	target_spymaster_speed_per_skill_point = t2_spsp_target_spy_value
	tier_speed = 1
	base_progress_goal = t3_base_phase_length_value
	maximum_secrecy = 95
	base_maximum_success = t2_base_max_success_value
	phases_per_agent_charge = 1
	success_chance_growth_per_skill_point = t3_scgpsp_value

	is_secret = no

	# Core Triggers
	allow = {
		is_adult = yes
		is_imprisoned = no
		scope:target = {
			any_character_situation = {
				situation_type = dynastic_cycle
			}
		}
	}

	valid = {
		scope:target = {
			any_character_situation = {
				situation_type = dynastic_cycle
			}
		}
	}

	# Agents
	agent_leave_threshold = -25
	agent_join_chance = {
		base = 0
		ai_agent_join_chance_basic_suite_modifier = yes
		# House
		modifier = {
			add = -50
			scope:recipient.house ?= scope:target.house
			scope:owner.house != scope:target.house
			desc = TARGET_IS_MY_HOUSE_MEMBER
		}
	}

	valid_agent = { is_valid_agent_standard_trigger = yes }
	agent_groups_owner_perspective = { courtiers councillors scripted_relations }

	odds_prediction = {
		add = base_odds_prediction_target_is_char_value
		add = odds_skill_contribution_diplomacy_value
		add = agent_groups_owner_perspective_value
		min = 0
	}

	# Base Chances
	base_success_chance = {
		base = 0
		scheme_type_skill_success_chance_modifier = { SKILL = DIPLOMACY }
		# Countermeasures
		apply_political_scheme_success_chance_adjustments_modifier = yes
		# Spiritual Head of Faith
		modifier = {
			add = -30
			desc = "SCHEME_VS_SPIRITUAL_HOF"
			scope:target.faith ?= {
				this = scope:owner.faith
				has_doctrine = doctrine_spiritual_head
				religious_head ?= scope:target
			}
		}
		# Diarchs are better at schemes within their liege's realm
		diarch_scheming_within_realm_bonus_modifier = yes
		## grand secretary director
		modifier = {
			add = 10
			scope:owner.liege ?= {
				has_active_mandate = placate_movements
			}
			scope:target ?= {
				is_in_pro_hegemon_or_hegemon_movement = no
			}
			desc = placate_movements_bonus
		}
		# Modifiers
		# House
		modifier = {
			scope:owner.house ?= {
				is_powerful_family = yes
				is_dominant_family = no
			}
			scope:owner != scope:target
			desc = OWNER_POWERFUL_FAMILY_DESC
			add = 10
		}
		modifier = {
			scope:target.house ?= {
				is_powerful_family = yes
				is_dominant_family = no
			}
			scope:owner != scope:target
			desc = TARGET_POWERFUL_FAMILY_DESC
			add = -10
		}
		modifier = {
			scope:owner.house ?= { is_dominant_family = yes }
			scope:owner != scope:target
			desc = OWNER_DOMINANT_FAMILY_DESC
			add = 20
		}
		modifier = {
			scope:target.house ?= { is_dominant_family = yes }
			scope:owner != scope:target
			desc = TARGET_DOMINANT_FAMILY_DESC
			add = -20
		}
		modifier = {
			scope:owner = {
				has_title = title:e_minister_of_rites
			}
			desc = OWNER_MINISTER_OF_RITES_DESC
			add = 15
		}
		modifier = {
			scope:target = {
				has_title = title:e_minister_of_rites
			}
			NOT = {
				scope:owner = {
					has_title = title:e_minister_of_rites
				}
			}
			desc = TARGET_MINISTER_OF_RITES_DESC
			add = -15
		}
		# Influence
		modifier = {
			desc = OWNER_INFLUENCE_LEVEL_DESC
			add = {
				value = scope:owner.influence_level
				multiply = 5
			}
		}
		modifier = {
			exists = scope:target
			scope:owner != scope:target
			desc = TARGET_INFLUENCE_LEVEL_DESC
			add = {
				value = scope:target.influence_level
				multiply = -5
			}
		}
		modifier = {
			add = 10
			desc = eparch_scheme_bonus_with_value_desc
			scope:owner = { has_court_position = eparch_court_position }
			scope:target ?= {
				domicile ?= { domicile_location = owner.top_liege.capital_province }
			}
		}
	}

	# On Actions
	on_start = {
		save_scope_as = scheme
		set_variable = {
			name = apply_countermeasures
			value = flag:political
		}
		# Fallback agents — a balanced config if you start the scheme from script.
		if = {
			limit = {
				scheme_owner = {
					NOT = { has_variable = agents_added }
				}
			}
			add_agent_slot = agent_proponent
			add_agent_slot = agent_diplomat
			add_agent_slot = agent_eunuch
			add_agent_slot = agent_gabbler
			add_agent_slot = agent_herald
		}
		#save the target's movement
		situation:dynastic_cycle ?= {
			random_participant_group = {
				limit = {
					participant_group_has_character = scope:scheme.scheme_target_character
				}
				save_scope_as = targets_movement
			}
		}
		set_variable = {
			name = targets_movement
			value = scope:targets_movement
		}
	}
	on_phase_completed = {
		suppress_scheme_follow_up_event_till_input_given_effect = yes
		celestial_movement_power_slander_prep_effect = yes
		cap_schemes_and_fire_reminders_effect = yes
	}
	on_hud_click  = { celestial_movement_power_slander_prep_effect = yes }
	on_semiyearly = {
		if = {
			limit = {
				scheme_owner = { is_ai = yes }
			}
			celestial_movement_power_slander_prep_effect = yes
		}
	}

	## Invalidation
	on_invalidated = {
		scheme_target_character = {
			save_scope_as = target
		}
		scheme_owner = {
			save_scope_as = owner
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = celestial_movement_power_slander_invalidated_title
				left_icon = scope:target
				if = {
					limit = {
						situation:dynastic_cycle ?= {
							any_participant_group = {
								participant_group_has_character = scope:target
							}
						}
					}
					custom_tooltip = celestial_movement_power_promote_invalidated
				}
				else = {
					custom_tooltip = celestial_movement_power_promote_invalidated_target
				}
			}
		}
	}
}

## Censor/Justice Find Secrets scheme
celestial_minister_find_secrets_scheme = {
	# Basic Setup
	skill = intrigue
	desc = celestial_minister_find_secrets_scheme_desc_general
	success_desc = celestial_minister_find_secrets_scheme_desc_success
	icon = intrigue
	illustration = "gfx/interface/illustrations/event_scenes/corridor.dds"
	target_type = character
	category = political
	
	# Parameters
	speed_per_skill_point = t2_spsp_owner_value
	base_progress_goal = t3_base_phase_length_value
	base_maximum_success = t3_base_max_success_value
	phases_per_agent_charge = 1
	success_chance_growth_per_skill_point = laamp_contract_scgpsp_value
	uses_resistance = no
	
	# Core Triggers
	valid = {
		scope:owner = {
			government_has_flag = government_is_celestial
			OR = {
				has_title = title:e_minister_censor
				has_title = title:e_minister_of_justice
			}
		}
	}

	# Agents
	agent_leave_threshold = -25
	agent_join_chance = {
		base = 0
		ai_agent_join_chance_basic_suite_modifier = yes
		ai_agent_join_chance_hostile_grievous_modifier = yes
	}
	valid_agent = { is_valid_agent_standard_trigger = yes }
	agent_groups_owner_perspective = { courtiers }
	agent_groups_target_character_perspective = { courtiers vassals }

	# Base Chances
	base_success_chance = {
		base = 5
		laamp_contract_scheme_basic_success_chance_modifier = yes
	}
	
	# On Actions
	on_start = {
		set_variable = {
			name = secrets_found
			value = 0
		}
	}
	on_phase_completed = {
		suppress_scheme_follow_up_event_till_input_given_effect = yes
		celestial_minister_find_secrets_scheme_prep_effect = yes
		cap_schemes_and_fire_reminders_effect = yes
	}

	on_hud_click  = { celestial_minister_find_secrets_scheme_prep_effect = yes }
	on_semiyearly = {
		if = {
			limit = {
				scheme_owner = { is_ai = yes }
			}
			celestial_minister_find_secrets_scheme_prep_effect = yes
		}
	}
	on_monthly = {
		save_scope_as = scheme
		scheme_owner.liege = {
			save_scope_as = councillor_liege
		}
		scheme_target_character = {
			save_scope_as = target_character
		}
		scheme_owner = {
			save_scope_as = councillor
			if = {
				limit = {
					scope:target_character = {
						spymaster_task_find_secrets_court_has_major_secrets_trigger = yes
					}
				}
				trigger_event = scheme_critical_moments.8069
			}
			else_if = {
				limit = {
					scope:target_character = {
						spymaster_task_find_secrets_court_has_minor_secrets_trigger = yes
					}
				}
				trigger_event = scheme_critical_moments.8068
			}
			# gain hook if Censor
			else_if = {
				limit = {
					title:e_minister_censor.holder = scope:councillor
				}
				random = {
					chance = {
						value = 0
						add = scope:scheme.scheme_success_chance
						add = {
							value = scope:scheme.var:secrets_found
							multiply = -20
						}
					}
					trigger_event = scheme_critical_moments.8070
				}
			}
			# Imprison known criminals if Justice
			else_if = {
				limit = {
					title:e_minister_of_justice.holder = scope:councillor
					scope:target_character = {
						any_vassal_or_below = {
							is_imprisoned = no
							liege = {
								has_imprisonment_reason = prev
							}
						}
					}
				}
				trigger_event = scheme_critical_moments.8071
			}
			else = {
				# nothing happens
			}
		}
	}
	on_invalidated = {
		save_scope_as = scheme
		scheme_owner = {
			send_interface_message = {
				title = scheme_invalidated_title
				type = intrigue_contract_scheme_invalidated_message
				right_icon = scope:scheme.scheme_target_character
				show_as_tooltip = {
					scope:scheme = { end_scheme = yes }
				}
			}
		}
	}
}
