revela_secretum_assign_appropriate_type_effect = {
	debug_log = "Running Fabricate Hook's Assign Appropriate Hook effect"
	assert_if = {
		limit = {
			scope:owner = {
				has_strong_hook = scope:revela_target
			}
		}
		text = "The Magister already has a Strong Hook on the Target! Why is this effect running?"
	}
	assert_if = {
		limit = {
			scope:revela_target = { is_ruler = yes }
			NOT = { exists = scope:strong_hook_against_ruler }
			scope:owner = { has_hook = scope:revela_target }
		}
		text = "The Magister has a hook against a ruler target, and the strong hook roll failed. Something has gone wrong to get here!"
	}

	save_scope_value_as = {
		name = hook_type
		value = flag:$TYPE$
	}
	# Go through the Hook types, and assign the appropriate one
	if = {
		limit = {
			scope:hook_type = flag:loyalty_hook
		}
		# Check rulers first (to give weaker Hooks)
		if = {
			limit = {
				scope:revela_target = { is_ruler = yes }
				NOT = { exists = scope:strong_hook_against_ruler } # Set by on_ready in the Scheme
			}
			add_hook = {
				type = indebted_hook
				target = scope:revela_target
			}
		}
		else = {
			add_hook = {
				type = loyalty_hook
				target = scope:revela_target
			}
		}
	}
	else_if = {
		limit = {
			scope:hook_type = flag:fabrication_hook
		}
		# Check rulers first (to give weaker Hooks)
		if = {
			limit = {
				scope:revela_target = { is_ruler = yes }
				NOT = { exists = scope:strong_hook_against_ruler } # Set by on_ready in the Scheme
			}
			add_hook = {
				type = manipulation_hook
				target = scope:revela_target
			}
			scope:revela_target = {
				add_opinion = {
					target = scope:revela_recipient
					modifier = fabricate_hook_threatened_me
					years = 5
				}
			}
		}
		else = {
			add_hook = {
				type = fabrication_hook
				target = scope:revela_target
			}
			scope:revela_target = {
				add_opinion = {
					target = scope:revela_recipient
					modifier = fabricate_hook_threatened_me
					years = 5
				}
			}
		}
	}
	else_if = {
		limit = {
			scope:hook_type = flag:life_threat_hook
		}
		debug_log = "Attempting to set life threat hook"
		# Check rulers first (to give weaker Hooks)
		if = {
			limit = {
				scope:revela_target = { is_ruler = yes }
				NOT = { exists = scope:strong_hook_against_ruler } # Set by on_ready in the Scheme
			}
			debug_log = "Trying to set regular threat hook against ruler"
			add_hook = {
				type = threat_hook
				target = scope:revela_target
			}
			scope:revela_target = {
				add_opinion = {
					target = scope:revela_recipient
					modifier = fabricate_hook_threatened_me
					years = 10
				}
			}
		}
		else = {
			if = {
				limit = { exists = scope:strong_hook_against_ruler }
				debug_log = "Trying to set life_threat_hook against a ruler"
			}
			else = {
				debug_log = "Setting life_threat_hook against non-ruler"
				assert_if = {
					limit = { scope:revela_target = { is_ruler = yes } }
					text = "There is no ruler strong hook roll, but we're still trying to set a life_threat_hook on them!"
				}
			}
			add_hook = {
				type = life_threat_hook
				target = scope:revela_target
			}
			scope:revela_target = {
				add_opinion = {
					target = scope:revela_recipient
					modifier = fabricate_hook_threatened_me
					years = 10
				}
			}
		}
	}
	# Error catch
	else = {
		assert_if = {
			limit = { always = yes } # It should never get here
			text = "Fabricate Hook assignment effect did not have a Hook type set when trying to assign a Hook!"
		}
	}
}

revela_secretum_block_scheme_owner_from_further_schemes_effect = {
	add_opinion = {
		target = scope:revela_recipient
		modifier = fabricated_hook_against_court_opinion
		years = 5
	}
	custom_tooltip = fabricate_hook_i_may_not_fabricate_again
}

revela_secretum_discovery_effect = {
	show_as_tooltip = { # Target dislikes you
		custom_tooltip = fabricate_hook_i_may_not_fabricate_again
		scope:revela_target = {
			add_opinion = {
				target = scope:revela_recipient
				modifier = fabricated_hook_against_court_opinion
				years = 5
			}
		}
		if = {
			limit = {
				exists = scope:revela_target.court_owner
				NOT = { scope:revela_target = scope:revela_target.court_owner }
			}
			scope:revela_target.court_owner = {
				add_opinion = {
					target = scope:revela_recipient
					modifier = fabricated_hook_against_court_opinion
					years = 5
				}
			}
		}
	}

	hidden_effect  = {
		# Set a blocker for Fabricating further Hooks against Court in question
		if = {
			limit = {
				exists = scope:revela_target.court_owner
			}
			scope:revela_target.court_owner = {
				send_interface_message = {
					type = revela_secretum_blocked
					left_icon = scope:revela_recipient

					revela_secretum_block_scheme_owner_from_further_schemes_effect = yes
				}
			}
		}
		if = {
			limit = {
				OR = {
					NOT = { exists = scope:target.court_owner }
					NOT = { scope:target.court_owner = scope:target }
				}
			}
			scope:target = {
				add_opinion = {
					target = scope:owner
					modifier = fabricated_hook_against_court_opinion
					years = 5
				}
			}
		}
	}
}


#Used in event options
revela_secretum_success_effect = {
	revela_secretum_assign_appropriate_type_effect = {
		TYPE = $TYPE$ # Sets the correct hook type to give
	}
}