﻿# Kills the selected children for the regula_incapable_events sacrifice
regula_incapable_sacrifice_child_effect = {
	death = {
		death_reason = death_sacrificed_to_keeper_of_souls
		killer = global_var:magister_character
	}
}

# Randomly selects children for the regula_incapable_events sacrifice
regula_incapable_select_sacrifice_effect = {
	if = {
		limit = {
			scope:incapable_magister = {
				piety_level = 0
			}
		}
		scope:heir = { # Heir is killed
			death = {
				death_reason = death_sacrificed_to_keeper_of_souls
				killer = scope:incapable_magister
			}
		}
	
		ordered_in_list = {
			list = children_of_magister
			max = 999 # Amount of children selected
			order_by = {
				value = fertility # Fertility is the most randomized attribute I could think of. Other things like weight, health, stress, or skills would have less RNG
			}			
		regula_incapable_sacrifice_child_effect = yes # Kills the children selected
		}
		
		regula_magister_sacrafice_piety_loss = { NUM_CHILDREN = regula_num_children } # Piety loss
	}
	
	else_if = {
		limit = {
			scope:incapable_magister = {
				piety_level = 1
			}
		}
		add_piety_level = -1
		
		scope:heir = { # Heir is killed
			death = {
				death_reason = death_sacrificed_to_keeper_of_souls
				killer = scope:incapable_magister
			}
		}
	
		ordered_in_list = {
			list = children_of_magister
			max = regula_num_children_divided_1_5 # Amount of children selected
			order_by = {
				value = fertility # Fertility is the most randomized attribute I could think of. Other things like weight, health, stress, or skills would have less RNG
			}			
		regula_incapable_sacrifice_child_effect = yes # Kills the children selected
		}
		
		regula_magister_sacrafice_piety_loss = { NUM_CHILDREN = regula_num_children_divided_1_5 } # Piety loss
	}
	else_if = {
		limit = {
			scope:incapable_magister = {
				piety_level = 2
			}
		}
		add_piety_level = -1
		
		scope:heir = { # Heir is killed
			death = {
				death_reason = death_sacrificed_to_keeper_of_souls
				killer = scope:incapable_magister
			}
		}
	
		ordered_in_list = {
			list = children_of_magister
			max = regula_num_children_divided_2 # Amount of children selected
			order_by = {
				value = fertility # Fertility is the most randomized attribute I could think of. Other things like weight, health, stress, or skills would have less RNG
			}			
		regula_incapable_sacrifice_child_effect = yes # Kills the children selected
		}
		
		regula_magister_sacrafice_piety_loss = { NUM_CHILDREN = regula_num_children_divided_2 } # Piety loss
	}
	else_if = {
		limit = {
			scope:incapable_magister = {
				piety_level = 3
			}
		}
		add_piety_level = -1
		
		scope:heir = { # Heir is killed
			death = {
				death_reason = death_sacrificed_to_keeper_of_souls
				killer = scope:incapable_magister
			}
		}
	
		ordered_in_list = {
			list = children_of_magister
			max = regula_num_children_divided_3 # Amount of children selected
			order_by = {
				value = fertility # Fertility is the most randomized attribute I could think of. Other things like weight, health, stress, or skills would have less RNG
			}			
		regula_incapable_sacrifice_child_effect = yes # Kills the children selected
		}
		
		regula_magister_sacrafice_piety_loss = { NUM_CHILDREN = regula_num_children_divided_3 } # Piety loss
	}
	else_if = {
		limit = {
			scope:incapable_magister = {
				piety_level = 4
			}
		}
		add_piety_level = -1
		
		scope:heir = { # Heir is killed
			death = {
				death_reason = death_sacrificed_to_keeper_of_souls
				killer = scope:incapable_magister
			}
		}
	
		ordered_in_list = {
			list = children_of_magister
			max = regula_num_children_divided_4 # Amount of children selected
			order_by = {
				value = fertility # Fertility is the most randomized attribute I could think of. Other things like weight, health, stress, or skills would have less RNG
			}			
		regula_incapable_sacrifice_child_effect = yes # Kills the children selected
		}
		
		regula_magister_sacrafice_piety_loss = { NUM_CHILDREN = regula_num_children_divided_4 } # Piety loss
	}
	else_if = {
		limit = {
			scope:incapable_magister = {
				piety_level = 5
			}
		}
		add_piety_level = -1
		
		scope:heir = { # Heir is killed
			death = {
				death_reason = death_sacrificed_to_keeper_of_souls
				killer = scope:incapable_magister
			}
		}
	
		ordered_in_list = {
			list = children_of_magister
			max = regula_num_children_divided_5 # Amount of children selected
			order_by = {
				value = fertility # Fertility is the most randomized attribute I could think of. Other things like weight, health, stress, or skills would have less RNG
			}			
		regula_incapable_sacrifice_child_effect = yes # Kills the children selected
		}
		
		regula_magister_sacrafice_piety_loss = { NUM_CHILDREN = regula_num_children_divided_5 } # Piety loss
	}
}

# The Magister loses piety per child sacrificed
# We lose more piety if we have the Sacred childbirth doctrine
# scope:incapable_magister should be Magister
# We need the $NUM_CHILDREN$ variable to count how much piety we lose
regula_magister_sacrafice_piety_loss = {
	if = { # Piety cost per sacrifice
		limit = {
			scope:incapable_magister.faith = {
				has_doctrine_parameter = piety_from_childbirth_active # Cost more if you have 'Sacred Childbirth'
			}
		}
		scope:incapable_magister = {
			add_piety = {
				value = $NUM_CHILDREN$
				multiply = -250
			}
		}
	}
	else = {
		scope:incapable_magister = {
			add_piety = {
				value = $NUM_CHILDREN$
				multiply = -100
			}
		}
	}
}
