﻿DCR_DW_demonic_impregnation = {
	category = interaction_category_friendly
	desc = DCR_DW_demonic_impregnation_desc

	cooldown = { years = 1 }
	cooldown_against_recipient = { years = 3 }

	cost = {
		piety = 500
	}

	is_shown = {
		exists = scope:recipient.host
		scope:actor = {
			highest_held_title_tier >= tier_county
			is_adult = yes
			is_imprisoned = no
			is_incapable = no
			is_landed = yes
			is_ruler = yes
			trigger_if = {
				limit = { is_female = yes }
				this = scope:recipient
				OR = {
					is_witch_trigger = yes # Is a witch
					has_character_flag = demon_child_non_pagan # Is a demon child
				}
			}
			trigger_if = {
				limit = { is_male = yes }
				has_character_flag = demon_child_non_pagan # Is a demon child
			}
			NOT = { has_trait = eunuch }
			NOT = { has_character_flag = DCR_do_not_disturb }
		}
		scope:recipient = { # Recipient is a female who is not pregnant
			OR = {
				top_liege = scope:actor.top_liege # In same realm only
				is_imprisoned_by = scope:actor # Is a prisoner of actor
			}
			age <= 45
			is_adult = yes
			is_female = yes
			NOT = { has_trait = eunuch }
			NOT = { has_character_flag = DCR_do_not_disturb }
		}
	}

	is_valid_showing_failures_only = {
		scope:recipient = {
			is_pregnant = no
			faith = scope:actor.faith
		}
	}

	on_accept = {
		scope:actor = {
			add_character_flag = {
				flag = DCR_do_not_disturb
				days = 2
			}
		}
		scope:recipient = {
			add_character_flag = {
				flag = DCR_do_not_disturb
				days = 2
			}
			if = { # Try to find a existing demon child in same realm
				limit = {
					#is_ai = no
					is_female = yes
					this = scope:actor
					any_realm_county = {
						holder = {
							faith = scope:actor.faith
							is_male = yes
							is_adult = yes
							is_imprisoned = no
							is_incapable = no
							has_character_flag = demon_child_non_pagan
							NOT = { this = scope:actor }
						}
					}
				}
				every_realm_county = {
					holder = {
						if = {
							limit = {
								faith = scope:actor.faith
								is_male = yes
								is_adult = yes
								is_imprisoned = no
								is_incapable = no
								has_character_flag = demon_child_non_pagan
								NOT = { this = scope:actor }
							}
							add_to_list = DCR_demon_child_list
						}
					}
				}
				random_in_list = {
					list = DCR_demon_child_list
					save_scope_as = DCR_demon_child
				}
				scope:DCR_demon_child = {
					trigger_event = DCR.0001
				}
			}
			else = {
				trigger_event = DCR.0002
				if = {
					limit = { NOT = { this = scope:actor } }
					scope:actor = {
						trigger_event = DCR.0003
					}
				}
			}
		}
	}

	ai_targets = {
		#ai_recipients = sub_realm_characters
		ai_recipients = courtiers
		ai_recipients = prisoners
		ai_recipients = vassals
		chance = 0.25
	}
	ai_targets = {
		ai_recipients = self
		chance = 1
	}
	ai_target_quick_trigger = {
		adult = yes
	}

	ai_frequency = 60

	ai_will_do = {
		base = 0.1
		modifier = {
			factor = 0
			scope:recipient = {
				any_child = {
					count >= 3
					is_alive = yes
				}
			}
		}
	}

	auto_accept = yes
}
