﻿pool_character_development_effect = {
	###POSIBLE EFFECTS###
	# Increase a low skill
	# Get married
	# Get a scripted relation
	# Get a lifestyle trait
	# Get a commander trait
	# Get an interesting trait
	# Get a secret
	# Kill someone
	# Learn a language

	save_temporary_scope_as = pool_character


	random_list = {
		# INCREASE A LOW SKILL
		100 = {
			trigger = { diplomacy < medium_skill_rating }
			add_diplomacy_skill = 1
		}
		100 = {
			trigger = { martial < medium_skill_rating }
			add_martial_skill = 1
		}
		100 = {
			trigger = { stewardship < medium_skill_rating }
			add_stewardship_skill = 1
		}
		100 = {
			trigger = { intrigue < medium_skill_rating }
			add_intrigue_skill = 1
		}
		100 = {
			trigger = { learning < medium_skill_rating }
			add_learning_skill = 1
		}
		100 = {
			trigger = { prowess < medium_skill_rating }
			modifier = {
				NOT = { can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:pool_character } }
				factor = 0.1
			}
			add_prowess_skill = 1
		}
		400 = {
			trigger = {
				prowess > medium_skill_rating
				NOT = {
					has_trait = berserker
				}
				faith = {
					has_doctrine = tenet_warmonger
				}
				OR = {
					culture = { has_cultural_pillar = heritage_north_germanic }
					religion = religion:germanic_religion
				}
			}
			modifier = {
				NOT = { can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:pool_character } }
				factor = 0.1
			}
			add_trait = berserker
		}
		100 = {
			trigger = {
				diplomacy >= medium_skill_rating
				NOT = {
					has_trait = poet
				}
				OR = {
					culture = { has_cultural_pillar = heritage_north_germanic }
					religion = religion:germanic_religion
					culture = { has_cultural_parameter = poet_trait_more_common }
				}
			}
			add_trait = poet
		}

		# GET MARRIED
		15 = {
			trigger = {
				is_physically_able_adult = yes
				age <= 40
				is_married = no
				can_marry_trigger = yes
				is_concubine = no
				is_lowborn = no
				is_ai = yes
				#The triggers below are here to avoid low fertility marriages (in most cases)
				NOR = {
					has_sexuality = asexual
					has_trait = celibate
					has_trait = chaste
				}
				fertility > low_fertility
			}
			
			save_temporary_scope_as = template
			
			if = {
				limit = {
					exists = scope:pool_character.location
					any_pool_character = {
						province = scope:pool_character.location
						allowed_to_marry_character_gender_trigger = { CHARACTER = scope:pool_character }
						is_physically_able_adult = yes
						age <= 40
						is_married = no
						can_marry_trigger = yes
						is_concubine = no
						is_attracted_to_gender_of = scope:pool_character
					}
				}
				random_pool_character = {
					province = scope:pool_character.location
					limit = {
						allowed_to_marry_character_gender_trigger = { CHARACTER = scope:pool_character }
						is_physically_able_adult = yes
						age <= 40
						is_married = no
						can_marry_trigger = yes
						is_concubine = no
						is_attracted_to_gender_of = scope:pool_character
					}
					save_temporary_scope_as = spouse
				}
			}
			else = {
				create_character = {
					location = scope:template.location
					gender_female_chance = scope:template.marriage_gender_adjusted_female_chance
					template = pool_repopulate_spouse
					save_temporary_scope_as = spouse
				}
			}

			if = {
				limit = {
					is_female = yes
					is_lowborn = no
					scope:spouse = {
						is_lowborn = yes
					}
				}
				marry_matrilineal = scope:spouse
			}
			else_if = {
				limit = {
					is_male = yes
					is_lowborn = yes
					scope:spouse = {
						is_lowborn = no
					}
				}
				marry_matrilineal = scope:spouse
			}
			else = {
				marry = scope:spouse
			}
			
			scope:spouse = {
				if = {
					limit = {
						exists = scope:template.host
					}
					visit_court_of = scope:template.host
				}
			}
		}

		# GET A LIFESTYLE TRAIT
		50 = {
			trigger = {
				number_of_lifestyle_traits <= 2
				is_adult = yes
				is_ai = yes
			}
			modifier = {
				number_of_lifestyle_traits = 0
				factor = 2
			}

			random_list = {
				100 = { #REVELER
					trigger = {
						NAND = {
							has_trait = lifestyle_reveler
							has_trait_xp = {
								trait = lifestyle_reveler
								value >= 100
							}
						}
						NOR = {
							has_trait = shy
							has_trait = celibate
							has_trait = temperate
							has_trait = chaste
							ai_greed < 0
						}
					}
					modifier = {
						has_trait = lifestyle_reveler
						factor = 5
					}
					modifier = {
						culture = { has_cultural_parameter = reveler_traits_more_common }
						factor = 5
					}
					if = {
						limit = {
							NOT = { has_trait = lifestyle_reveler }
						}
						add_trait = lifestyle_reveler
					}
					else = {
						add_trait_xp = {
							trait = lifestyle_reveler
							value = 10
						}
					}
				}
				100 = { #BLADEMASTER
					trigger = {
						NAND = {
							has_trait = lifestyle_blademaster
							has_trait_xp = {
								trait = lifestyle_blademaster
								value >= 100
							}
						}
						prowess >= decent_skill_rating
					}
					modifier = {
						has_trait = lifestyle_blademaster
						factor = 5
					}
					modifier = {
						factor = 3
						culture = {
							has_cultural_parameter = blademaster_traits_more_common
						}
					}
					modifier = {
						NOT = { can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:pool_character } }
						factor = 0.1
					}
					if = {
						limit = { has_trait = lifestyle_blademaster }
						add_trait_xp = {
							trait = lifestyle_blademaster
							value = 10
						}
					}
					else = { add_trait = lifestyle_blademaster }
				}
				100 = { #HUNTER
					trigger = {
						NOT = {
							hunt_lifestyle_track_greater_equal_trigger = { TRACK = hunter GREATER_EQUAL = 100 }
						}
						ai_boldness >= medium_positive_ai_value
						ai_energy >= low_positive_ai_value
						ai_compassion < high_positive_ai_value
					}
					modifier = {
						has_trait = lifestyle_hunter
						factor = 5
					}
					modifier = {
						culture = {
							OR = {
								has_cultural_parameter = hunting_traits_more_common
								has_cultural_parameter = falconer_traits_more_common
							}
						}
						factor = 5
					}
					if = {
						limit = { has_trait = lifestyle_hunter }
						random_list = {
							10 = {
								modifier = {
									culture = { has_cultural_parameter = hunting_traits_more_common }
									add = 20
								}
								add_trait_xp = {
									trait = lifestyle_hunter
									track = hunter
									value = 10
								}
							}
							10 = {
								modifier = {
									culture = { has_cultural_parameter = falconer_traits_more_common }
									add = 20
								}
								add_trait_xp = {
									trait = lifestyle_hunter
									track = falconer
									value = 10
								}
							}
						}
					}
					else = { add_trait = lifestyle_hunter }
				}
				100 = { #PHYSICIAN
					trigger = {
						NAND = {
							has_trait = lifestyle_physician
							has_trait_xp = {
								trait = lifestyle_physician
								value >= 100
							}
						}
						learning >= decent_skill_rating
					}
					modifier = {
						has_trait = lifestyle_physician
						factor = 5
					}
					modifier = {
						culture = { has_cultural_tradition = tradition_medicinal_plants }
						factor = 2
					}
					if = {
						limit = { has_trait = lifestyle_physician }
						add_trait_xp = {
							trait = lifestyle_physician
							value = 10
						}
					}
					else = { add_trait = lifestyle_physician }
				}
				100 = { #MYSTIC
					trigger = {
						NAND = {
							has_trait = lifestyle_mystic
							has_trait_xp = {
								trait = lifestyle_mystic
								value >= 100
							}
						}
						learning >= decent_skill_rating
					}
					modifier = {
						has_trait = lifestyle_mystic
						factor = 5
					}
					modifier = {
						ai_zeal > 0
						factor = 0.5
					}
					modifier = {
						is_witch_trigger = yes
						factor = 3
					}
					modifier = {
						culture = { has_cultural_parameter = mystic_trait_more_common }
						factor = 5
					}
					if = {
						limit = { has_trait = lifestyle_mystic }
						add_trait_xp = {
							trait = lifestyle_mystic
							value = 10
						}
					}
					else = { add_trait = lifestyle_mystic }
				}
				100 = { #HERBALIST
					trigger = {
						NOT = { has_trait = lifestyle_herbalist }
						learning >= decent_skill_rating
					}
					modifier = {
						ai_zeal > 0
						factor = 0.5
					}
					modifier = {
						is_witch_trigger = yes
						factor = 3
					}
					modifier = {
						culture = { has_cultural_parameter = herbalist_traits_more_common }
						factor = 5
					}
					add_trait = lifestyle_herbalist
				}
				50 = { #GARDENER
					trigger = {
						NOT = { has_trait = lifestyle_gardener }
						stewardship >= decent_skill_rating
					}
					modifier = {
						culture = { has_cultural_parameter = can_appoint_court_gardener }
						factor = 5
					}
					add_trait = lifestyle_gardener
				}
			}
		}

		#GET A COMMANDER TRAIT
		100 = {
			trigger = {
				has_trait = education_martial
				number_of_commander_traits < commander_trait_limit
				is_ai = yes
			}

			random_list = {
				1 = {
					trigger = { NOT = { has_trait = logistician } }
					add_trait = logistician
				}
				1 = {
					trigger = { NOT = { has_trait = military_engineer } }
					add_trait = military_engineer
				}
				1 = {
					trigger = { NOT = { has_trait = aggressive_attacker } }
					add_trait = aggressive_attacker
				}
				1 = {
					trigger = { NOT = { has_trait = unyielding_defender } }
					add_trait = unyielding_defender
				}
				1 = {
					trigger = { NOT = { has_trait = forder } }
					add_trait = forder
				}
				1 = {
					trigger = { NOT = { has_trait = holy_warrior } }
					add_trait = holy_warrior
				}
				1 = {
					trigger = { NOT = { has_trait = reckless } }
					add_trait = reckless
				}
				1 = {
					trigger = { NOT = { has_trait = cautious_leader } }
					add_trait = cautious_leader
				}
				1 = {
					trigger = { NOT = { has_trait = rough_terrain_expert } }
					add_trait = rough_terrain_expert
				}
				1 = {
					trigger = { NOT = { has_trait = open_terrain_expert } }
					add_trait = open_terrain_expert
				}
			}
		}

		# GET AN INTERESTING TRAIT
		20 = {
			trigger = { is_adult = yes is_ai = yes }
			random_list = {
				1 = {
					trigger = { NOT = { has_trait = lunatic } }
					add_trait = lunatic_1
				}
				1 = {
					trigger = { NOT = { has_trait = possessed } }
					add_trait = possessed_1
				}
				1 = {
					trigger = { NOT = { has_trait = scarred } }
					add_trait = scarred
					add_trait_xp = {
		                trait = scarred
		                value = {
		                    integer_range = {
		                        min = 5
		                        max = 25
		                    }
		                }
		            }
				}
				1 = {
					trigger = { NOT = { has_trait = poet } }
					add_trait = poet
				}
				1 = {
					trigger = {
						can_be_drunkard = yes
					}
					add_trait = drunkard
				}
				1 = {
					trigger = { #Does not use the can_be_rakish to reduce performance hit
						NOR = {
							has_trait = rakish
							has_trait = celibate
							has_trait = chaste
							has_sexuality = asexual
						}
					}
					add_trait = rakish
				}
				1 = { #Does not use the can_be_flagellant to reduce performance hit
					trigger = { NOT = { has_trait = flagellant } }
					add_trait = flagellant
				}
				1 = { #Does not use the can_be_contrite to reduce performance hit
					trigger = {
						NOR = {
							has_trait = deceitful
							has_trait = contrite
						}
					}
					add_trait = contrite
				}
				1 = { #Does not use the can_be_journaller to reduce performance hit
					trigger = { NOT = { has_trait = journaller } }
					add_trait = journaller
				}
				1 = {
					trigger = {
						is_eunuch_trigger = no
						is_male = yes
						age >= 12
					}
					add_trait = eunuch_1
				}
				1 = {
					trigger = {
						is_eunuch_trigger = no
						is_male = yes
						age < 12
					}
					add_trait = beardless_eunuch
				}
				1 = {
					trigger = { NOT = { has_trait = blind } }
					add_trait = blind
				}
				1 = {
					trigger = {
						NOR = {
							has_trait = intellect_bad
							has_trait = dull
							has_trait = shrewd
						}
					}
					add_trait = shrewd
				}
				1 = {
					trigger = {
						NOR = {
							has_trait = weak
							has_trait = physique_bad
							has_trait = strong
						}
					}
					add_trait = strong
				}
				1 = {
					trigger = {
						NOT = {
							has_trait = loyal
						}
					}
					add_trait = loyal
				}
				1 = {
					trigger = {
						NOT = {
							has_trait = disloyal
						}
					}
					add_trait = disloyal
				}
			}
		}

		# GET LOYAL/DISLOYAL
		10 = {
			trigger = {
			    is_ai = yes
				culture = {
					has_cultural_parameter = loyal_trait_more_common
				}
				NOT = { has_trait = loyal }
			}
			add_trait = loyal
		}
		10 = {
			trigger = {
			    is_ai = yes
				culture = {
					has_cultural_parameter = disloyal_trait_more_common
				}
				NOT = { has_trait = disloyal }
			}
			add_trait = disloyal
		}

		# GET A SECRET
		30 = {
			trigger = {
				NOT = { any_secret = { always = yes } }
				is_adult = yes
				is_ai = yes
			}

			courtier_guest_pool_character_secret_giving_effect = yes
		}

		# Learn a language
		30 = {
			trigger = {
				exists = location.county.culture
				learning >= 8
				num_of_known_languages < language_soft_cap
				NOT = {
					knows_language_of_culture = location.county.culture
				}
			}
			learn_language_of_culture = location.county.culture
		}
	} #RANDOM_LIST ENDS HERE
	
	# Certain characters learn languages very often
	random = {
		chance = {
			value = 70
			if = {
				limit = {
					has_trait = scholar
				}
				add = -50
			}
		}
		if = {
			limit = {
			    is_ai = yes
				culture = {
					has_cultural_parameter = wanderers_learn_languages
				}
				num_of_known_languages < language_soft_cap
				exists = location.county.culture
				NOT = {
					knows_language_of_culture = location.county.culture
				}
			}
			learn_language_of_culture = location.county.culture
		}
	}
	
	random = {
		chance = 20
		# Cultural Traditions
		if = { # blademaster_traits_more_common
			limit = {
				is_adult = yes
				is_ai = yes
				can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:pool_character }
				culture = {
					has_cultural_parameter = blademaster_traits_more_common
				}
			}
			blademaster_lifestyle_rank_up_effect = yes
		}
	}
	random = {
		chance = 80
		if = { # wanderers_gain_extra_combat_skills
			limit = {
			    is_ai = yes
				is_adult = yes
				can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:pool_character }
				culture = {
					has_cultural_parameter = wanderers_gain_extra_combat_skills
				}
			}
			random_list = {
				10 = {
					blademaster_lifestyle_rank_up_effect = yes
				}
				10 = {
					wanderer_give_random_commander_trait_effect = yes
				}
				20 = {
					add_prowess_skill = 1
				}
				10 = {
					add_prowess_skill = 2
				}
				20 = {
					add_martial_skill = 1
				}
				10 = {
					add_martial_skill = 2
				}
			}
		}
	}
	if = { # wanderers_gain_extra_economic_skills
		limit = {
			is_adult = yes
			is_ai = yes
			culture = {
				has_cultural_parameter = wanderers_gain_extra_economic_skills
			}
		}
		random_list = {
			20 = {
				wanderer_give_random_economic_trait_effect = yes
			}
			30 = {
				add_stewardship_skill = 1
			}
			10 = {
				add_stewardship_skill = 2
			}
			40 = {
				add_gold = 50
			}
		}
	}
	
	
	# Cultural Traditions
	random = {
		chance = 10
		if = {
			limit = {
				is_adult = yes
				is_ai = yes
				can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:pool_character }
				has_education_martial_trigger = yes
				culture = {
					has_cultural_parameter = winter_soldier_trait_more_common
				}
				NOT = {
					has_trait = winter_soldier
				}
			}
			add_trait = winter_soldier
		}
	}
	random = {
		chance = 10
		if = {
			limit = {
				is_adult = yes
				is_ai = yes
				can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:pool_character }
				has_education_martial_trigger = yes
				culture = {
					has_cultural_parameter = forest_fighter_trait_more_common
				}
				NOT = {
					has_trait = forest_fighter
				}
			}
			add_trait = forest_fighter
		}
	}
	random = {
		chance = 10
		if = {
			limit = {
				is_adult = yes
				is_ai = yes
				can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:pool_character }
				has_education_martial_trigger = yes
				culture = {
					has_cultural_parameter = rough_terrain_expert_trait_more_common
				}
				NOT = {
					has_trait = rough_terrain_expert
				}
			}
			add_trait = rough_terrain_expert
		}
	}
	random = {
		chance = 10
		if = {
			limit = {
				is_adult = yes
				is_ai = yes
				can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:pool_character }
				has_education_martial_trigger = yes
				culture = {
					has_cultural_parameter = desert_warrior_trait_more_common
				}
				NOT = {
					has_trait = desert_warrior
				}
			}
			add_trait = desert_warrior
		}
	}
	random = {
		chance = 10
		if = {
			limit = {
				is_adult = yes
				is_ai = yes
				can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:pool_character }
				has_education_martial_trigger = yes
				culture = {
					has_cultural_parameter = jungle_stalker_trait_more_common
				}
				NOT = {
					has_trait = jungle_stalker
				}
			}
			add_trait = jungle_stalker
		}
	}
	
	# Spend any excess gold to avoid having ultra-rich characters floating around
	while = {
		limit = {
			gold >= 1000
			NOT = {
				any_player = {
					exists = dynasty
					dynasty = scope:pool_character.dynasty
				}
			}
			is_ruler = no
			is_ai = yes
		}
		random_list = {
			100 = { # Spend gold on getting a friend
				trigger = {
					ai_sociability > low_negative_ai_value
					is_physically_able_adult = yes
					NOR = {
						has_trait = shy
						has_trait = reclusive
					}
					exists = scope:pool_character.location
					any_pool_character = {
						province = scope:pool_character.location
						is_physically_able_adult = yes
						NOT = { this = scope:pool_character }
						NOT = { has_any_scripted_relation = scope:pool_character }
					}
				}
				random_pool_character = {
					province = scope:pool_character.location
					limit = {
						is_physically_able_adult = yes
						NOT = { this = scope:pool_character }
						NOT = { has_any_scripted_relation = scope:pool_character }
					}
					save_temporary_scope_as = new_friend
				}
				add_prestige = major_prestige_value
				set_random_friendship_reason = { TARGET = scope:new_friend }
				pay_short_term_gold = {
					target = scope:new_friend
					gold = 500
				}
			}
			
			150 = { # Spend gold on for religious purposes
				trigger = {
					ai_zeal >= medium_positive_ai_value
					learning < 30
				}
				add_learning_skill = 3
				add_piety = major_piety_value
				remove_short_term_gold = 500
			}
			
			200 = { # Spend gold on gaining prestige and training prowess!
				trigger = {	
					can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:pool_character }
					prowess < 30
				}
				knight_increase_prowess_chance_effect = yes
				add_prestige = major_prestige_value
				remove_short_term_gold = 500
			}
			
			100 = { # Spend gold on gaining prestige and skill!
				trigger = {	
					can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:pool_character }
					martial < 25
				}
				add_martial_skill = 2
				add_prestige = major_prestige_value
				remove_short_term_gold = 500
			}
			
			100 = { # Spend gold on gaining prestige and skill!
				trigger = {
					intrigue < 25
				}
				add_intrigue_skill = 3
				add_prestige = major_prestige_value
				remove_short_term_gold = 500
			}
			
			100 = { # Spend gold on gaining prestige and skill!
				trigger = {
					stewardship < 25
				}
				add_stewardship_skill = 3
				add_prestige = major_prestige_value
				remove_short_term_gold = 500
			}
			
			100 = { # Spend gold on gaining prestige and skill!
				trigger = {
					diplomacy < 25
				}
				add_diplomacy_skill = 3
				add_prestige = major_prestige_value
				remove_short_term_gold = 500
			}
			
			100 = { # Lavish wedding!
				trigger = {
					is_physically_able_adult = yes
					age <= 40
					is_married = no
					can_marry_trigger = yes
					is_concubine = no
					#The triggers below are here to avoid low fertility marriages
					OR = {
						has_sexuality = heterosexual
						has_sexuality = bisexual
						allowed_to_marry_same_sex_trigger = yes
					}
					NOR = {
						has_trait = celibate
						has_trait = chaste
					}
					fertility > low_fertility
				}
				
				save_temporary_scope_as = template
				
				if = {
					limit = {
						exists = scope:pool_character.location
						any_pool_character = {
							province = scope:pool_character.location
							allowed_to_marry_character_gender_trigger = { CHARACTER = scope:pool_character }
							is_physically_able_adult = yes
							age <= 40
							is_married = no
							can_marry_trigger = yes
							is_concubine = no
							is_attracted_to_gender_of = scope:pool_character
						}
					}
					random_pool_character = {
						province = scope:pool_character.location
						limit = {
							allowed_to_marry_character_gender_trigger = { CHARACTER = scope:pool_character }
							is_physically_able_adult = yes
							age <= 40
							is_married = no
							can_marry_trigger = yes
							is_concubine = no
							is_attracted_to_gender_of = scope:pool_character
						}
						save_temporary_scope_as = spouse
					}
				}
				else = {
					create_character = {
						location = scope:template.location
						gender_female_chance = scope:template.marriage_gender_adjusted_female_chance
						template = pool_repopulate_spouse
						save_temporary_scope_as = spouse
					}
				}


				marry = scope:spouse
				
				scope:spouse = {
					if = {
						limit = {
							exists = scope:template.host
						}
						visit_court_of = scope:template.host
					}
				}
				remove_short_term_gold = 500
			}	
			500 = { # Become an adventurer!
				trigger = {
					has_dlc_feature = roads_to_power
					gold >= 500
					is_physically_able_adult = yes
					exists = location.county
					ai_can_valid_to_create_laamp_trigger = yes
				}
				create_landless_adventurer_title_effect = {
					REASON = flag:voluntary
					FLAVOR_CHAR = root
				}
				if = {
					limit = {
						NOT = {
							exists = global_var:pool_adventurer_spawn
						}
					}
					set_global_variable = {
						name = pool_adventurer_spawn
						value = 1
					}
				}
				else = {
					change_global_variable = {
						name = pool_adventurer_spawn
						add = 1
					}
				}
			}	
			500 = { # Just waste the gold on nonsense
				add_prestige = minor_prestige_value
				remove_short_term_gold = 500
			}
		}
	}
}