﻿diarch_coup_attempt_is_valid_trigger = {
	# Diarchy checks.
	is_diarch = yes
	$LIEGE$ = { has_diarchy_active_parameter = regents_can_try_to_overthrow_present_lieges }
	## Liege must be physically present to overthrow. You can't coup them whilst they're abroad.
	$LIEGE$ = {
		is_imprisoned = no
		is_travelling = no
		is_at_war = no
		custom_tooltip = {
			text = custom.not_attending_activity
			NOT = { exists = involved_activity }
		}
		age >= 5
	}
	# Support checks.
	## Have you gathered enough support from the realm's powerful vassals and/or councillors?
	trigger_if = {
		limit = {
			liege = {
				OR = {
					any_powerful_vassal = { count > 0 }
					any_powerful_family = { count > 0 }
				}
			}
		}
		custom_tooltip = {
			text = diarch_attempt_to_overthrow_liege.tt.majority_powerful_vassal_support
			subject = root
			has_variable_list = coup_pv_supporters_list
			any_in_list = {
				variable = coup_pv_supporters_list
				count >= pv_overthrow_threshold_value
				# Double check they're still valid.
				diarch_coup_valid_conspiracy_culmination_vassals_trigger = { LIEGE = $LIEGE$ }
			}
		}
	}
	# As a speed-bump, we check how long this diarchy has been on for.
	OR = {
		# Either, you've been a diarch for a good long ways.
		trigger_if = {
				limit = {
					has_variable = RewReg_diarchy_year_diarch_title
				}
				custom_tooltip = {
					text = RegRew_diarche_coup_trigger_years.tt
					var:RewReg_diarchy_year_diarch_title > RegRew_months_diarch_value
				}
			}
		# Or, you haven't been but everyone is kinda used to the concept of a diarch.
		AND = {
			years_as_diarch >= 4
			$LIEGE$ = { years_in_diarchy >= 10 }
		}
		# OR, you've laid the groundwork for such a coup already
		custom_tooltip = {
			text = diarch_attempt_to_overthrow_liege_bypass
			has_character_flag = laid_coup_groundwork_flag
		}
	}
	# And finally, for ease of sanity, your liege must be of a certain size.
	$LIEGE$.sub_realm_size >= minor_realm_size
}

regency_for_personal_reasons_trigger = {
	OR = {
		custom_tooltip = {
			text = regency_for_personal_reasons_trigger.tt.cannot_govern_by_themselves
			OR = {
				AND = {
					is_adult = no
					NOT = {
						liege = { has_diarchy_parameter = diarchy_type_is_junior_emperorship }
					}
				}
				is_incapable = yes
				has_character_modifier = isolating_modifier				
			}
		}
		custom_tooltip = {
			text = Reg_Rew_need_to_diarch_text
			has_character_flag = diarchy_away_in_war
		}
	}
}


