﻿lwxxx_display_last_will_abdication_event_trigger = {
	not = { exists = global_var:lwxxx_do_not_display_last_will_abdication_event }
}

lwxxx_has_authority_trigger = {
	trigger_if = {
		limit = {
			or = {
				government_has_flag = government_is_feudal
				government_has_flag = government_is_clan
			}
		}

		custom_description = {
			text = last_will_succession_law_insufficient_crown_authority_custom_description
			or = {
				has_realm_law = crown_authority_1
				has_realm_law = crown_authority_2
				has_realm_law = crown_authority_3
			}
		}
	}
	trigger_if = {
		limit = {
			government_has_flag = government_is_tribal
		}

		custom_description = {
			text = last_will_succession_law_insufficient_tribal_authority_custom_description
			or = {
				has_realm_law = tribal_authority_1
				has_realm_law = tribal_authority_2
				has_realm_law = tribal_authority_3
			}
		}
	}
}

lwxxx_admin_or_laamp_trigger = {
	or = {
		government_allows = administrative
		is_landless_adventurer = yes
	}
}
lwxxx_last_will_succession_law_can_keep_trigger = {
	trigger_if = {
		limit = {
			has_realm_law = last_will_succession_law
			lwxxx_admin_or_laamp_trigger = no
		}

		lwxxx_last_will_succession_law_can_have_trigger = yes
	}
}

lwxxx_last_will_succession_law_can_have_trigger = {
	is_ai = no
	lwxxx_has_authority_trigger = yes
	lwxxx_admin_or_laamp_trigger = no
}

lwxxx_last_will_succession_law_can_pass_trigger = {
	lwxxx_admin_or_laamp_trigger = no
}

lwxxx_title_has_last_will_claimant_trigger = {
	has_variable = lwxxx_last_will_claimant
}

lwxxx_claim_to_county_trigger = {
	save_temporary_scope_as = lwxxx_claimant
	$TITLE$ = { save_temporary_scope_as = lwxxx_title_claim }
	$HOLDER$ = { save_temporary_scope_as = lwxxx_title_holder }

	any_claim = {
		this = scope:lwxxx_title_claim
		has_title_law = lwxxx_last_will_elective_succession_law
		holder = scope:lwxxx_title_holder
	}
}

lwxxx_claim_to_other_county_trigger = {
	save_temporary_scope_as = lwxxx_claimant
	$TITLE$ = { save_temporary_scope_as = lwxxx_title_claim }
	$HOLDER$ = { save_temporary_scope_as = lwxxx_title_holder }

	any_claim = {
		tier = tier_county
		not = { this = scope:lwxxx_title_claim }
		has_title_law = lwxxx_last_will_elective_succession_law
		holder = scope:lwxxx_title_holder
	}
}

lwxxx_claim_to_higher_title_trigger = {
	save_temporary_scope_as = lwxxx_claimant
	$TITLE$ = { save_temporary_scope_as = lwxxx_title_claim }
	$HOLDER$ = { save_temporary_scope_as = lwxxx_title_holder }

	any_claim = {
		tier >= tier_duchy
		not = { this = scope:lwxxx_title_claim }
		has_title_law = lwxxx_last_will_elective_succession_law
		holder = scope:lwxxx_title_holder
	}
}

lwxxx_elected_to_any_county_trigger = {
	save_temporary_scope_as = lwxxx_claimant
	$HOLDER$ = { save_temporary_scope_as = lwxxx_title_holder }

	any_claim = {
		tier = tier_county
		custom_description = {
			text = lwxxx_title_does_not_have_last_will_law_description
			has_title_law = lwxxx_last_will_elective_succession_law
		}
		holder = scope:lwxxx_title_holder
		save_temporary_scope_as = lwxxx_elective_title
		custom_description = {
			text = lwxxx_claimant_does_not_have_holder_vote_description
			scope:lwxxx_claimant = { has_election_vote_of = { who = scope:lwxxx_title_holder title = scope:lwxxx_elective_title } }
		}
	}
}

lwxxx_elected_to_other_county_trigger = {
	save_temporary_scope_as = lwxxx_claimant
	$TITLE$ = { save_temporary_scope_as = lwxxx_title_claim }
	$HOLDER$ = { save_temporary_scope_as = lwxxx_title_holder }

	any_claim = {
		tier = tier_county
		not = { this = scope:lwxxx_title_claim }
		has_title_law = lwxxx_last_will_elective_succession_law
		holder = scope:lwxxx_title_holder
		save_temporary_scope_as = lwxxx_elective_title
		scope:lwxxx_claimant = { has_election_vote_of = { who = scope:lwxxx_holder title = scope:lwxxx_elective_title } }
	}
}

lwxxx_elected_to_higher_title_trigger = {
	save_temporary_scope_as = lwxxx_claimant
	$TITLE$ = { save_temporary_scope_as = lwxxx_title_claim }
	$HOLDER$ = { save_temporary_scope_as = lwxxx_title_holder }

	any_claim = {
		tier >= tier_duchy
		not = { this = scope:lwxxx_title_claim }
		has_title_law = lwxxx_last_will_elective_succession_law
		holder = scope:lwxxx_title_holder
		save_temporary_scope_as = lwxxx_elective_title
		scope:lwxxx_claimant = { has_election_vote_of = { who = scope:lwxxx_holder title = scope:lwxxx_elective_title } }
	}
}
