﻿rtd_reincarnate_the_dead = { #scope: player character
	scope = character
	saved_scopes = { gui_character }

	# is_shown = {}
	is_valid = {
		NOT = { has_character_flag = reincarnating }
		scope:gui_character = {
			NOT = { has_trait = reincarnation }
		}
		trigger_if = {
			limit = {
				debug_only = no
			}
			scope:gui_character = {
				trigger_if = {
					limit = {
						NOT = { has_game_rule = rtd_rule_coexistence_limit_free }
					}
					rtd_value_num_of_scions < rtd_value_coexistence_limit
				}
			}
			NOT = { has_character_modifier = rtd_modifier_reincarnated_recently }
			piety >= rtd_value_piety_cost
			custom_description = {
				text = not_enough_same_heritage_counties
				subject = scope:gui_character
				any_sub_realm_county = {
					count >= rtd_value_same_heritage_counties
					culture = { has_same_culture_heritage = scope:gui_character.culture }
				}
			}
		}
	}
	effect = {
		add_character_flag = reincarnating
		save_scope_as = player_character

		custom_tooltip = rtd_reincarnate_the_dead.tt

		if = {
			limit = {
				debug_only = no
			}
			add_piety = {
				value = rtd_value_piety_cost
				multiply = -1
			}
			add_character_modifier = {
				modifier = rtd_modifier_reincarnated_recently
				years = rtd_value_cooldown
			}
		}

		trigger_event = rtd_reincarnate_the_dead.01
	}
}