namespace = regula_bloodline

# 0000-0999: Eligibility events
# 1000-1999: Magister events
# 2000-2999: Generic events

######################################################
# ELIGIBILITY EVENTS
# 0000-0999
######################################################

regula_bloodline.0001 = { # Potestas non Transfunde Queen record.
	type = character_event
	hidden = yes

	trigger = {
		NOT = { global_var:regula_potestas_queen_bloodline_active = yes }
		global_var:magister_character = {
			NOT = { has_trait = regula_potestas_queen_bloodline }
			var:regula_potestas_queen_tally >= 4
		}
	}

	immediate = {
		set_global_variable = {
			name = last_magister_character
			value = global_var:magister_character
		}
		global_var:magister_character.primary_heir = {
			trigger_event = {
				id = regula_bloodline.1001
				days = 35
			}
		}
	}
}

regula_bloodline.0002 = { # Servitude War record.
	type = character_event
	hidden = yes

	trigger = {
		NOT = { global_var:regula_servitude_war_bloodline_active = yes }
		global_var:magister_character = {
			NOT = { has_trait = regula_servitude_war_bloodline }
			var:regula_servitude_war_tally >= 5
		}
	}

	immediate = {
		set_global_variable = {
			name = last_magister_character
			value = global_var:magister_character
		}
		global_var:magister_character.primary_heir = {
			trigger_event = {
				id = regula_bloodline.1002
				days = 35
			}
		}
	}
}

regula_bloodline.0003 = { # Domination War record.
	type = character_event
	hidden = yes

	trigger = {
		NOT = { global_var:regula_domination_war_bloodline_active = yes }
		global_var:magister_character = {
			NOT = { has_trait = regula_domination_war_bloodline }
			var:regula_domination_war_tally >= 10
		}
	}

	immediate = {
		set_global_variable = {
			name = last_magister_character
			value = global_var:magister_character
		}
		global_var:magister_character.primary_heir = {
			trigger_event = {
				id = regula_bloodline.1003
				days = 35
			}
		}
	}
}

regula_bloodline.0004 = { # Contubernalis record.
	type = character_event
	hidden = yes

	trigger = {
		NOT = { global_var:regula_contubernalis_bloodline_active = yes }
		global_var:magister_character = {
			NOT = { has_trait = regula_contubernalis_bloodline }
			var:regula_contubernalis_tally >= 5
		}
	}

	immediate = {
		set_global_variable = {
			name = last_magister_character
			value = global_var:magister_character
		}
		global_var:magister_character.primary_heir = {
			trigger_event = {
				id = regula_bloodline.1004
				days = 35
			}
		}
	}
}


regula_bloodline.0005 = { # Domitans Tribunal record.
	type = character_event
	hidden = yes

	trigger = {
		NOT = { global_var:regula_domitans_bloodline_active = yes }
		global_var:magister_character = {
			NOT = { has_trait = regula_domitans_bloodline }
			var:regula_domitans_tally >= 20
		}
	}

	immediate = {
		set_global_variable = {
			name = last_magister_character
			value = global_var:magister_character
		}
		global_var:magister_character.primary_heir = {
			trigger_event = {
				id = regula_bloodline.1005
				days = 35
			}
		}
	}
}

regula_bloodline.0006 = { # Fascinare record.
	type = character_event
	hidden = yes

	trigger = {
		NOT = { global_var:regula_fascinare_bloodline_active = yes }
		global_var:magister_character = {
			NOT = { has_trait = regula_fascinare_bloodline }
			var:regula_fascinare_tally >= 40
		}
	}

	immediate = {
		set_global_variable = {
			name = last_magister_character
			value = global_var:magister_character
		}
		global_var:magister_character.primary_heir = {
			trigger_event = {
				id = regula_bloodline.1006
				days = 35
			}
		}
	}
}


regula_bloodline.0021 = { # Pregnant lovers/spouses record. Called on pregnancy.
	type = character_event
	hidden = yes

	trigger = {
		is_married = yes
		OR = {
			root.primary_spouse = {
				NOT = { has_trait = regula_multitasker_bloodline }
				NOT = { has_trait = magister_trait_group }
				regula_num_pregnant_consorts_and_lovers >=3
			}
			root.primary_spouse = {
				NOT = { has_trait = regula_multitasker_bloodline }
				regula_num_pregnant_consorts_and_lovers >=8
			}
		}
	}

	immediate = {
		root.primary_spouse = {	
			trigger_event = {
				id = regula_bloodline.2021
				days = 35
			}
		}
	}
}

regula_bloodline.0022 = { # Number of children record. Called on pregnancy.
	type = character_event
	hidden = yes

	trigger = {
		regula_num_children >= 6
	}

	immediate = {
		trigger_event = {
			id = regula_bloodline.2022
			days = 35
		}
	}
}


regula_bloodline.0023 = { # Twins adjustment for those with Bun in the Oven. Called on pregnancy.
	type = character_event
	hidden = yes

	trigger = {
		has_trait = regula_bun_bloodline
	}

	immediate = {
		random = {
			chance = 20
			set_num_pregnancy_children = 2
		}
		random = {
			chance = 10
			set_num_pregnancy_children = 3
		}
		random = {
			chance = 5
			set_num_pregnancy_children = 4
		}
	}
}

######################################################
# MAGISTER EVENTS
# 1000-1999
######################################################

regula_bloodline.1000 = { #Inheritance from grandparents
	type = character_event
	hidden = yes

	trigger = {
		any_close_family_member = {
			even_if_dead = yes
			has_trait_with_flag = regula_bloodline_magister
		}
	}

	immediate = {
		if = {
			limit = {
				NOT = { has_trait = regula_potestas_queen_bloodline }
				any_close_family_member = {
					has_trait = regula_potestas_queen_bloodline
				}
			}
			add_trait = regula_potestas_queen_bloodline
		}
		if = {
			limit = {
				NOT = { has_trait = regula_servitude_war_bloodline }
				any_close_family_member = {
					has_trait = regula_servitude_war_bloodline
				}
			}
			add_trait = regula_servitude_war_bloodline
		}
		if = {
			limit = {
				NOT = { has_trait = regula_domination_war_bloodline }
				any_close_family_member = {
					has_trait = regula_domination_war_bloodline
				}
			}
			add_trait = regula_domination_war_bloodline
		}
		if = {
			limit = {
				NOT = { has_trait = regula_contubernalis_bloodline }
				any_close_family_member = {
					has_trait = regula_contubernalis_bloodline
				}
			}
			add_trait = regula_contubernalis_bloodline
		}
		if = {
			limit = {
				NOT = { has_trait = regula_domitans_bloodline }
				any_close_family_member = {
					has_trait = regula_domitans_bloodline
				}
			}
			add_trait = regula_domitans_bloodline
		}
		if = {
			limit = {
				NOT = { has_trait = regula_fascinare_bloodline }
				any_close_family_member = {
					has_trait = regula_fascinare_bloodline
				}
			}
			add_trait = regula_fascinare_bloodline
		}
	}
}


regula_bloodline.1001 = { # Potestas of Queens
	type = character_event
	title = regula_bloodline.1001.t
	desc = regula_bloodline.1001.desc

	theme = regula_theme
	override_background = {
		event_background = godless_shrine
	}
	right_portrait = {
		character = global_var:magister_character
		animation = personality_bold
	}
	lower_right_portrait = {
			character = global_var:last_magister_character
	}
	
	immediate = {
		global_var:last_magister_character = {
			regula_bloodline_addition_effect = { BLOODLINE = regula_potestas_queen_bloodline }
			set_global_variable = {
				name = potestas_queen_bloodline_magister
				value = global_var:last_magister_character
			}
		}
	}

	option = { # Great!
		name = regula_bloodline.1001.a

		set_global_variable = {
			name = regula_potestas_queen_bloodline_active
			value = yes
		}
	}

	after = {
	}
}


regula_bloodline.1002 = { # Servitude War
	type = character_event
	title = regula_bloodline.1002.t
	desc = regula_bloodline.1002.desc

	theme = regula_theme
	override_background = {
		event_background = throne_room  # Town?
	}
	right_portrait = {
		character = global_var:magister_character
		animation = flirtation
	}
	lower_right_portrait = {
			character = global_var:last_magister_character
	}
	
	immediate = {
		global_var:last_magister_character = {
			regula_bloodline_addition_effect = { BLOODLINE = regula_servitude_war_bloodline }
			set_global_variable = {
				name = servitude_war_bloodline_magister
				value = global_var:last_magister_character
			}
		}
	}

	option = { # Great!
		name = regula_bloodline.1002.a

		set_global_variable = {
			name = regula_servitude_war_bloodline_active
			value = yes
		}
	}

	after = {
	}
}


regula_bloodline.1003 = { # Domination War
	type = character_event
	title = regula_bloodline.1003.t
	desc = regula_bloodline.1003.desc

	theme = regula_theme
	override_background = {
		event_background = regula_bedchamber
	}
	right_portrait = {
		character = global_var:magister_character
		animation = personality_bold
	}
	lower_right_portrait = {
			character = global_var:last_magister_character
	}
	
	immediate = {
		global_var:last_magister_character = {
			regula_bloodline_addition_effect = { BLOODLINE = regula_domination_war_bloodline }
			set_global_variable = {
				name = domination_war_bloodline_magister
				value = global_var:last_magister_character
			}
		}
	}

	option = { # Great!
		name = regula_bloodline.1003.a

		set_global_variable = {
			name = regula_domination_war_bloodline_active
			value = yes
		}
	}

	after = {
	}
}


regula_bloodline.1004 = { # Contubernalis
	type = character_event
	title = regula_bloodline.1004.t
	desc = regula_bloodline.1004.desc

	theme = regula_theme
	override_background = {
		event_background = physicians_study
	}
	right_portrait = {
		character = global_var:magister_character
		animation = disapproval
	}
	lower_right_portrait = {
			character = global_var:last_magister_character
	}
	
	immediate = {
		global_var:last_magister_character = {
			regula_bloodline_addition_effect = { BLOODLINE = regula_contubernalis_bloodline }
			set_global_variable = {
				name = contubernalis_bloodline_magister
				value = global_var:last_magister_character
			}
		}
	}

	option = { # Great!
		name = regula_bloodline.1004.a

		set_global_variable = {
			name = regula_contubernalis_bloodline_active
			value = yes
		}
	}

	after = {
	}
}


regula_bloodline.1005 = { # Domitans Tribunal
	type = character_event
	title = regula_bloodline.1005.t
	desc = regula_bloodline.1005.desc

	theme = regula_theme
	override_background = {
		event_background = godless_shrine
	}
	right_portrait = {
		character = global_var:magister_character
		animation = personality_compassionate
	}
	lower_right_portrait = {
			character = global_var:last_magister_character
	}

	
	immediate = {
		global_var:last_magister_character = {
			regula_bloodline_addition_effect = { BLOODLINE = regula_domitans_bloodline }
			set_global_variable = {
				name = domitans_bloodline_magister
				value = global_var:last_magister_character
			}
		}
	}

	option = { # Great!
		name = regula_bloodline.1005.a

		set_global_variable = {
			name = regula_domitans_bloodline_active
			value = yes
		}
		global_var:last_magister_character = {
			regula_bloodline_addition_effect = { BLOODLINE = regula_domitans_bloodline }
			set_global_variable = {
				name = domitans_bloodline_magister
				value = global_var:last_magister_character
			}
		}
	}

	after = {
	}
}


regula_bloodline.1006 = { # Fascinare
	type = character_event
	title = regula_bloodline.1006.t
	desc = regula_bloodline.1006.desc

	theme = regula_theme
	override_background = {
		event_background = sitting_room  # Town?
	}
	right_portrait = {
		character = global_var:magister_character
		animation = personality_compassionate
	}
	lower_right_portrait = {
			character = global_var:last_magister_character
	}
	
	immediate = {
		global_var:last_magister_character = {
			regula_bloodline_addition_effect = { BLOODLINE = regula_fascinare_bloodline }
			set_global_variable = {
				name = fascinare_bloodline_magister
				value = global_var:last_magister_character
			}
		}
	}

	option = { # Great!
		name = regula_bloodline.1006.a

		set_global_variable = {
			name = regula_fascinare_bloodline_active
			value = yes
		}

	}

	after = {
	}
}

######################################################
# GENERIC EVENTS
# 2000-2999
######################################################



regula_bloodline.2021 = { # Multitasker
	type = character_event
	hidden = yes

	
	immediate = {
		regula_bloodline_addition_effect = { BLOODLINE = regula_multitasker_bloodline }

		send_interface_toast = { # Tell the character
			title = regula_bloodline.2021.title
			desc = regula_bloodline.2021.personal_desc
			add_trait = regula_multitasker_bloodline
		}
	}

	after = {
	}
}

regula_bloodline.2022 = { # Bun in the Oven
	type = character_event
	hidden = yes

	immediate = {
		regula_bloodline_addition_effect = { BLOODLINE = regula_bun_bloodline }

		send_interface_toast = { # Tell the character
			title = regula_bloodline.2022.personal_desc
			add_trait = regula_bun_bloodline

		}

		every_spouse = { #Inform relevant parties.
			send_interface_message = {
				type = good_omen
				title = regula_bloodline.2022.t
				right_icon = root
				desc = regula_bloodline.2022.desc
			}
		}
	}

	after = {
	}
}
