﻿
#####################################################################
# EFFECT LIST
#####################################################################
# !!! Remember to add all new effects with a short description here !!!

#bastard_secret_check_effect
#bastard_real_father_suspicion_chance_effect
#remove_all_bastard_traits - Removes any and all relevant bastard traits, used primarily in the adoption interaction

#####################################################################
# EFFECTS
#####################################################################

#Sets the correct "parent house" for a known bastard
set_parent_house_effect = {
	if = {
		limit = {
			age < bastard_legitimacy_change_cutoff_age
		}
		if = {
			limit = {
				should_mother_give_house_to_bastard_trigger = yes
			}
			set_house = mother.house
		}
		else_if = {
			limit = {
				exists = father
				exists = father.house
			}
			set_house = father.house
		}
		else = {
			set_to_lowborn = yes
		}
	}
}

#Sets the correct bastard trait
add_bastard_trait_based_on_faith_effect = {
	if = {
		limit = {
			faith = {
				has_doctrine_parameter = bastards_none
			}
		}
		add_trait_force_tooltip = wild_oat
	}
	else = {
		add_trait_force_tooltip = bastard
		scope:father ?= {
			random_memory = {
				limit = {
					OR = {
						has_memory_type = first_born
						has_memory_type = twins_born
						has_memory_type = child_born
					}
					any_memory_participant = { scope:child ?= this }
				}
				set_variable = bastard
			}
		}
		scope:mother ?= {
			random_memory = {
				limit = {
					OR = {
						has_memory_type = first_born
						has_memory_type = twins_born
						has_memory_type = child_born
					}
					any_memory_participant = { scope:child ?= this }
				}
				set_variable = bastard
			}
		}
		scope:real_father = {
			scope:child = {
				if = {
					limit = { has_trait = twin }
					random_sibling = {
						limit = { is_twin_of = scope:child }
						save_scope_as = child_2
					}
				}
			}
			if = {
				limit = {
					NOR = {
						any_child = {
							even_if_dead = yes
							this != scope:child
						}
						exists = scope:child_2
					}
				}
				create_character_memory = {
					type = first_born
					participants = { child = scope:child }
				}
			}
			else = {
				if = {
					limit = { exists = scope:child_2 }
					create_character_memory = {
						type = twins_born
						participants = {
							child = scope:child
							child_2 = scope:child_2
						}
					}
				}
				else = {
					create_character_memory = {
						type = child_born
						participants = { child = scope:child }
					}
				}
			}
			scope:new_memory = { set_variable = bastard }
		}
	}
}


#Sets correct bastard trait and parentage depending on age


#Replaces one bastard-type trait with another as faith changes
replace_bastard_trait_based_on_faith_effect = {
	if = {
		limit = {
			has_trait = bastard
		}
		if = {
			limit = {
				faith = {
					has_doctrine_parameter = bastards_none
				}
			}
			remove_trait = bastard
			add_trait_force_tooltip = wild_oat
		}
		else = {
			add_trait_force_tooltip = bastard
		}
	}
}



pregnancy_spouse_suspicion_chance_effect = {
	hidden_effect = { #Scopes mother and real_father exist
		save_scope_as = spouse
		random_list = {
			0 = { #Father is suspicious
				trigger = {
					accepts_adultery_without_penalty_trigger = no
				}

				#Base chance
				modifier = {
					add = husband_suspicion_base_value
					always = yes
				}
				#Increased chance of suspicion if it actually is a bastard
				modifier = {
					add = 50
					scope:real_father != scope:spouse
				}
				#Increase significantly if the mother has a known lover
				modifier = {
					add = 150
					scope:mother = {
						OR = {
							any_secret = { # Trigger for secret relations
								type = secret_lover
								is_known_by = scope:spouse
								trigger_if = {
									limit = {
										exists = secret_target
									}
									secret_target != scope:spouse
								}
							}
							any_relation = { # Trigger for public relations
								type = lover
								this != scope:spouse # No suspicion chance if their lover is us!
								NOT = { has_secret_relation_lover = scope:mother } # Not a secret relation (That's checked in the above step).
							}
						}
					}
				}
				#Increased chance of suspicion if the child is a bastard and the mother is not very smart
				modifier = {
					add = 10
					scope:real_father != scope:spouse
					scope:mother = {
						has_trait_rank = {
							trait = intellect_bad
							rank > 0
						}
					}
				}
				modifier = {
					add = 15
					scope:real_father != scope:spouse
					scope:mother = {
						has_trait_rank = {
							trait = intellect_bad
							rank > 1
						}
					}
				}
				modifier = {
					add = 20
					scope:real_father != scope:spouse
					scope:mother = {
						has_trait_rank = {
							trait = intellect_bad
							rank > 2
						}
					}
				}
				#Negative modifier if the mother is smart
				modifier = {
					add = -5
					scope:mother = {
						has_trait_rank = {
							trait = intellect_good
							rank > 0
						}
					}
				}
				modifier = {
					add = -10
					scope:mother = {
						has_trait_rank = {
							trait = intellect_good
							rank > 1
						}
					}

				}
				modifier = {
					add = -15
					scope:mother = {
						has_trait_rank = {
							trait = intellect_good
							rank > 2
						}
					}
				}
				#Bonuses for high intelligence if it is a bastard
				modifier = {
					add = 30
					scope:real_father != scope:spouse
					has_trait_rank = {
						trait = intellect_good
						rank > 0
					}
				}
				modifier = {
					add = 30
					scope:real_father != scope:spouse
					has_trait_rank = {
						trait = intellect_good
						rank > 1
					}
				}
				modifier = {
					add = 30
					scope:real_father != scope:spouse
					has_trait_rank = {
						trait = intellect_good
						rank > 2
					}
				}
				#Negative modifiers for high intelligence if it is NOT a bastard
				modifier = {
					add = -30
					scope:real_father = scope:spouse
					has_trait_rank = {
						trait = intellect_good
						rank > 0
					}
				}
				modifier = {
					add = -30
					scope:real_father = scope:spouse
					has_trait_rank = {
						trait = intellect_good
						rank > 1
					}
				}
				modifier = {
					add = -30
					scope:real_father = scope:spouse
					has_trait_rank = {
						trait = intellect_good
						rank > 2
					}
				}
				#Increased chance if father is paranoid
				modifier = {
					add = 50
					has_trait = paranoid
				}
				#Very high chance if father is Celibate and not stupid
				modifier = {
					add = 1500
					has_trait = celibate
					NOT = {
						has_trait_rank = {
							trait = intellect_bad
							rank > 2
						}
					}
				}
				modifier = {
					scope:mother = { has_variable = borte_first_child_var } # You already know about this
					factor = 0
				}
				trigger_event = adultery.1001
			}
			100 = { #No suspicion. Regular notification message is good enough for this if it's not the first child
				trigger = {
					accepts_adultery_without_penalty_trigger = no
				}

				#Base chance
				modifier = {
					add = {
						value = 0
							subtract = husband_suspicion_base_value
					}
					always = yes
				}

				if = {
					limit = {
						OR = {
							any_child = { count < 1 }
							AND = {
								NOT = { any_child = { dynasty = scope:spouse.dynasty } }
								scope:spouse = { matrilinear_marriage = no }
							}
						}
					}
					trigger_event = pregnancy.1002
				}
				else = {
					send_interface_toast = {
						type = msg_known_pregnancy
						left_icon = scope:mother
						title = pregnancy_not_first_child_message_title
						desc = pregnancy_not_first_child_message
						show_as_tooltip = {
							scope:mother = { add_trait_force_tooltip = pregnant }
						}
					}
				}
			}
		}
	}
}


bastard_real_father_suspicion_chance_effect = {
	hidden_effect = { #Root will here refer to the mother with a pregnancy
		save_scope_as = mother

		#Build a list of potential fathers
		every_in_list = {
			variable = potential_father_variable_list
			limit = {
				NOT = {	is_consort_of = scope:mother }	
			}
			add_to_list = potential_fathers
		}
		clear_variable_list = potential_father_variable_list #Remove list when unnecessary
		every_relation = {
			type = lover
			limit = {
				NOR = {
					root = { is_consort_of = prev }
					is_in_list = potential_fathers
				}
			}
			add_to_list = potential_fathers
		}
		if = {
			limit = {
				scope:real_father = {
					NOR = {
						root = { is_consort_of = prev }
						is_in_list = potential_fathers
					}
				}
			}
			scope:real_father = {
				add_to_list = potential_fathers
			}
		}

		every_in_list = {
			list = potential_fathers
			random = { #Real father has a random chance of suspecting that they are
				chance = real_father_suspicion_base_value
				modifier = {
					add = 10
					has_trait = shrewd
				}
				modifier = {
					add = 10
					has_trait = intellect_good_1
				}
				modifier = {
					add = 20
					has_trait = intellect_good_2
				}
				modifier = {
					add = 30
					has_trait = intellect_good_3
				}
				modifier = {
					add = -30
					has_trait = dull
				}
				modifier = {
					add = -10
					has_trait = intellect_bad_1
				}
				modifier = {
					add = -20
					has_trait = intellect_bad_2
				}
				modifier = {
					add = -10
					has_trait = intellect_bad_3
				}
				modifier = {
					add = 35
					is_married = no
					is_concubine = no
				}
				modifier = {
					add = {
						value = intrigue
					}
				}
				#Very low chance if the potential_father is in fact, a woman and not stupid
				modifier = {
					add = -1500
					is_female = yes
					NOT = {
						has_trait_rank = {
							trait = intellect_bad
							rank > 2
						}
					}
				}
				if = {
					limit = {
						scope:mother = {
							exists = var:event_triggered
						}
					}
					trigger_event = {
						id = pregnancy.3001
						days = { 5 20 }
					}
				}
				
				if = {
					limit = {
						NOT = {
							scope:mother = {
								exists = var:event_triggered
							}
						}
					}
					scope:mother = {
						set_variable = {
							name = event_triggered 
							value = yes
							days = 365
						}
					}
				}
			}
		}
	}
}

bastard_pregnancy_mother_announcement_effect = {
	hidden_effect = {
		if = {
			limit = {
				NOT = { has_trait = pregnant }
			}
			add_trait_force_tooltip = pregnant
		}
	}
	# Could build an event target list instead, and use it to fire a first_valid on_action where all the events have triggers inside them so that only one event will fire for any given character

	scope:mother = {
		set_known_bastard_on_pregnancy = yes
		add_character_flag = {
			flag = pregnancy_real_father_of_bastard_is_known_flag
			months = 9
		}
		trigger_event = {
			id = pregnancy.6001
			days = 3
		}
	}
	scope:real_father = {
		trigger_event = {
			id = pregnancy.6002
			days = 3
		}
	}
	if = {
		limit = {
			scope:mother = { is_married = yes }
		}
		scope:mother = {
			every_spouse = {
				if = {
					limit = { accepts_adultery_without_penalty_trigger = yes }
					trigger_event = {
						id = pregnancy.6999
						days = 3
					}
				}
				else = {
					trigger_event = {
						id = pregnancy.6003
						days = 3
					}
				}
			}
		}
	
	}


	scope:mother = {
		every_parent = {
			limit = {
				is_ai = no # No need to send pure notifications to AI
				NOR = {
					this = scope:mother
					this = scope:real_father
				}
				trigger_if = {
					limit = { exists = scope:father }
					this != scope:father
				}
				accepts_adultery_without_penalty_trigger = no
			}
			add_to_list = mother_family_list
			trigger_event = {
				id = pregnancy.6004
				days = 3
			}
		}
		every_child = {
			limit = {
				is_ai = no # No need to send pure notifications to AI
				NOR = {
					this = scope:mother
					this = scope:real_father
				}
				trigger_if = {
					limit = {
						exists = scope:father
					}
					this != scope:father
				}
				accepts_adultery_without_penalty_trigger = no
			}
			add_to_list = mother_family_list
			trigger_event = {
				id = pregnancy.6004
				days = 3
			}
		}
		every_sibling = {
			limit = {
				is_ai = no # No need to send pure notifications to AI
				NOR = {
					this = scope:mother
					this = scope:real_father
				}
				trigger_if = {
					limit = {
						exists = scope:father
					}
					this != scope:father
				}
				accepts_adultery_without_penalty_trigger = no
			}
			add_to_list = mother_family_list
			trigger_event = {
				id = pregnancy.6004
				days = 3
			}
		}
	}
	scope:real_father = {
		if = {
			limit = { exists = primary_partner }
			primary_partner = {
				if = {
					limit = {
						NOT = { is_in_list = mother_family_list } #To guard against incest triggering multiple events
						is_ai = no # No need to send pure notifications to AI
						NOR = {
							this = scope:mother
							this = scope:real_father
						}
						trigger_if = {
							limit = {
								exists = scope:father
							}
							this != scope:father
						}
						accepts_adultery_without_penalty_trigger = no
					}
					trigger_event = {
						id = pregnancy.6005
						days = 3
					}
				}
			}
		}
		every_parent = {
			limit = {
				NOT = { is_in_list = mother_family_list } #To guard against incest triggering multiple events
				is_ai = no # No need to send pure notifications to AI
				NOR = {
					this = scope:mother
					this = scope:real_father
				}
				trigger_if = {
					limit = {
						exists = scope:father
					}
					this != scope:father
				}
				accepts_adultery_without_penalty_trigger = no
			}
			trigger_event = {
				id = pregnancy.6006
				days = 3
			}
		}
		every_child = {
			limit = {
				NOT = { is_in_list = mother_family_list } #To guard against incest triggering multiple events
				NOR = {
					this = scope:mother
					this = scope:real_father
				}
				trigger_if = {
					limit = {
						exists = scope:father
					}
					this != scope:father
				}
				accepts_adultery_without_penalty_trigger = no
			}
			trigger_event = {
				id = pregnancy.6006
				days = 3
			}
		}
		every_sibling = {
			limit = {
				NOT = { is_in_list = mother_family_list } #To guard against incest triggering multiple events
				NOR = {
					this = scope:mother
					this = scope:real_father
				}
				trigger_if = {
					limit = {
						exists = scope:father
					}
					this != scope:father
				}
				accepts_adultery_without_penalty_trigger = no
			}
			trigger_event = {
				id = pregnancy.6006
				days = 3
			}
		}
	}
}


bastard_pregnancy_married_mother_announcement_effect = {
	save_scope_as = secret_exposer
	add_to_temporary_list = notified_of_bastardy
	scope:mother.pregnancy_assumed_father = {
		save_scope_as = father
	}
	scope:mother.pregnancy_real_father = {
		save_scope_as = real_father
	}

	scope:mother = {
		add_character_flag = {
			flag = pregnancy_real_father_of_bastard_is_known_flag
			months = 8
		}
		set_known_bastard_on_pregnancy = yes

		if = {
			limit = {
				NOT = { is_in_list = notified_of_bastardy }
			}
			trigger_event = {
				id = secret_bastard.0010
				days = 1
			}
			add_to_temporary_list = notified_of_bastardy
		}
	}
	scope:father = {
		if = {
			limit = {
				NOT = { is_in_list = notified_of_bastardy }
			}
			trigger_event = {
				id = secret_bastard.0011
				days = 1
			}
			add_to_temporary_list = notified_of_bastardy
		}
	}
	scope:real_father = {
		if = {
			limit = {
				NOT = { is_in_list = notified_of_bastardy }
			}
			trigger_event = {
				id = secret_bastard.0013
				days = 1
			}
			add_to_temporary_list = notified_of_bastardy
		}
		add_to_temporary_list = notified_of_bastardy

		if = {
			limit = {
				exists = primary_partner
			}
			primary_partner = {
				if = {
					limit = {
						NOT = { is_in_list = notified_of_bastardy }
					}
					trigger_event = {
						id = secret_bastard.0014
						days = 1
					}
					add_to_temporary_list = notified_of_bastardy
				}
			}
		}
	}
	scope:mother = {
		every_close_or_extended_family_member = {
			limit = {
				NOT = { is_in_list = notified_of_bastardy }
				
			}
			add_to_temporary_list = to_be_notified_of_bastardy
		}
		if = {
			limit = {
				is_playable_character = yes
				liege ?= { NOT = { is_in_list = notified_of_bastardy } }
			}
			liege = {
				add_to_temporary_list = to_be_notified_of_bastardy
			}
		}
	}
	scope:real_father = {
		every_close_family_member = {
			limit = {
				NOT = { is_in_list = notified_of_bastardy }
				
			}
			add_to_temporary_list = to_be_notified_of_bastardy
		}
	}
	scope:father = {
		every_close_family_member = {
			limit = {
				NOT = { is_in_list = notified_of_bastardy }
				
			}
			add_to_temporary_list = to_be_notified_of_bastardy
		}
	}

	every_in_list = {
		list = to_be_notified_of_bastardy
		limit = {
			NOT = { is_in_list = notified_of_bastardy }
		}
		trigger_event = {
			id = secret_bastard.0012
			days = 1
		}

		add_to_temporary_list = notified_of_bastardy
	}
}

bastard_pregnancy_unmarried_mother_announcement_effect = {

	save_scope_as = secret_exposer

	scope:mother.pregnancy_real_father = {
		save_scope_as = real_father
	}

	scope:mother = {
		set_known_bastard_on_pregnancy = yes
		add_character_flag = {
			flag = pregnancy_real_father_of_bastard_is_known_flag
			months = 9
		}

		trigger_event = {
			id = secret_bastard.1000
			days = 1
		}
		add_to_temporary_list = notified_of_bastardy
	}
	scope:real_father = {
		trigger_event = {
			id = secret_bastard.1003
			days = 1
		}
		add_to_temporary_list = notified_of_bastardy

		if = {
			limit = {
				is_married = yes
			}
			primary_spouse = {
				trigger_event = {
					id = secret_bastard.1004
					days = 1
				}
				add_to_temporary_list = notified_of_bastardy
			}
		}
	}
	scope:mother = {
		every_parent = {
			limit = {
				NOT = { is_in_list = notified_of_bastardy }
				
			}
			trigger_event = {
				id = secret_bastard.1001
				days = 1
			}
			add_to_temporary_list = notified_of_bastardy
		}
		every_close_or_extended_family_member = {
			limit = {
				NOT = { is_in_list = notified_of_bastardy }

			}
			add_to_temporary_list = to_be_notified_of_bastardy
		}
		if = {
			limit = {
				is_playable_character = yes
				liege ?= { NOT = { is_in_list = notified_of_bastardy } }
			}
			liege = {
				add_to_temporary_list = to_be_notified_of_bastardy
			}
		}
	}
	scope:real_father = {
		every_close_or_extended_family_member = {
			limit = {
				NOT = { is_in_list = notified_of_bastardy }
				
			}
			add_to_temporary_list = to_be_notified_of_bastardy
		}
	}

	every_in_list = {
		list = to_be_notified_of_bastardy
		limit = {
			NOT = { is_in_list = notified_of_bastardy }
		}
		trigger_event = {
			id = secret_bastard.1002
			days = 1
		}
		add_to_temporary_list = notified_of_bastardy
	}
}


#Selects the correct bastard pregnancy announcement to fire
bastardy_pregnancy_announcement_effect = {
	custom_tooltip = bastardy_pregnancy_announcement_tooltip
	if = {
		limit = {
			this = scope:mother
		}
		bastard_pregnancy_mother_announcement_effect = yes
	}
	else_if = {
		limit = {
			exists = scope:mother.pregnancy_assumed_father
		}
		bastard_pregnancy_married_mother_announcement_effect = yes
	}
	else = {
		bastard_pregnancy_unmarried_mother_announcement_effect = yes
	}
	if = {
		limit = {
			is_ai = no
		}
		add_character_flag = {
			flag = tutorial_reactive_advice_bastards
		}
	}
}



#Effect run in the legitimize bastard interactions
legitimize_bastard_interaction_opinions_effect = {
	hidden_effect = {
		$LEGITIMIZER$ = {
			save_scope_as = actor
		}
		if = {
			limit = {
				exists = $HOUSE_HEAD$
			}
			$HOUSE_HEAD$ = {
				save_scope_as = house_head
			}
		}

		if = {
			limit = {
				scope:actor = {
					is_parent_of = $BASTARD$
				}
			}
			scope:actor = {
				save_scope_as = parent
			}
		}
		else = {
			$BASTARD$ = {
				random_parent = {
					limit = {
						house = scope:actor.house
						is_playable_character = yes
					}
					alternative_limit = {
						house = scope:actor.house	
					}
					alternative_limit = {
						always = yes
					}
					weight = {
						base = 1
						compare_modifier = {
							value = highest_held_title_tier
							multiplier = 1000
						}
					}
					save_scope_as = parent
				}
			}
		}
	}
	# Reveal secret if you are the father
	if = {
		limit = {
			any_secret = {
				type = secret_unmarried_illegitimate_child
				secret_target = {
					real_father = {
						this = scope:actor
					}
				}
			}
		}
		random_secret = {
			type = secret_unmarried_illegitimate_child
			limit = {
				secret_target = {
					real_father = {
						this = root
					}
				}
			}
			expose_secret = scope:actor
		}
	}

	$BASTARD$ = {
		hidden_effect = { remove_trait = bastard }
		add_trait_force_tooltip = legitimized_bastard
		add_opinion = {
			target = scope:actor
			modifier = legitimized_me_opinion
		}
		scope:actor = {
			if = {
				limit = {
					is_parent_of = $BASTARD$
				}
				$BASTARD$ = {
					random_parent = {
						limit = { this != scope:actor }
						add_opinion = {
							target = scope:actor
							modifier = legitimized_my_child_opinion
						}
					}
				}
				every_spouse = {
					limit = {
						NOT = { is_parent_of = $BASTARD$ }
					}
					add_opinion = {
						target = scope:actor
						modifier = legitimized_a_bastard_opinion
					}
				}
				if = {
					limit = {
						any_child = {
							is_adult = yes
							NOT = { this = $BASTARD$ }
							NOR = {
								has_trait = bastard
								has_trait = legitimized_bastard
								opinion = {
									value >= 40
									target = $BASTARD$
								}
							}
						}
					}
					every_child = {
						limit = {
							is_adult = yes
							NOT = { this = $BASTARD$ }
							NOR = {
								has_trait = bastard
								has_trait = legitimized_bastard
								opinion = {
									value >= 40
									target = $BASTARD$
								}
							}
						}
						custom =  every_child_adult_non_bastard_dislike
						add_opinion = {
							target = scope:actor
							modifier = legitimized_a_bastard_opinion
						}
					}
				}
			}
		}
	}

	hidden_effect = {
		$BASTARD$ = {
			trigger_event = bastard_interaction.0001
			
			save_scope_as = legitimized_bastard

			if = {
				limit = {
					NOT = { exists = scope:newborn_legitimization }
				}
				every_parent = {
					limit = { this != scope:actor }
					trigger_event = bastard_interaction.0003
				}
			}
		}

		scope:actor = {
			if = {
				limit = {
					NOT = { exists = scope:newborn_legitimization }
					is_parent_of = $BASTARD$
				}
				trigger_event = bastard_interaction.0002
			}

			if = {
				limit = {
					is_parent_of = $BASTARD$
				}
				every_spouse = {
					limit = {
						NOT = { is_parent_of = $BASTARD$ }
						this != scope:actor
					}
					$BASTARD$ = { save_scope_as = legitimized_bastard }
					trigger_event = bastard_interaction.0004
				}
				every_child = {
					limit = {
						is_adult = yes
						NOT = { this = $BASTARD$ }
						this != scope:actor
					}
					trigger_event = bastard_interaction.0005
				}
			}
			else = {
				scope:parent ?= {
					if = {
						limit = {
							NOT = { exists = scope:newborn_legitimization }
						}
						trigger_event = bastard_interaction.0006
					}
				
					every_spouse = {
						limit = {
							NOT = { is_parent_of = $BASTARD$ }
							this != scope:actor
						}
						trigger_event = bastard_interaction.0007
					}

					every_child = {
						limit = {
							is_adult = yes
							NOT = { this = $BASTARD$ }
							this != scope:actor
						}
						trigger_event = bastard_interaction.0008
					}
				}
			}
		}
	}
}


bastard_real_father_discovery_on_birth_effect = {
	hidden_effect = {
		random_secret = {
			limit = {
				OR = {
					secret_type = secret_unmarried_illegitimate_child
					secret_type = secret_disputed_heritage
				}
				secret_target = scope:child
			}
			save_scope_as = secret
		}

		scope:child.real_father = {
			random = {
				chance = real_father_suspicion_base_value
				compare_modifier = {
					value = intrigue
				}
				modifier = {
					add = 25
					has_trait = intellect_good
				}
				modifier = {
					add = -20
					has_trait = intellect_bad
				}

				trigger_event = {
					id = birth.1006
					days = 5
				}
			}
		}
	}
}



bastard_to_wild_oat_conversion_effect = {
	if = { #If you're a bastard and your new faith says they don't exist! 
		limit = {
			has_trait = bastard
			faith = { has_doctrine_parameter = bastards_none }
			trigger_if = { #If you have a highborn parent, then you have to have their dynasty and their faith has to say no to bastards as well! Otherwise we might mess up too many successions... 
				limit = {
					any_parent = {
						exists = dynasty
					}
				}
				exists = root.dynasty
				any_parent = {
					dynasty = root.dynasty
					faith = { has_doctrine_parameter = bastards_none }
				}
			}
		}
		remove_trait = bastard
		add_trait = wild_oat
	}
}

bastard_to_wild_oat_conversion_interaction_effect = {
	if = { #If you're a bastard and your new faith says they don't exist! 
		limit = {
			has_trait = bastard
			scope:actor.faith = { has_doctrine_parameter = bastards_none }
			trigger_if = { #If you have a highborn parent, then you have to have their dynasty and their faith has to say no to bastards as well! Otherwise we might mess up too many successions... 
				limit = {
					any_parent = {
						exists = dynasty
					}
				}
				exists = scope:recipient.dynasty
				any_parent = {
					dynasty = scope:recipient.dynasty
					faith = { has_doctrine_parameter = bastards_none }
				}
			}
		}
		remove_trait = bastard
		add_trait_force_tooltip = wild_oat
	}
}

bastard_to_wild_oat_conversion_assimilation_effect = {
	if = { #If you're a bastard and your new faith says they don't exist! 
		limit = {
			has_trait = bastard
			scope:new_faith = { has_doctrine_parameter = bastards_none }
			trigger_if = { #If you have a highborn parent, then you have to have their dynasty and their faith has to say no to bastards as well! Otherwise we might mess up too many successions... 
				limit = {
					any_parent = {
						exists = dynasty
					}
				}
				exists = dynasty
				any_parent = {
					dynasty = prev.dynasty
					faith = { has_doctrine_parameter = bastards_none }
				}
			}
		}
		remove_trait = bastard
		add_trait_force_tooltip = wild_oat
	}
}

remove_inherited_descendent_traits_effect = {
	if = {
		limit = {
			has_trait = sayyid
			exists = scope:real_father
			NOT = {
				scope:real_father = { has_trait = sayyid }
			}
		}
		remove_trait = sayyid
	}
	if = {
		limit = {
			has_trait = golden_lineage
			exists = scope:real_father
			NOT = {
				scope:real_father = { has_trait = golden_lineage }
			}
		}
		remove_trait = golden_lineage
	}
}


#Removes all bastard traits
remove_all_bastard_traits = {
	if = {
		limit = {
			has_trait = wild_oat
		}
		remove_trait = wild_oat
	}
	if = {
		limit = {
			has_trait = bastard
		}
		remove_trait = bastard
	}
	if = {
		limit = {
			has_trait = legitimized_bastard
		}
		remove_trait = legitimized_bastard
	}
	if = {
		limit = {
			has_trait = disputed_heritage
		}
		remove_trait = disputed_heritage
	}
}
