﻿namespace = regula_incapable

regula_incapable.1000 = {
	type = character_event
	title = regula_incapable.1000.t
	desc = regula_incapable.1000.desc
	theme = court
	
	override_background = {
		reference = regula_holy_order_interior
	}
	
	left_portrait = {
		character = global_var:magister_character.primary_spouse
		animation = grief
	}

	right_portrait = {
		character = global_var:magister_character.primary_heir
		animation = worry
	}

	trigger = {
		has_trait = magister_trait_group
		has_trait = incapable
		is_ai = no
		NOT = {
			has_character_flag = flag_regula_incapable_cooldown
		}
		global_var:magister_character.primary_spouse = {
			exists = this
		}
		global_var:magister_character.primary_heir = {
			exists = this
			is_adult = yes
		}
	}

	immediate = {
		global_var:magister_character.primary_spouse = {
			save_scope_as = domina
		}
		global_var:magister_character.primary_heir = {
			save_scope_as = heir
		}
		global_var:magister_character = {
			save_scope_as = incapable_magister
		}
		every_child = {
			limit = {
				father = global_var:magister_character
				mother = { has_trait = devoted_trait_group }
				NOT = { this = global_var:magister_character.primary_heir }
				is_adult = no
				is_landed = no
				is_alive = yes
			}
			add_to_list = children_of_magister
		}
	}
	
	option = { # You sever the connection with the Keeper of Souls
		name = regula_incapable.1000.a
		add_internal_flag = dangerous
		highlight_portrait = scope:domina
		
		scope:incapable_magister = {
			custom_description_no_bullet = { text = regula_incapable_depose }
			custom_tooltip = regula_incapable.1000.a.tt
			custom_tooltip = stress_threshold.3411.l.tt
			
			hidden_effect = {	#Make all weak claims on your titles into strong claims.
				every_held_title = {
					save_temporary_scope_as = abdicator_title
					every_claimant = {
						limit = { has_weak_claim_on = scope:abdicator_title }
						make_claim_strong = scope:abdicator_title
					}
				}
				death = {
					death_reason = death_cutoff_from_keeper_of_souls
				}
				every_consort = {
					stress_impact = {
						base = medium_stress_gain
						zealous = medium_stress_gain
						cynical = medium_stress_loss
						compassionate = medium_stress_gain
						callous = medium_stress_loss
						sadistic = medium_stress_loss
					}
				}
			}
		}
		
		scope:incapable_magister.faith = {
			change_fervor = {
				value = -25
				desc = regula_incapable_1000.a_fervor_change
			}
		}
	}
	
	# A ritual sacrifice is performed to save you
	## Your heir is sacrificed along with a varying amount of children. The amount is determined by your piety level and the total number of children you have. The children selected is random. Only non-adult/non-landed children are selected.
	option = {
		name = regula_incapable.1000.b
		custom_description_no_bullet = { text = regula_incapable_sacrifice }
		add_internal_flag = dangerous
		trigger = {
			regula_harem_learning_skill >= regula_num_harem_times_15 # (Devoted spouses' combined learning skill) >= (Number of devoted spouses * 15) ##Essentially, the average learning skill of your spouses would need to be 15 or greater##
		}
		
		regula_incapable_select_sacrifice_effect = yes # Selects children at random for the sacrifice
		
		scope:incapable_magister = {
			stress_impact = {
				base = massive_stress_gain
				arrogant = massive_stress_loss
				humble = massive_stress_gain
			}
			remove_trait = incapable
		}
	}
	
	# Heir takes matters into his own hands
	option = {
		name = regula_incapable.1000.c
		scope:incapable_magister = {
			death = {
				death_reason = death_murder
				killer = scope:heir
			}
		}
		scope:heir = {
			stress_impact = {
				ambitious = major_stress_loss
				callous = minor_stress_loss
				sadistic = minor_stress_loss
				content = minor_stress_gain
				compassionate = major_stress_gain
			}
			add_piety = major_piety_loss
			custom_tooltip = regula_incapable.1000.c.tt
		}
		scope:incapable_magister.faith = {
			change_fervor = {
				value = -25
				desc = regula_incapable_1000.c_fervor_change
			}
		}
		hidden_effect = {
			every_living_character = {
				limit = {
					AND = {
						NOT = {
							this = scope:incapable_magister
							this = scope:heir
							this = scope:domina
						}
						OR = {
							is_close_or_extended_family_of = scope:incapable_magister
							has_faith = scope:incapable_magister.faith
						}
					}
				}
				add_opinion = {
					target = scope:heir
					modifier = regula_assassinated_incapable_magister
				}
			}
		}			
	}
	
	# Nothing happens - continue playing with the incapable trait
	option = {
		name = regula_incapable.1000.d
		custom_description_no_bullet = { text = regula_incapable_do_nothing }
		
		scope:domina = {
			add_stress = major_stress_impact_gain
		}
		
		scope:heir = {
			add_stress = major_stress_impact_gain
		}
		
		hidden_effect = {
			scope:incapable_magister = {
				every_consort = {
					limit = {
						has_trait = devoted_trait_group
						NOR = {
							scope:domina = this
							scope:paelex = this
						}
					}
					stress_impact = {
						base = major_stress_gain
						ambitious = medium_stress_gain
						content = medium_stress_loss
						impatient = medium_stress_gain
						patient = medium_stress_loss
						compassionate = medium_stress_gain
						callous = medium_stress_loss
					}
				}
			}
		}
	}
	
	after = {
		scope:incapable_magister = {
			add_character_flag = {
				flag = flag_regula_incapable_cooldown
				years = 10
			}
		}
	}
}

regula_incapable.2000 = {
	type = character_event
	title = regula_incapable.2000.t
	desc = regula_incapable.2000.desc
	theme = court
	
	override_background = {
		reference = regula_holy_order_interior
	}
	
	left_portrait = {
		character = global_var:magister_character.primary_spouse
		animation = worry
	}
	
	right_portrait = {
		character = scope:paelex
		animation = grief
	}

	lower_right_portrait = {
		character = global_var:magister_character.primary_heir
	}

	trigger = {
		has_trait = magister_trait_group
		has_trait = incapable
		is_ai = no
		NOT = {
			has_character_flag = flag_regula_incapable_cooldown
		}
		global_var:magister_character.primary_spouse = {
			exists = this
		}
		global_var:magister_character.primary_heir = {
			exists = this
			is_adult = no
		}
		any_spouse = {
			has_trait = paelex
		}
	}

	immediate = {
		global_var:magister_character.primary_spouse = {
			save_scope_as = domina
		}
		global_var:magister_character.primary_heir = {
			save_scope_as = heir
		}
		global_var:magister_character = {
			save_scope_as = incapable_magister
		}
		random_spouse = {
			limit = {
				has_trait = paelex
			}
			save_scope_as = paelex
		}
		every_child = {
			limit = {
				father = global_var:magister_character
				mother = { has_trait = devoted_trait_group }
				NOT = { this = global_var:magister_character.primary_heir }
				is_adult = no
				is_landed = no
				is_alive = yes
			}
			add_to_list = children_of_magister
		}
	}
	
	option = { # You sever the connection with the Keeper of Souls despite underage heir
		name = regula_incapable.2000.a
		add_internal_flag = dangerous
		highlight_portrait = scope:domina
		
		scope:incapable_magister = {
			custom_description_no_bullet = { text = regula_incapable_depose }
			custom_tooltip = regula_incapable.2000.a.tt
			custom_tooltip = stress_threshold.3411.l.tt
			
			hidden_effect = {	#Make all weak claims on your titles into strong claims.
				every_held_title = {
					save_temporary_scope_as = abdicator_title
					every_claimant = {
						limit = { has_weak_claim_on = scope:abdicator_title }
						make_claim_strong = scope:abdicator_title
					}
				}
				death = {
					death_reason = death_cutoff_from_keeper_of_souls
				}
				every_consort = {
					stress_impact = {
						base = medium_stress_gain
						zealous = medium_stress_gain
						cynical = medium_stress_loss
						compassionate = medium_stress_gain
						callous = medium_stress_loss
						sadistic = medium_stress_loss
					}
				}
			}
		}
		
		scope:incapable_magister.faith = {
			change_fervor = {
				value = -25
				desc = regula_incapable_1000.a_fervor_change
			}
		}
	}
	
	# A ritual sacrifice is performed to save you
	## Your heir is sacrificed along with a varying amount of children. The amount is determined by your piety level and the total number of children you have. The children selected is random. Only non-adult/non-landed children are selected.
	option = {
		name = regula_incapable.2000.b
		custom_description_no_bullet = { text = regula_incapable_sacrifice }
		add_internal_flag = dangerous
		trigger = {
			regula_harem_learning_skill >= regula_num_harem_times_15 # (Devoted spouses' combined learning skill) >= (Number of devoted spouses * 15) ##Essentially, the average learning skill of your spouses would need to be 15 or greater##
		}
		
		regula_incapable_select_sacrifice_effect = yes # Selects children at random for the sacrifice
		
		scope:incapable_magister = {
			stress_impact = {
				base = massive_stress_gain
				arrogant = massive_stress_loss
				humble = massive_stress_gain
			}
			remove_trait = incapable
		}
	}
	
	# Nothing happens - continue playing with the incapable trait
	option = {
		name = regula_incapable.2000.c
		custom_description_no_bullet = { text = regula_incapable_do_nothing }
		
		scope:domina = {
			add_stress = major_stress_impact_gain
		}
		
		scope:paelex = {
			add_stress = major_stress_impact_gain
		}
		
		hidden_effect = {
			scope:incapable_magister = {
				every_consort = {
					limit = {
						has_trait = devoted_trait_group
						NOR = {
							scope:domina = this
							scope:paelex = this
						}
					}
					stress_impact = {
						base = major_stress_gain
						ambitious = medium_stress_gain
						content = medium_stress_loss
						impatient = medium_stress_gain
						patient = medium_stress_loss
						compassionate = medium_stress_gain
						callous = medium_stress_loss
					}
				}
			}
		}
	}
	
	after = {
		scope:incapable_magister = {
			add_character_flag = {
				flag = flag_regula_incapable_cooldown
				years = 10
			}
		}
	}
}
