namespace = bp2_decision

##################################################
#
#	FIND WET NURSE
# 0001	Find a character to be a wet nurse
#
##################################################

bp2_decision.0001 = { #find wet nurse candidates
	type = character_event
	content_source = dlc_009
	title = bp2_decision.0001.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { exists = root.primary_spouse }
				desc = bp2_decision.0001.desc
			}
			desc = bp2_decision.0001.desc_widower
		}
	}
	theme = family
	override_background = {
		reference = bp2_nursery
	}
	left_portrait = {
		character = scope:wet_nurse_candidate_1
	}
	right_portrait = {
		character = scope:wet_nurse_candidate_2
	}

	immediate = {
		if = {
			limit = {
				any_spouse = { }
			}
			random_spouse = {
				save_scope_as = spouse
			}
		}
		hidden_effect = {
			if = {
				limit = {
					exists = capital_province
					any_pool_character = {
						province = root.capital_province
						can_be_employed_as = wet_nurse_court_position
					}
				}
				random_pool_character = {
					province = root.capital_province
					limit = { can_be_employed_as = wet_nurse_court_position}
					save_scope_as = wet_nurse_candidate_1
				}
				if = {
					limit = {
						exists = capital_province
						any_pool_character = {
							province = root.capital_province
							can_be_employed_as = wet_nurse_court_position
							this != scope:wet_nurse_candidate_1
						}
					}
					save_scope_as = wet_nurse_candidate_2
				}
				else = {
					create_character = { #create poor candidate without a child
						template = generic_peasant_character
						gender = female
						age = { 18 25 }
						culture = root.culture
						faith = root.faith
						location = root.location
						save_scope_as = wet_nurse_candidate_2
					}
				}
			}
			else = {
				create_character = { #create a good candidate with a child
					template = bp2_wet_nurse_template
					location = root.location
					save_scope_as = wet_nurse_candidate_1
				}
				create_character = {
					template = peasant_child_character
					age = { 0 5 }
					culture = root.culture
					faith = root.faith
					location = root.location
					save_scope_as = wet_nurse_candidate_1_child
				}
				scope:wet_nurse_candidate_1_child = {
					set_mother = scope:wet_nurse_candidate_1
				}
				create_character = { #create poor candidate without a child
					template = generic_peasant_character
					gender = female
					age = { 18 25 }
					culture = root.culture
					faith = root.faith
					location = root.location
					save_scope_as = wet_nurse_candidate_2
				}
			}
		}
	}

	# Expensive wet nurse with great health and a chance for good trait
	option = {
		name = bp2_decision.0001.a
		custom_tooltip = bp2_decision.0001.a.aptitude
		pay_treasury_or_gold = {
			target = scope:wet_nurse_candidate_1
			value = tiny_treasury_or_gold_value
		}
		hidden_effect = {
			add_courtier = scope:wet_nurse_candidate_1
			add_courtier = scope:wet_nurse_candidate_1_child
		}
		if = { #reappoint the former wet nurse, fire current one if exists
			limit = {
				employs_court_position = wet_nurse_court_position
			}
			every_court_position_holder = {
				type = wet_nurse_court_position
				save_temporary_scope_as = current_wet_nurse
			}
			replace_court_position = {
				recipient = scope:wet_nurse_candidate_1
				holder = scope:current_wet_nurse
				court_position = wet_nurse_court_position
			}
		}
		else = {
			appoint_court_position = {
				recipient = scope:wet_nurse_candidate_1
				court_position = wet_nurse_court_position
			}
		}
		stress_impact = {
			greedy = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = greedy
				add = -100
			}
			modifier = {
				short_term_gold < minor_gold_value
				factor = 0
			}
		}
	}
	
	# Cheaper wet nurse; all random traits
	option = {
		name = bp2_decision.0001.b
		custom_tooltip = bp2_decision.0001.b.aptitude
		pay_treasury_or_gold = {
			target = scope:wet_nurse_candidate_2
			value = {
				add = tiny_treasury_or_gold_value
				divide = 3
			}
		}
		hidden_effect = {
			add_courtier = scope:wet_nurse_candidate_2
		}
		if = { #reappoint the former wet nurse, fire current one if exists
			limit = {
				employs_court_position = wet_nurse_court_position
			}
			every_court_position_holder = {
				type = wet_nurse_court_position
				save_temporary_scope_as = current_wet_nurse
			}
			replace_court_position = {
				recipient = scope:wet_nurse_candidate_2
				holder = scope:current_wet_nurse
				court_position = wet_nurse_court_position
			}
		}
		else = {
			appoint_court_position = {
				recipient = scope:wet_nurse_candidate_2
				court_position = wet_nurse_court_position
			}
		}
		stress_impact = {
			greedy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50
			modifier = {
				short_term_gold < tiny_gold_value_check
				factor = 0
			}
		}
	}
	
	# On seconds thoughts, I won't hire a wet nurse at all...
	option = {
		name = bp2_decision.0001.c
		ai_chance = {
			base = 0
			modifier = {
				short_term_gold < tiny_gold_value_check
				add = 10
			}
		}
	}

	after = {
		if = {
			limit = { scope:wet_nurse_candidate_1 = { has_court_position = wet_nurse_court_position } }
			scope:wet_nurse_candidate_2 = {
				silent_disappearance_effect = yes
			}
		}
		else_if = {
			limit = { scope:wet_nurse_candidate_2 = { has_court_position = wet_nurse_court_position } }
			scope:wet_nurse_candidate_1 = {
				silent_disappearance_effect = yes
			}
			scope:wet_nurse_candidate_1_child = {
				silent_disappearance_effect = yes
			}
		}
		else = {
			scope:wet_nurse_candidate_1 = {
				silent_disappearance_effect = yes
			}
			scope:wet_nurse_candidate_2 = {
				silent_disappearance_effect = yes
			}
			scope:wet_nurse_candidate_1_child = {
				silent_disappearance_effect = yes
			}
		}
	}
}

bp2_decision.0002 = { #rites of passage
	type = character_event
	content_source = dlc_009
	title = bp2_decision.0002.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:teentribal != root }
				desc = bp2_decision.0002.desc
			}
			desc = bp2_decision.0002.desc_root
		}
		triggered_desc = {
			trigger = {
				scope:teentribal = {
					is_target_in_variable_list = {
						name = possible_rites
						target = flag:duel
					}
				}
			}
			desc = bp2_decision.0002.desc_duel
		}
		triggered_desc = {
			trigger = {
				scope:teentribal = {
					is_target_in_variable_list = {
						name = possible_rites
						target = flag:scarification
					}
				}
			}
			desc = bp2_decision.0002.desc_scarification
		}
		triggered_desc = {
			trigger = {
				scope:teentribal = {
					is_target_in_variable_list = {
						name = possible_rites
						target = flag:seclusion
					}
				}
			}
			desc = bp2_decision.0002.desc_seclusion
		}
		triggered_desc = {
			trigger = {
				scope:teentribal = {
					is_target_in_variable_list = {
						name = possible_rites
						target = flag:hair_shaving
					}
				}
			}
			desc = bp2_decision.0002.desc_hair_shaving
		}
		triggered_desc = {
			trigger = {
				scope:teentribal = {
					is_target_in_variable_list = {
						name = possible_rites
						target = flag:cleansing
					}
				}
			}
			desc = bp2_decision.0002.desc_cleansing
		}
		first_valid = {
			triggered_desc = {
				trigger = { scope:teentribal != root }
				desc = bp2_decision.0002.desc_end
			}
			desc = bp2_decision.0002.desc_end_root
		}
	}
	theme = family
	override_background = {
		reference = holy_site_generic_scope
	}

	left_portrait = {
		character = root
		animation = war_defender
	}
	right_portrait = {
		trigger = { scope:teentribal != root } 
		character = scope:teentribal
		animation = throne_room_bow_1
	}
	lower_right_portrait = {
		trigger = { exists = scope:priest }
		character = scope:priest
	}

	immediate = {
		capital_province = {
			save_scope_as = holy_site_scope
		}
		location = {
			save_scope_as = rite_location
		}
		if = {
			limit = {
				is_landed = yes
				character_can_rites_of_passage_trigger = yes
			}
			save_scope_as = teentribal
		}
		else_if = {
			limit = {
				any_child = {
					character_can_rites_of_passage_trigger = yes
				}
			}
			save_scope_as = liege
			random_child = {
				limit = {	
					character_can_rites_of_passage_trigger = yes
				}
				weight = {
					base = 1
					modifier = {
						has_character_flag = unproven_adult_flag
						add = 100
					}
					modifier = {
						is_primary_heir_of = scope:liege
						add = 100
					}
					modifier = {
						can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root }
						add = 10
					}
				}
				save_scope_as = teentribal
			}
		}
		else_if = {
			limit = {
				any_courtier = {
					is_hostage_of = root
					character_can_rites_of_passage_trigger = yes
				}
			}
			save_scope_as = liege
			random_courtier = {
				limit = {
					is_hostage_of = root
					character_can_rites_of_passage_trigger = yes
				}
				weight = {
					base = 1
					modifier = {
						has_character_flag = unproven_adult_flag
						add = 100
					}
					modifier = {
						can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root }
						add = 10
					}
				}
				save_scope_as = teentribal
			}
		}
		if = { #grab a court chaplain if you have one
			limit = {
				cp:councillor_court_chaplain ?= {
					is_available_ai_adult = yes
				}
			}
			cp:councillor_court_chaplain = {
				save_scope_as = priest
			}
		}
		if = { #duel rite for warrior cultures
			limit = {
				culture = {
					OR = {
						has_cultural_pillar = ethos_bellicose
						has_cultural_pillar = ethos_stoic
					}
				}
			}
			scope:teentribal = {
				add_to_variable_list = {
					name = possible_rites
					target = flag:duel
				}
			}
		}
		if = { #scarification rite for warrior cultures
			limit = {
				culture = {
					OR = {
						has_cultural_pillar = ethos_bellicose
						has_cultural_pillar = ethos_stoic
						has_cultural_pillar = ethos_communal
					}
				}
			}
			scope:teentribal = {
				add_to_variable_list = {
					name = possible_rites
					target = flag:scarification
				}
			}
		}
		if = { #seclusion rite for non-communal cultures
			limit = {
				culture = {
					NOT = {
						has_cultural_pillar = ethos_communal
					}
				}
			}
			scope:teentribal = {
				add_to_variable_list = {
					name = possible_rites
					target = flag:seclusion
				}
			}
		}
		if = { #hair shaving rite non-warrior cultures
			limit = {
				culture = {
					OR = {
						has_cultural_pillar = ethos_spiritual
						has_cultural_pillar = ethos_communal
						has_cultural_pillar = ethos_egalitarian
						has_cultural_pillar = ethos_bureaucratic
					}
				}
			}
			scope:teentribal = {
				add_to_variable_list = {
					name = possible_rites
					target = flag:hair_shaving
				}
			}
		}
		if = { #cleansing for non-warrior cultures
			limit = {
				culture = {
					NOT = {
						has_cultural_pillar = ethos_bellicose
						has_cultural_pillar = ethos_stoic
					}
				}
			}
			scope:teentribal = { 
				add_to_variable_list = {
					name = possible_rites
					target = flag:cleansing
				}
				if = {
					limit = {
						scope:rite_location = {
							OR = {
								is_riverside_province = yes
								is_coastal = yes
							}
						}
					}
					set_variable = {
						name = cleansing_type
						value = flag:water_cleanse
					}		
				}
				else = { 
					set_variable = {
						name = cleansing_type
						value = flag:fire_cleanse
					}
				}
			}
		}
	}

	option = { #combat duel
		name = bp2_decision.0002.a
		flavor = bp2_decision.0002.a.flavor
		custom_tooltip = bp2_decision.0002.a.tt
		trigger = {
			scope:teentribal = {
				is_target_in_variable_list = {
					name = possible_rites
					target = flag:duel
				}
			}
		}
		show_as_tooltip = {
			random_list = {
				1 = {
					desc = bp2_decision.0002.a.win
					show_chance = no
					scope:teentribal = {
						add_character_modifier = {
							modifier = proven_adult_modifier
							years = 10
						}
						custom_tooltip = bp2_decision.0002.effect_tt
					}
				}
				1= {
					desc = bp2_decision.0002.a.lose
					show_chance = no
					scope:teentribal = {
						add_character_modifier = {
							modifier = insecure_adult_modifier
							years = 10
						}
						custom_tooltip = bp2_decision.0002.effect_tt
					}
				}
			}
		}
		scope:teentribal = { #set variable to determine which rite was completed when creating a memory
			set_variable = {
				name = chosen_rite_memory
				value = flag:dueling_rite_memory
			}
		}
		trigger_event = bp2_yearly.7021
		ai_chance = {
			base = 1
		}
	}

	option = { #scarification
		name = bp2_decision.0002.b
		flavor = bp2_decision.0002.b.tt
		trigger = {
			scope:teentribal = {
				is_target_in_variable_list = {
					name = possible_rites
					target = flag:scarification
				}
			}
		}
		show_as_tooltip = {
			random_list = {
				1 = {
					desc = bp2_decision.0002.b_scarred
					show_chance = no
					scope:teentribal = {
						add_character_modifier = {
							modifier = proven_adult_modifier
							years = 10
						}
						custom_tooltip = bp2_decision.0002.effect_tt
						custom_tooltip = bp2_decision.0002.b_scarred.tt
					}
				}
				1= {
					desc = bp2_decision.0002.b_modifier
					show_chance = no
					scope:teentribal = {
						add_character_modifier = {
							modifier = insecure_adult_modifier
							years = 10
						}
						custom_tooltip = bp2_decision.0002.effect_tt
					}
				}
			}
		}
		scope:teentribal = { #set variable to determine which rite was completed when creating a memory
			set_variable = {
				name = chosen_rite_memory
				value = flag:scarification_rite_memory
			}
		}
		trigger_event = bp2_yearly.7023
		ai_chance = {
			base = 1
		}
	}

	option = { #seclusion
		name = bp2_decision.0002.c
		flavor = bp2_decision.0002.c.tt
		trigger = {
			scope:teentribal = {
				is_target_in_variable_list = {
					name = possible_rites
					target = flag:seclusion
				}
			}
		}
		show_as_tooltip = {
			custom_tooltip = bp2_decision.0002.c.destination
			random_list = {
				1 = {
					desc = bp2_decision.0002.c_win
					show_chance = no
					scope:teentribal = {
						add_character_modifier = {
							modifier = proven_adult_modifier
							years = 10
						}
						custom_tooltip = bp2_decision.0002.c_trait
					}
				}
				1= {
					desc = bp2_decision.0002.c_lose
					show_chance = no
					scope:teentribal = {
						add_character_modifier = {
							modifier = insecure_adult_modifier
							years = 10
						}
						add_trait_xp = {
							trait = lifestyle_traveler
							track = danger
							value = 25
						}
						increase_wounds_no_death_effect = { REASON = wild_animal }
					}
				}
			}
		}
		scope:teentribal = { #set variable to determine which rite was completed when creating a memory
			set_variable = {
				name = chosen_rite_memory
				value = flag:seclusion_rite_memory
			}
		}
		trigger_event = bp2_yearly.7024
		ai_chance = {
			base = 1
		}
	}

	option = { #hair shave
		trigger = {
			scope:teentribal = {
				is_target_in_variable_list = {
					name = possible_rites
					target = flag:hair_shaving
				}
			}
		}
		name = bp2_decision.0002.d
		flavor = bp2_decision.0002.d.tt
		show_as_tooltip = {
			random_list = {
				1 = {
					show_chance = no
					desc = bp2_decision.0002.d_bald
					scope:teentribal = {
						add_character_modifier = {
							modifier = proven_adult_modifier
							years = 10
						}
						add_character_modifier = {
							modifier = shaven_bald_modifier
							years = 3
						}
						custom_tooltip = bp2_decision.0002.effect_tt
						add_piety = medium_piety_gain
					}
				}
				1 = {
					show_chance = no
					desc = bp2_decision.0002.d_shave				
					scope:teentribal = {
						add_character_modifier = {
							modifier = insecure_adult_modifier
							years = 10
						}
						custom_tooltip = bp2_decision.0002.effect_tt
						custom_tooltip = bp2_decision.0002.d_artifact
					}
				}
			}
		}
		scope:teentribal = { #set variable to determine which rite was completed when creating a memory
			set_variable = {
				name = chosen_rite_memory
				value = flag:shaving_hair_rite_memory
			}
		}
		trigger_event = bp2_yearly.7026
		ai_chance = {
			base = 1
		}
	}

	option = { #fire/water cleansing
		trigger = {
			scope:teentribal = {
				is_target_in_variable_list = {
					name = possible_rites
					target = flag:cleansing
				}
			}
		}
		name = bp2_decision.0002.e
		flavor = bp2_decision.0002.e.tt
		show_as_tooltip = {
			random_list = {
				1 = {
					show_chance = no
					desc = bp2_decision.0002.e.full
					scope:teentribal = {
						add_character_modifier = {
							modifier = proven_adult_modifier
							years = 10
						}
						if = {
							limit = {
								num_sinful_traits > 0
							}
							custom_tooltip = bp2_decision.0002.e_flip
						}
						custom_tooltip = bp2_decision.0002.effect_tt
						add_piety = medium_piety_gain
						if = {
							limit = {
								scope:teentribal.var:cleansing_type = flag:water_cleanse
							}
							add_stress = minor_stress_gain
						}
						else = {
							add_character_modifier = {
								modifier = scorched_soles_modifier
								years = 5
							}
						}
					}
				}
				1 = {
					show_chance = no
					desc = bp2_decision.0002.e.partially
					scope:teentribal = {
						add_character_modifier = {
							modifier = insecure_adult_modifier
							years = 10
						}
						custom_tooltip = bp2_decision.0002.effect_tt
					}
				}
			}
		}
		if = {
			limit = {
				scope:teentribal.var:cleansing_type = flag:water_cleanse
			}
			scope:teentribal = { #set variable to determine which rite was completed when creating a memory
				set_variable = {
					name = chosen_rite_memory
					value = flag:water_cleanse_rite_memory
				}
			}
			trigger_event = bp2_yearly.7027
		}
		else_if = {
			limit = {
				scope:teentribal.var:cleansing_type = flag:fire_cleanse
			}
			scope:teentribal = { #set variable to determine which rite was completed when creating a memory
				set_variable = {
					name = chosen_rite_memory
					value = flag:fire_cleanse_rite_memory
				}
			}
			trigger_event = bp2_yearly.7028
		}
		ai_chance = {
			base = 1
		}
	}

	option = { # opt out - trigger the decision cooldown, don't get your money back. Think of it as a non-refundable deposit.
		name = bp2_decision.0002.f
		flavor = bp2_decision.0002.tt
		scope:teentribal ?= {
			remove_variable ?= cleansing_type
			remove_variable ?= chosen_rite_memory
			clear_variable_list ?= possible_rites
		}
		ai_chance = { #there is no reason for the AI to back out at this point
			base = 0
		}
	}
}
