﻿namespace = regula_holy_bloodline_events

# Custom major decision event triggered by the "Consecrate Bloodline" decision. This will apply special traits to all members of your dynasty.
regula_holy_bloodline_events.0001 = {
	type = character_event
	title = regula_holy_bloodline_events.0001.t

	desc = regula_holy_bloodline_events.0001.desc

	theme = faith

	left_portrait = {
		character = root
		animation = personality_zealous
	}

	right_portrait = {
		character = scope:domina
		animation = admiration
	}

	immediate = {
		play_music_cue = "mx_cue_sacredrite"
		hidden_effect = {
			primary_spouse ?= {
				save_scope_as = domina
			}
			dynasty = {
				set_variable = {
					name = variable_made_bloodline_holy
					value = yes
				}
			}
		}
	}

	option = {
		name = regula_holy_bloodline_events.0001.a

		set_nickname_effect = { NICKNAME = regula_nickname_holy_magister }
		# All live descendants get the descendant trait
		declare_regula_bloodline_holy_decision_effect = yes
	}
}

# Adds holy blood "Sacrutus Genus" to all applicable characters
regula_holy_bloodline_events.0002 = {
	type = character_event
	hidden = yes
	
	trigger = {
		OR = {
			mother ?= {
				has_sacrutus_genus_trait = yes
			}
			father ?= {
				has_sacrutus_genus_trait = yes
			}
		}
		has_sacrutus_genus_trait = no
	}
	
	# If father is Magister and mother is uncharmed, then 25% chance of getting Sacrutus Dimidium
	# If father/mother has Sacrutus Genus Sanguis, then we get Sacrutus Genus Sanguis, if mother is not devoted then 50% chance of Dimidium
	immediate = {
		# Magister is father
		if = {
			limit = {
				father ?= {
					has_trait = magister_trait_group
				}
			}
			# Check if mother is charmed
			if = {
				limit = {
					mother ?= {
						has_trait = devoted_trait_group
					}
				}
				add_trait = regula_sacrutus_genus_sanguis
			}
			else = {
				random_list = {
					75 = {
						add_trait = regula_sacrutus_genus_sanguis
					}
					25 = {
						add_trait = regula_sacrutus_genus_dimidium
					}
				}
			}
		}

		# Father/Mother already has holy blood (and mother is charmed)
		if = {
			limit = {
				OR = {
					mother ?= {
						has_sacrutus_genus_trait = yes
						has_trait = devoted_trait_group
					}
					father ?= {
						has_sacrutus_genus_trait = yes
					}
				}
			}
			add_trait = regula_sacrutus_genus_sanguis
		}

		# Father/Mother already has holy blood (and mother is NOT charmed)
		if = {
			limit = {
				OR = {
					mother ?= {
						has_sacrutus_genus_trait = yes
						NOT = { has_trait = devoted_trait_group }
					}
					father ?= {
						has_sacrutus_genus_trait = yes
					}
				}
			}
			random_list = {
				50 = {
					add_trait = regula_sacrutus_genus_sanguis
				}
				50 = {
					add_trait = regula_sacrutus_genus_dimidium
				}
			}
		}

		# Recursively do this for children
		every_child = {
			even_if_dead = yes
			trigger_event = regula_holy_bloodline_events.0002
		}
	}
}

# If we have "Sacrutus Dimidium" then we can regain Sacrutus Sanguis if mother becomes charmed
regula_holy_bloodline_events.0003 = {
	type = character_event
	hidden = yes
	
	trigger = {
		has_trait = regula_sacrutus_genus_dimidium
	}
	
	# If mother becomes charmed we regain Sacrutus Sanguis
	immediate = {
		# Check if mother is charmed
		if = {
			limit = {
				mother ?= {
					has_trait = devoted_trait_group
				}
			}
			remove_trait = regula_sacrutus_genus_dimidium
			add_trait = regula_sacrutus_genus_sanguis
		}
	}
}