﻿regula_forge_inheritance_law = {

	# Basic Setup
	skill = intrigue
	desc = regula_forge_inheritance_law_desc_general
	success_desc = "FORGE_INHERITANCE_LAW_SUCCESS_DESC"
	discovery_desc = "FORGE_INHERITANCE_LAW_DISCOVERY_DESC"
	icon = icon_scheme_generate_claim
	illustration = "gfx/interface/illustrations/event_scenes/regula_alcove.dds"
	target_type = character
	category = hostile
	is_secret = no

	# 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 = 0
	tier_speed = 1
	base_progress_goal = t3_base_phase_length_value
	base_maximum_success = t2_base_max_success_value
	phases_per_agent_charge = 1
	success_chance_growth_per_skill_point = t3_scgpsp_value
	cooldown = { months = 2 }

	# Core Triggers
	allow = {
		is_adult = yes
		is_imprisoned = no
		NOT = { has_trait = incapable }
		OR = {
			any_secret = {
				secret_type = regula_covert_conversion
			}
			is_regula_trigger = yes
		}
		scope:target = {
			is_imprisoned = no
			is_landed = yes
		}
	}

	valid = {
		scope:owner = {
			is_imprisoned = no
			NOT = { has_trait = incapable }
			is_in_civil_war = no
		}
		scope:target = {
			is_imprisoned = no
			is_in_civil_war = no
			is_landed = yes
			OR = {
				exists = location
				in_diplomatic_range = scope:owner
			}
		}
	}

	# 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
			is_male = yes
			desc = TARGET_IS_MY_HOUSE_MEMBER
		}
		modifier = {
			add = 25
			scope:recipient.house ?= scope:target.house
			is_female = yes
			desc = TARGET_IS_MY_HOUSE_MEMBER
		}
		modifier = {
			add = 10
			is_female = yes
		}
	}
	valid_agent = { is_valid_agent_standard_trigger = yes }
	agent_groups_owner_perspective = { courtiers peer_vassals vassals councillors }

	odds_prediction = {
		add = hostile_scheme_base_odds_prediction_target_is_title_value
		add = odds_skill_contribution_diplomacy_value
		add = agent_groups_owner_perspective_value
		add = agent_groups_target_character_perspective_value
		add = odds_raid_estate_scheme_misc_value
		min = 0
	}

	# Base Chances
	base_success_chance = {
		base = 0

		# Skill
		compare_modifier = {
			desc = "SCHEME_MY_INTRIGUE"
			value = scope:owner.intrigue
			multiplier = 2
		}
		compare_modifier = {
			desc = "SCHEME_TARGET_HOLDER_INTRIGUE"
			value = scope:target.intrigue
			multiplier = -2
		}
		# 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
			}
		}
		# Sponsored Inspiration
		modifier = {
			add = -15
			desc = target_has_sponsored_inspiration
			scope:target = {
				exists = inspiration
				inspiration = { exists = inspiration_sponsor }
			}
		}
		# Family Feud
		house_feud_hostile_scheme_success_modifier = yes
		# Diarchs are better at schemes within their liege's realm
		diarch_scheming_within_realm_bonus_modifier = yes
		# Modifiers
		modifier = {
			scope:owner = {
				has_character_modifier = united_political_agents_modifier
				is_vassal_of = scope:target
			}
			desc = united_political_agents_modifier
			add = 15
		}
		# House
		modifier = {
			scope:owner.house = {
				is_powerful_family = yes
				is_dominant_family = no
			}
			desc = OWNER_POWERFUL_FAMILY_DESC
			add = 10
		}
		modifier = {
			scope:target.house = {
				is_powerful_family = yes
				is_dominant_family = no
			}
			desc = TARGET_HOLDER_POWERFUL_FAMILY_DESC
			add = -10
		}
		modifier = {
			scope:owner.house = { is_dominant_family = yes }
			desc = OWNER_DOMINANT_FAMILY_DESC
			add = 20
		}
		modifier = {
			scope:target.house = { is_dominant_family = yes }
			desc = TARGET_HOLDER_DOMINANT_FAMILY_DESC
			add = -20
		}
		modifier = {
			scope:target.house = scope:owner.top_liege.house
			desc = TARGET_HOLDER_EMPEROR_HOUSE_DESC
			add = -10
		}
		# Influence
		modifier = {
			desc = OWNER_INFLUENCE_LEVEL_DESC
			add = {
				value = scope:owner.influence_level
				multiply = 5
			}
		}
		modifier = {
			desc = TARGET_HOLDER_INFLUENCE_LEVEL_DESC
			add = {
				value = scope:target.influence_level
				multiply = -5
			}
		}
		# Favour
		opinion_modifier = {
			trigger = {
				NOT = {
					scope:owner.top_liege ?= scope:owner
				}
			}
			who = scope:owner.top_liege
			opinion_target = scope:owner
			multiplier = 0.2
		}
		opinion_modifier = {
			who = scope:owner.top_liege
			opinion_target = scope:target
			multiplier = -0.2
		}
		# house_head_request_interaction
		modifier = {
			add = political_scheme_variable_list_value
			scope:owner = {
				has_variable_list = supporting_political_schemes
			}
			desc = HOUSE_HEAD_SCHEME_SUPPORT_DESC
		}
		modifier = {
			add = -10
			scope:owner = { has_character_modifier = political_schemes_distracted_modifier }
			desc = political_schemes_distracted_modifier
		}
	}

	# On Actions
	## Add agents
	on_start = {
		# 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_intermediary
			add_agent_slot = agent_proponent
			add_agent_slot = agent_sycophant
			add_agent_slot = agent_political_socialite
			add_agent_slot = agent_bureaucrat
		}
	}
	on_phase_completed = {
		suppress_scheme_follow_up_event_till_input_given_effect = yes
		regula_forge_inheritance_law_scheme_prep_effect = yes
		cap_schemes_and_fire_reminders_effect = yes
	}
	on_hud_click  = { regula_forge_inheritance_law_scheme_prep_effect = yes }
	on_semiyearly = {
		if = {
			limit = {
				scheme_owner = { is_ai = yes }
			}
			regula_forge_inheritance_law_scheme_prep_effect = yes
		}
	}
	
	on_monthly = {
		hostile_scheme_monthly_discovery_chance_effect = yes
		if = {
			limit = {
				NOT = { exists = scope:discovery_event_happening }
			}
			fire_generic_contract_scheme_on_going_events_effect = yes
		}
	}

	## Invalidation
	on_invalidated = {
		scheme_owner = { save_scope_as = owner }
		scheme_target_character = { save_scope_as = target }

		if = {
			limit = {
				scope: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
				}
			}
		}
		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
				}
			}
		}
	}
}
