﻿
legitimize_child_of_concubine_interaction = {
	icon = child_of_concubine_legitimized
	category = interaction_category_diplomacy
	desc = legitimize_child_of_concubine_interaction_desc

	is_shown = {
		NOT = { scope:actor = scope:recipient }
		scope:actor.dynasty = scope:recipient.dynasty
		OR = {
			scope:actor = scope:recipient.dynasty.dynast
			scope:actor = scope:recipient.house.house_head
			scope:actor = scope:recipient.father
			scope:actor = scope:recipient.mother
		}
		scope:actor = {
			religion = scope:recipient.religion
			faith = { has_doctrine_parameter = bastards_legitimize }
		}
		scope:recipient = {
			OR = {
				has_trait = child_of_concubine_female
				has_trait = child_of_concubine_male
				has_trait = child_of_concubine_disinherited_female
				has_trait = child_of_concubine_disinherited_male
			}
		}
	}

	is_valid = {}

	auto_accept = yes

	cost = {
		prestige = {
			value = bastard_legitimization_prestige_cost
			divide = 2
		}
	}
	
	on_accept = {
		scope:actor = {
			stress_impact = {
				arrogant = minor_stress_impact_gain
			}
			send_interface_message = {
				type = event_generic_neutral
				title = legitimize_child_of_concubine_interaction_notification
				right_icon = scope:recipient
				show_as_tooltip = {
					scope:recipient = {
						add_opinion = {
							target = scope:actor
							modifier = legitimized_me_opinion
						}
						every_parent = {
							limit = { NOT = { this = scope:actor } }
							add_opinion = {
								target = scope:actor
								modifier = legitimized_my_child_opinion
							}					
						}
					}
				}
			}
		}
		
		hidden_effect = {
			scope:recipient = {
				legitimize_child_of_concubine_effect = yes
				add_opinion = {
					target = scope:actor
					modifier = legitimized_me_opinion
				}
				every_parent = {
					limit = { NOT = { this = scope:actor } }
					add_opinion = {
						target = scope:actor
						modifier = legitimized_my_child_opinion
					}					
					hidden_effect = { #Nudge towards friendship
						if = {
							limit = {
								NOR = {
									has_relation_friend = scope:actor
									has_relation_potential_friend = scope:actor
								}
							}
							set_relation_potential_friend = scope:actor
						}
					}
				}
				every_sibling = {
					limit = { any_parent = { house = scope:recipient.house } }
					if = {
						limit = {
							has_trait = child_of_concubine_female
						}
						remove_trait = child_of_concubine_female
						add_trait = child_of_concubine_disinherited_female
					}
					else_if = {
						limit = {
							has_trait = child_of_concubine_male
						}
						remove_trait = child_of_concubine_male
						add_trait = child_of_concubine_disinherited_male
					}
				}
			}
		}
	}

	ai_targets = {
		ai_recipients = dynasty
	}
	
	ai_frequency = 55

	ai_potential = {
        is_ruler = yes
	}
	
	ai_will_do = {
		base = -100

		modifier = {
			add = 200
			scope:actor = {
				OR = {
					has_relation_best_friend = scope:recipient
					has_relation_friend = scope:recipient
					has_relation_soulmate = scope:recipient
					has_relation_lover = scope:recipient
				}
			}
		}

		modifier = {
			add = 100
			exists = scope:actor.primary_spouse
			scope:actor.primary_spouse = { is_visibly_fertile = no }
			scope:actor = { has_eligible_child_heir_trigger = no }
			scope:recipient = {
				trigger_if = {
					limit = { 
						scope:actor = { culture_or_faith_is_male_dominated_trigger = yes }
					}
					is_female = yes
					OR = {
						is_married = no
						matrilinear_marriage = yes
						matrilinear_betrothal = yes
					}
				}
				trigger_else_if = {
					limit = { 
						scope:actor = { culture_or_faith_is_female_dominated_trigger = yes }
					}
					is_male = yes
					OR = {
						is_married = no
						patrilinear_marriage = yes
						patrilinear_betrothal = yes
					}
				}
				trigger_else = {
					OR = {
						is_married = no
						trigger_if = {
							limit = { is_female = yes }
							OR = {
								matrilinear_marriage = yes
								matrilinear_betrothal = yes
							}
						}
						trigger_if = {
							limit = { is_male = yes }
							OR = {
								patrilinear_marriage = yes
								patrilinear_betrothal = yes
							}
						}
					}
				}
			}
		}

		opinion_modifier = { # Opinion of child
			who = scope:actor
			opinion_target = scope:recipient
			desc = AI_OPINION_REASON
		}

	}
}
