regula_forge_inheritance_law = {
	skill = intrigue
	icon = icon_scheme_hostile


	cooldown = { months = 2 }
	is_secret = yes
	base_secrecy = 25
	hostile = yes
	uses_agents = no
	power_per_skill_point = 6
	resistance_per_skill_point = 2
	tier_resistance = 1
	minimum_progress_chance = 35
	maximum_progress_chance = 95
	# Does not use Spymaster
	spymaster_power_per_skill_point = 3
	spymaster_resistance_per_skill_point = 1
	minimum_success = 50
	
	allow = {
		is_adult = yes
		any_secret = {
			secret_type = regula_covert_conversion
		}
		is_imprisoned = no
		scope:target = { 
			is_imprisoned = no
		}
	}

	valid = {
		NOT = { scope:target = { has_trait = incapable } }
		is_imprisoned = no

		scope:target = {
			is_imprisoned = no
			OR = {
				exists = location
				in_diplomatic_range = scope:owner
			}
		}
	}

	valid_agent = {
		is_regula_trigger = yes
		age >= 16
	}
	
	agent_join_chance = {
		base = 0
	}

	base_success_chance = {
		base = 25

		hostile_scheme_base_chance_modifier = yes

		modifier = {
			add = 20
			desc = FABRICATE_HOOK_DECEITFUL
			scope:owner = {
				has_trait = deceitful
			}
		}

		modifier = {
			add = -20
			desc = FABRICATE_HOOK_HONEST
			scope:owner = {
				has_trait = honest
			}
		}

		modifier = {
			add = 10
			desc = FABRICATE_HOOK_TARGET_TRUSTING
			scope:target = {
				has_trait = trusting
			}
		}

		modifier = {
			add = 10
			desc = FABRICATE_HOOK_TARGET_INTELLECT_BAD_1
			scope:target = {
				has_trait = intellect_bad_1
			}
		}

		modifier = {
			add = 20
			desc = FABRICATE_HOOK_TARGET_INTELLECT_BAD_2
			scope:target = {
				has_trait = intellect_bad_2
			}
		}

		modifier = {
			add = 30
			desc = FABRICATE_HOOK_TARGET_INTELLECT_BAD_3
			scope:target = {
				has_trait = intellect_bad_3
			}
		}

		modifier = {
			add = -10
			desc = FABRICATE_HOOK_TARGET_INTELLECT_GOOD_1
			scope:target = {
				has_trait = intellect_good_1
			}
		}

		modifier = {
			add = -20
			desc = FABRICATE_HOOK_TARGET_INTELLECT_GOOD_2
			scope:target = {
				has_trait = intellect_good_2
			}
		}

		modifier = {
			add = -30
			desc = FABRICATE_HOOK_TARGET_INTELLECT_GOOD_3
			scope:target = {
				has_trait = intellect_good_3
			}
		}

		modifier = {
			add = -20
			desc = FABRICATE_HOOK_TARGET_SCHEMER
			scope:target = {
				has_trait = schemer
			}
		}

		modifier = {
			add = -20
			desc = FABRICATE_HOOK_TARGET_PARANOID
			scope:target = {
				has_trait = paranoid
			}
		}

		modifier = {
			add = -10
			desc = FABRICATE_HOOK_TARGET_FICKLE
			scope:target = {
				has_trait = fickle
			}
		}

		modifier = {
			add = 10
			desc = FABRICATE_HOOK_TARGET_ARROGANT
			scope:target = {
				has_trait = arrogant
			}
		}

		modifier = {
			add = 20
			desc = FABRICATE_HOOK_TARGET_GREEDY
			scope:target = {
				has_trait = greedy
			}
		}

		modifier = {
			add = 10
			desc = FABRICATE_HOOK_TARGET_CRAVEN
			scope:target = {
				has_trait = craven
			}
		}

		compare_modifier = {
			value = scope:owner.cp:councillor_spymaster.intrigue
			multiplier = 2
			desc = FABRICATE_HOOK_SPYMASTER_INTRIGUE
			trigger = {
				exists = scope:owner.cp:councillor_spymaster
				NOT = { scope:owner.cp:councillor_spymaster = scope:target }
			}
		}
		
		modifier = {
			add = -50
			desc = FABRICATE_HOOK_TARGETING_SPYMASTER
			scope:target = {
				has_council_position = councillor_spymaster
			}
		}
		
		# Spiritual Head of Faith
		modifier = {
			add = -50
			desc = "SCHEME_VS_SPIRITUAL_HOF"
			scope:target = {
				faith = scope:owner.faith
				faith = {
					has_doctrine = doctrine_spiritual_head
				}
				faith = {
					exists = religious_head
					religious_head = {
			 			this = scope:target
			 		}
				}
			}
		}


		modifier = {
			desc = "SCHEME_SCHEMER_TRAIT"
			scope:owner = { has_trait = schemer }
			add = 25
		}


		#Rank tier difference (landed target/target whose liege doesn't care)
		modifier = { #3 or more higher rank
			trigger = { scope:owner = { NOT = { is_consort_of = scope:target } } } # Your spouse doesn't care if you're a different rank than them.
			add = 20
			desc = "HIGHER_RANK_THAN_SCHEME_TARGET"
			scope:target = {
				personal_scheme_success_compare_target_liege_tier_trigger = no
				NOT = {
					is_theocratic_lessee = yes
				}
			}
			scope:owner = {
				tier_difference = {
					target = scope:target
					value >= 3
				}
			}
		}
		modifier = { #2 higher rank
			trigger = { scope:owner = { NOT = { is_consort_of = scope:target } } } # Your spouse doesn't care if you're a different rank than them.
			add = 10
			desc = "HIGHER_RANK_THAN_SCHEME_TARGET"
			scope:target = {
				personal_scheme_success_compare_target_liege_tier_trigger = no
				NOT = {
					is_theocratic_lessee = yes
				}
			}
			scope:owner = {
				tier_difference = {
					target = scope:target
					value = 2
				}
			}
		}
		modifier = { #1 higher rank
			trigger = { scope:owner = { NOT = { is_consort_of = scope:target } } } # Your spouse doesn't care if you're a different rank than them.
			add = 0
			desc = "HIGHER_RANK_THAN_SCHEME_TARGET"
			scope:target = {
				personal_scheme_success_compare_target_liege_tier_trigger = no
				NOT = {
					is_theocratic_lessee = yes
				}
			}
			scope:owner = {
				tier_difference = {
					target = scope:target
					value = 1
				}
			}
		}

		# Dynasty Kin Personal Scheme Success Chance on Dynasty Perk
		modifier = {
			add = kin_legacy_4_success_chance
			desc = KIN_LEGACY_DESC
			exists = scope:owner.dynasty
			scope:owner.dynasty = {
				has_dynasty_perk = kin_legacy_4
			}
			scope:target.dynasty = scope:owner.dynasty
		}

		# Thicker Than Water Perk
		modifier = {
			add = thicker_than_water_bonus
			desc = BEFRIEND_THICKER_THAN_WATER_PERK_DESC
			scope:owner = {
				has_perk = thicker_than_water_perk
			}
			scope:target = {
				is_close_or_extended_family_of = scope:owner
			}
		}
	}


	on_ready = {
		scheme_owner = {
			#Do I want to proceed to a roll?
			if = {
				limit = {
					is_ai = no
				}
				random_list = {
					50 = { #Warrior Princess
						trigger_event = regula_forge_inheritance_outcome.0001
					}
					50 = { #Haruspex
						trigger_event = regula_forge_inheritance_outcome.0002
					}
				}
			}
		}
	}
	# # Do the Success Roll
	# random = {
	# 	chance = scheme_success_chance
	# 	save_scope_value_as = {
	# 		name = scheme_succeeded
	# 		value = yes
	# 	}
	# }
	# # Do the Secrecy Roll
	# save_scope_value_as = {
	# 	name = discovery_chance
	# 	value = {
	# 		value = 100
	# 		subtract = scheme_secrecy
	# 	}
	# }
	# random = {
	# 	chance = scope:discovery_chance
	# 	save_scope_value_as = {
	# 		name = scheme_discovered
	# 		value = yes
	# 	}
	# }

	# # On Success: Fire Event
	# if = {
	# 	limit = { exists = scope:scheme_succeeded }
	# 	scheme_owner = {
	# 		trigger_event = {
	# 			id = regula_forge_inheritance_outcome.1000
	# 		}
	# 	}
	# }

	# else = {
	# 	if = {
	# 		limit = { exists = scope:scheme_discovered }
	# 		scheme_owner = {
	# 			trigger_event = {
	# 				id = regula_forge_inheritance_outcome.2000
	# 			}
	# 		}
	# 	}
	# 	else = {
	# 		scheme_owner = {
	# 			send_interface_message = {
	# 				type = fabricate_hook_bad_message
	# 				title = regula_forge_inheritance_law_failed_reset_message
					
	# 				custom_tooltip = restart_scheme_tt
	# 				hidden_effect = {
	# 					scope:scheme = {
	# 						add_scheme_progress = -10
	# 					}
	# 				}
	# 			}
	# 		}
	# 	}
	# }



	
	on_invalidated = {
		if = {
			limit = {
				scheme_target = { is_alive = no }
			}
			scheme_owner = {
				send_interface_message = {
					type = event_generic_neutral
					title = regula_forge_inheritance_invalid
					left_icon = scope:target
					custom_tooltip = regula_forge_inheritance_invalid_dead_tt
					add_gold = 75
					add_prestige = 125
				}
			}
		}

		else_if = { #fallback invalidation
			limit = {
				OR = {
					scope:owner = { is_imprisoned = yes }
					scope:target = { is_imprisoned = yes }

					scope:target = {
						NOR = {
							exists = location
							in_diplomatic_range = scope:owner
						}
					}
				}
			}
			scheme_owner = {
				send_interface_message = {
					type = event_generic_neutral
					title = regula_forge_inheritance_invalid
					left_icon = scope:target
					custom_tooltip = regula_forge_inheritance_invalid_inaccessible_tt
					add_gold = 100
					add_prestige = 200
				}
			}
		}
	}

	on_monthly = {
		hostile_scheme_discovery_chance_effect = yes
	}
	success_desc = "FORGE_INHERITANCE_LAW_SUCCESS_DESC"
	discovery_desc = "FORGE_INHERITANCE_LAW_DISCOVERY_DESC"
}