﻿#New Effects
inspirational_progress_point_gain_effect = {
	if = {
		limit = {
			NOT = {
				exists = scope:adventurer
			}
		}
		if = {
			limit = {
				has_inspirational_lifestyle_trait_trigger = no 
				NOT = { has_trait = $INSPIRATIONAL_TRAIT$ } 
			}
			add_trait = $INSPIRATIONAL_TRAIT$
		}	
		if = {
			limit = {
				has_trait = $INSPIRATIONAL_TRAIT$
				NOT = { has_character_flag = local_artisan }
			}
			add_trait_xp = {
				trait = $INSPIRATIONAL_TRAIT$
				track = $TRACK$
				value = {
					integer_range = {
						min = 0
						max = 1
					}
					add = $PROGRESS$
					multiply = 2
				}
			}
		}
		else_if = {
			limit = {
				has_trait = $INSPIRATIONAL_TRAIT$
			}
			add_trait_xp = {
				trait = $INSPIRATIONAL_TRAIT$
				track = $TRACK$
				value = {
					add = $PROGRESS$
					multiply = 2
				}
			}
		}
	}
}

inspirational_progress_point_gain_single_track_effect = {
	if = {
		limit = {
			NOT = {
				exists = scope:adventurer
			}
		}
		if = {
			limit = {
				has_inspirational_lifestyle_trait_trigger = no 
				NOT = { has_trait = $INSPIRATIONAL_TRAIT$ } 
			}
			add_trait = $INSPIRATIONAL_TRAIT$
		}
		if = {
			limit = {
				has_trait = $INSPIRATIONAL_TRAIT$
				NOT = { has_character_flag = local_artisan }
			}
			add_trait_xp = {
				trait = $INSPIRATIONAL_TRAIT$
				value = {
					integer_range = {
						min = 0
						max = 1
					}
					add = $PROGRESS$
					multiply = 2
				}
			}
		}
		else_if = {
			limit = {
				has_trait = $INSPIRATIONAL_TRAIT$
			}
			add_trait_xp = {
				trait = $INSPIRATIONAL_TRAIT$
				value = {
					add = $PROGRESS$
					multiply = 2
				}
			}
		}	
	}
}

inspirational_clean_flag_effect = {
	if = {
		limit = { has_variable = wealth }
		remove_variable = wealth
	}
	if = {
		limit = { has_variable = quality }
		remove_variable = quality
	}
	if = {
		limit = { has_variable = artifact_quality }
		remove_variable = artifact_quality
	}
	if = {
		limit = { has_variable = artifact_dedication_var }
		remove_variable = artifact_dedication_var
	}
	if = {
		limit = { has_variable = artifact_dedication_a_var }
		remove_variable = artifact_dedication_a_var
	}
	if = {
		limit = { has_variable = artifact_dedication_b_var }
		remove_variable = artifact_dedication_b_var
	}
	if = {
		limit = { has_variable = artifact_dedication_d_var }
		remove_variable = artifact_dedication_d_var
	}
	if = {
		limit = { has_variable = artifact_dedication_e_var }
		remove_variable = artifact_dedication_e_var
	}
	if = {
		limit = { has_variable = artifact_dedication_f_var }
		remove_variable = artifact_dedication_f_var
	}
	if = {
		limit = { has_variable = artifact_dedication_g1_var }
		remove_variable = artifact_dedication_g1_var
	}
	if = {
		limit = { has_variable = artifact_dedication_g2_var }
		remove_variable = artifact_dedication_g2_var
	}
	if = {
		limit = { has_variable = artifact_dedication_h_var }
		remove_variable = artifact_dedication_h_var
	}
	if = {
		limit = { has_variable = artifact_inscribe_motto_var }
		remove_variable = artifact_inscribe_motto_var
	}
	if = {
		limit = { has_variable = adventure_destination }
		remove_variable = adventure_destination
	}
	if = {
		limit = { has_variable = artifact_artisan_type }
		remove_variable = artifact_artisan_type
	}
	if = {
		limit = { has_variable = artifact_decoder_ring }
		remove_variable = artifact_decoder_ring
	}
	if = {
		limit = { has_variable = artifact_signet_ring }
		remove_variable = artifact_signet_ring
	}
}

better_inspiration_completion_removal_basic_effect = {
	if = {
		limit = { has_variable = book_artifact_subject }
		remove_variable = book_artifact_subject
	}
	if = {
		limit = { has_variable = book_artifact_topic }
		remove_variable = book_artifact_topic
	}
	if = {
		limit = { has_variable = book_topic_category }
		remove_variable = book_topic_category
	}
	if = {
		limit = { has_variable = book_subject_witch_scope }
		remove_variable = book_subject_witch_scope
	}
	if = {
		limit = { has_variable = quality }
		remove_variable = quality
	}
	if = {
		limit = { has_variable = wealth }
		remove_variable = wealth
	}
	if = {
		limit = { has_variable = book_content_quality }
		remove_variable = book_content_quality
	}
	if = {
		limit = { has_variable = book_topic_cat_name }
		remove_variable = book_topic_cat_name
	}
	if = {
		limit = { has_variable = book_topic_dog_name }
		remove_variable = book_topic_dog_name
	}
	if = {
		limit = { has_variable = book_topic_united_title }
		remove_variable = book_topic_united_title
	}
	if = {
		limit = { has_variable = book_topic_created_title }
		remove_variable = book_topic_created_title
	}
	if = {
		limit = { has_variable = book_topic_restored_title }
		remove_variable = book_topic_restored_title
	}
	if = {
		limit = { has_variable = relevant_title }
		remove_variable = relevant_title
	}
	if = {
		limit = { has_variable = artifact_tapestry_scene }
		remove_variable = artifact_tapestry_scene
	}
	if = {
		limit = { has_variable = adventure_artifact_location }
		remove_variable = adventure_artifact_location
	}
	if = {
		limit = { has_variable = artifact_weapon_type }
		remove_variable = artifact_weapon_type
	}
	if = {
		limit = { has_variable = artifact_armor_type }
		remove_variable = artifact_armor_type
	}
	if = {
		limit = { has_variable = artifact_artisan_type }
		remove_variable = artifact_artisan_type
	}
	if = {
		limit = { has_variable = artifact_smith_type }
		remove_variable = artifact_smith_type
	}
	if = {
		limit = { has_variable = artifact_alchemy_type }
		remove_variable = artifact_alchemy_type
	}
	if = {
		limit = { has_variable = adventure_type }
		remove_variable = adventure_type
	}
	inspirational_clean_flag_effect = yes
}

better_inspiration_completion_effect = {
	if = {
		limit = { exists = scope:owner }
		scope:owner = {
			better_inspiration_completion_removal_basic_effect = yes
		}
	}
	if = {
		limit = { exists = scope:inspiration_sponsor }
		scope:inspiration_sponsor = {
			better_inspiration_completion_removal_basic_effect = yes
		}
	}
	if = {
		limit = { exists = scope:inspiration_owner }
		scope:inspiration_owner = {
			better_inspiration_completion_removal_basic_effect = yes
			# They might also have a bunch of blocker-flags saved from events
			if = {
				limit = { has_character_flag = had_event_fund_inspiration_2001 }
				remove_character_flag = had_event_fund_inspiration_2001
			}
			if = {
				limit = { has_character_flag = had_event_fund_inspiration_2002 }
				remove_character_flag = had_event_fund_inspiration_2002
			}
			if = {
				limit = { has_character_flag = had_event_fund_inspiration_2003 }
				remove_character_flag = had_event_fund_inspiration_2003
			}
			if = {
				limit = { has_character_flag = had_event_fund_inspiration_2004 }
				remove_character_flag = had_event_fund_inspiration_2004
			}
			if = {
				limit = { has_character_flag = had_event_fund_inspiration_2005 }
				remove_character_flag = had_event_fund_inspiration_2005
			}
			if = {
				limit = { has_character_flag = had_event_fund_inspiration_2006 }
				remove_character_flag = had_event_fund_inspiration_2006
			}
			if = {
				limit = { has_character_flag = had_event_fund_inspiration_2021 }
				remove_character_flag = had_event_fund_inspiration_2021
			}
			if = {
				limit = { has_character_flag = had_event_fund_inspiration_2050 }
				remove_character_flag = had_event_fund_inspiration_2050
			}
			if = {
				limit = { has_character_flag = had_event_fund_inspiration_2080 }
				remove_character_flag = had_event_fund_inspiration_2080
			}
			if = {
				limit = { has_character_flag = had_event_fund_inspiration_2090 }
				remove_character_flag = had_event_fund_inspiration_2090
			}
			if = {
				limit = { has_character_flag = had_event_fund_inspiration_2130 }
				remove_character_flag = had_event_fund_inspiration_2130
			}
			if = {
				limit = { has_character_flag = had_event_fund_inspiration_3001 }
				remove_character_flag = had_event_fund_inspiration_3001
			}
			if = {
				limit = { has_character_flag = had_event_fund_inspiration_3011 }
				remove_character_flag = had_event_fund_inspiration_3011
			}
			if = {
				limit = { has_character_flag = had_event_fund_inspiration_3012 }
				remove_character_flag = had_event_fund_inspiration_3012
			}
			if = {
				limit = { has_character_flag = had_event_fund_inspiration_3013 }
				remove_character_flag = had_event_fund_inspiration_3013
			}
			if = {
				limit = { has_character_flag = had_event_fund_inspiration_3014 }
				remove_character_flag = had_event_fund_inspiration_3014
			}
			if = {
				limit = { has_character_flag = had_event_fund_inspiration_3015 }
				remove_character_flag = had_event_fund_inspiration_3015
			}
			if = {
				limit = { has_character_flag = had_event_fund_inspiration_3030 }
				remove_character_flag = had_event_fund_inspiration_3030
			}
			if = {
				limit = { has_character_flag = had_event_fund_inspiration_3031 }
				remove_character_flag = had_event_fund_inspiration_3031
			}
			if = {
				limit = { has_character_flag = had_event_fund_inspiration_4001 }
				remove_character_flag = had_event_fund_inspiration_4001
			}
			if = {
				limit = { has_character_flag = had_event_fund_inspiration_5011 }
				remove_character_flag = had_event_fund_inspiration_5011
			}
			if = {
				limit = { has_character_flag = had_event_fund_inspiration_5021 }
				remove_character_flag = had_event_fund_inspiration_5021
			}
			if = {
				limit = { has_character_flag = had_event_fund_inspiration_6001 }
				remove_character_flag = had_event_fund_inspiration_6001
			}
			if = {
				limit = { has_character_flag = had_event_fund_inspiration_6002 }
				remove_character_flag = had_event_fund_inspiration_6002
			}
			if = {
				limit = { has_character_flag = had_event_fund_inspiration_6003 }
				remove_character_flag = had_event_fund_inspiration_6003
			}
			if = {
				limit = { has_character_flag = had_event_fund_inspiration_6004 }
				remove_character_flag = had_event_fund_inspiration_6004
			}
			if = {
				limit = { has_character_flag = had_event_fund_inspiration_6005 }
				remove_character_flag = had_event_fund_inspiration_6005
			}
			if = {
				limit = { has_character_flag = had_event_fund_inspiration_6006 }
				remove_character_flag = had_event_fund_inspiration_6006
			}
			if = {
				limit = { has_character_flag = had_event_fund_inspiration_8001 }
				remove_character_flag = had_event_fund_inspiration_8001
			}
			if = {
				limit = { has_character_flag = had_event_fund_inspiration_8011 }
				remove_character_flag = had_event_fund_inspiration_8011
			}
			if = {
				limit = { has_character_flag = had_event_fund_inspiration_8012 }
				remove_character_flag = had_event_fund_inspiration_8012
			}
			if = {
				limit = { has_character_flag = had_event_fund_inspiration_8013 }
				remove_character_flag = had_event_fund_inspiration_8013
			}
			if = {
				limit = { has_character_flag = had_event_fund_inspiration_8014 }
				remove_character_flag = had_event_fund_inspiration_8014
			}
			if = {
				limit = { has_character_flag = had_event_fund_inspiration_8015 }
				remove_character_flag = had_event_fund_inspiration_8015
			}
			if = {
				limit = { has_character_flag = had_event_fund_inspiration_8017 }
				remove_character_flag = had_event_fund_inspiration_8017
			}
			#Inspirational Events
			if = {
				limit = { has_character_flag = had_event_inspirational_0002 }
				remove_character_flag = had_event_inspirational_0002
			}
			if = {
				limit = { has_character_flag = had_event_inspirational_0003 }
				remove_character_flag = had_event_inspirational_0003
			}
		}
	}
}

inspirational_throne_point_gain_effect = {
	if = {
		limit = {
			court_grandeur_current_level >= 5
			any_equipped_character_artifact = {
				artifact_slot_type = throne
				NOT = { has_variable = inspired_throne }
			}
		}
		every_equipped_character_artifact = {
			limit = { artifact_type = throne }
			if = {
				limit = { NOT = { has_variable = inspirational_throne } }
				set_variable = { 
					name = inspirational_throne
					value = 1
				}
			}
			else = {
				change_variable = {
					name = inspirational_throne
					add = 1
				}
			}
		}
	}
}

inspirational_throne_modifier_add_effect = {
	every_equipped_character_artifact = {
		limit = { 
			artifact_type = throne 
			var:inspirational_throne >= 5
			NOT = { has_variable = inspired_throne }
		}
		if = {
			limit = { artifact_owner = { has_court_type = court_diplomatic } }
			add_artifact_modifier = inspirational_artifact_diplomacy_per_prestige_level_modifier
		}
		else_if = {
			limit = { artifact_owner = { has_court_type = court_warlike } }
			add_artifact_modifier = inspirational_artifact_martial_per_prestige_level_modifier
		}
		else_if = {
			limit = { artifact_owner = { has_court_type = court_administrative } }
			add_artifact_modifier = inspirational_artifact_stewardship_per_prestige_level_modifier
		}
		else_if = {
			limit = { artifact_owner = { has_court_type = court_intrigue } }
			add_artifact_modifier = inspirational_artifact_intrigue_per_prestige_level_modifier
		}
		else_if = {
			limit = { artifact_owner = { has_court_type = court_scholarly } }
			add_artifact_modifier = inspirational_artifact_learning_per_prestige_level_modifier
		}
		else_if = {
			limit = { artifact_owner = { has_court_type = court_tribal } }
			add_artifact_modifier = inspirational_artifact_prowess_per_prestige_level_modifier
		}
		set_variable = { name = inspired_throne }
	}
}

inspirational_improve_artificer_effect = {
	if = {
		limit = {
			OR = {
				has_character_modifier = local_artisan_modifier
				has_character_flag = local_artisan
			}
		}
		remove_character_modifier = local_artisan_modifier
		remove_character_flag = local_artisan
		custom_tooltip = inspirational_no_longer_local_artisan
	}
	else = {
		random_list = {
			20 = { #blacksmith
				trigger = {
					OR = {
						has_inspirational_lifestyle_trait_trigger = no
						has_trait = inspirational_blacksmith
					}
				}
				modifier = {
					add = 10
					OR = {
						weapon_inspiration_average_skill_value >= medium_inspiration_skill
						armor_inspiration_average_skill_value >= medium_inspiration_skill
					}
				}
				compare_modifier = {
					value = weapon_inspiration_average_skill_value
					multiplier = 2.5
				}
				compare_modifier = {
					value = armor_inspiration_average_skill_value
					multiplier = 2.5
				}
				modifier = { #Some cultures are more likely to pick this vocation than others
					add = 10
					culture = {
						OR = {
							has_cultural_tradition = tradition_frugal_armorsmiths
							has_cultural_tradition = tradition_metal_craftsmanship
						}
					}
				}
				random_list = {
					1 = {
						inspirational_progress_point_gain_effect = { INSPIRATIONAL_TRAIT = inspirational_blacksmith TRACK = weaponsmith PROGRESS = 2 }
					}
					1 = {
						inspirational_progress_point_gain_effect = { INSPIRATIONAL_TRAIT = inspirational_blacksmith TRACK = armorsmith PROGRESS = 2 }
					}
				}
			}
			20 = { #goldsmith
				trigger = {
					OR = {
						has_inspirational_lifestyle_trait_trigger = no
						has_trait = inspirational_goldsmith
					}
				}
				modifier = {
					add = 10
					smith_inspiration_average_skill_value >= medium_inspiration_skill
				}
				compare_modifier = {
					value = smith_inspiration_average_skill_value
					multiplier = 5
				}
				modifier = { #Some cultures are more likely to pick this vocation than others
					add = 10
					culture = {
						OR = {
							has_cultural_tradition = tradition_metal_craftsmanship
							has_cultural_tradition = tradition_ancient_miners
						}
					}
				}
				random_list = {
					1 = {
						inspirational_progress_point_gain_effect = { INSPIRATIONAL_TRAIT = inspirational_goldsmith TRACK = majesty PROGRESS = 2 }
					}
					1 = {
						inspirational_progress_point_gain_effect = { INSPIRATIONAL_TRAIT = inspirational_goldsmith TRACK = luxury PROGRESS = 2 }
					}
				}
			}
			20 = { #artisan
				trigger = {
					OR = {
						has_inspirational_lifestyle_trait_trigger = no
						has_trait = inspirational_artisan
					}
				}
				modifier = {
					add = 10
					artisan_inspiration_average_skill_value >= medium_inspiration_skill
				}
				compare_modifier = {
					value = artisan_inspiration_average_skill_value
					multiplier = 5
				}
				modifier = {
					culture = { #Some cultures are more likely to pick this vocation than others
						has_cultural_parameter = improved_artisan_inspiration
					}
					add = 10
				}
				random_list = {
					1 = {
						inspirational_progress_point_gain_effect = { INSPIRATIONAL_TRAIT = inspirational_artisan TRACK = carpentry PROGRESS = 2 }
					}
					1 = {
						inspirational_progress_point_gain_effect = { INSPIRATIONAL_TRAIT = inspirational_artisan TRACK = sculpture PROGRESS = 2 }
					}
				}
			}
			20 = { #author
				trigger = {
					OR = {
						has_inspirational_lifestyle_trait_trigger = no
						has_trait = inspirational_author
					}
				}
				modifier = {
					add = 10
					book_inspiration_average_skill_value >= medium_inspiration_skill
				}
				compare_modifier = {
					value = book_inspiration_average_skill_value
					multiplier = 5
				}
				modifier = {
					culture = { #Some cultures are more likely to pick this vocation than others
						OR = {
							has_cultural_tradition = tradition_language_scholars
							has_cultural_tradition = tradition_philosopher_culture
							has_cultural_tradition = tradition_legalistic
						}
					}
					add = 10
				}
				inspirational_progress_point_gain_single_track_effect = { INSPIRATIONAL_TRAIT = inspirational_author PROGRESS = 2 }
			}
			20 = { #weaver
				trigger = {
					OR = {
						has_inspirational_lifestyle_trait_trigger = no
						has_trait = inspirational_weaver
					}
				}
				modifier = {
					add = 10
					weaver_inspiration_average_skill_value >= medium_inspiration_skill
				}
				compare_modifier = {
					value = weaver_inspiration_average_skill_value
					multiplier = 5
				}
				modifier = {
					culture = { #Some cultures are more likely to pick this vocation than others
						has_cultural_parameter = improved_weaver_inspiration
					}
					add = 10
				}
				inspirational_progress_point_gain_single_track_effect = { INSPIRATIONAL_TRAIT = inspirational_weaver PROGRESS = 2 }
			}
			2 = { #alchemist
				trigger = {
					OR = {
						has_inspirational_lifestyle_trait_trigger = no
						has_trait = inspirational_alchemist
					}
				}
				modifier = { #Alchemy arrived to Europe in the 13th century, but existed basically everywhere else before that
					add = -1
					culture_has_european_heritage_pillar_trigger = yes
					current_date < 1200.01.01
				}
				modifier = {
					add = 2
					alchemy_inspiration_average_skill_value >= medium_inspiration_skill
				}
				compare_modifier = {
					value = alchemy_inspiration_average_skill_value
					multiplier = 1
				}
				modifier = { 
					add = 2
					has_trait = lifestyle_mystic
				}
				random_list = {
					1 = {
						inspirational_progress_point_gain_effect = { INSPIRATIONAL_TRAIT = inspirational_alchemist TRACK = theory PROGRESS = 2 }
					}
					1 = {
						inspirational_progress_point_gain_effect = { INSPIRATIONAL_TRAIT = inspirational_alchemist TRACK = applied PROGRESS = 2 }
					}
				}
			}
		}
	}
}
#Overridden Effects

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 = lifestyle_poet
				}
				OR = {
					culture = { has_cultural_pillar = heritage_north_germanic }
					religion = religion:germanic_religion
					culture = { has_cultural_parameter = poet_trait_more_common }
				}
			}
			add_trait = lifestyle_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
				#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
			}
			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
				}
			}
		}

		#LEARN INSPIRATIONAL LIFESTYLE TRAIT
		50 = {
			trigger = {
				number_of_lifestyle_traits <= 2
				is_adult = yes
			}

			random_list = {
				20 = { #blacksmith
					trigger = {
						OR = {
							has_inspirational_lifestyle_trait_trigger = no
							has_trait = inspirational_blacksmith
						}
					}
					random_list = {
						1 = {
							inspirational_progress_point_gain_effect = { INSPIRATIONAL_TRAIT = inspirational_blacksmith TRACK = weaponsmith PROGRESS = 2 }
						}
						1 = {
							inspirational_progress_point_gain_effect = { INSPIRATIONAL_TRAIT = inspirational_blacksmith TRACK = weaponsmith PROGRESS = 2 }
						}
					}
				}
				20 = { #goldsmith
					trigger = {
						OR = {
							has_inspirational_lifestyle_trait_trigger = no
							has_trait = inspirational_goldsmith
						}
					}
					random_list = {
						1 = {
							inspirational_progress_point_gain_effect = { INSPIRATIONAL_TRAIT = inspirational_goldsmith TRACK = majesty PROGRESS = 2 }
						}
						1 = {
							inspirational_progress_point_gain_effect = { INSPIRATIONAL_TRAIT = inspirational_goldsmith TRACK = luxury PROGRESS = 2 }
						}
					}
				}
				20 = { #artisan
					trigger = {
						OR = {
							has_inspirational_lifestyle_trait_trigger = no
							has_trait = inspirational_artisan
						}
					}
					random_list = {
						1 = {
							inspirational_progress_point_gain_effect = { INSPIRATIONAL_TRAIT = inspirational_artisan TRACK = carpentry PROGRESS = 2 }
						}
						1 = {
							inspirational_progress_point_gain_effect = { INSPIRATIONAL_TRAIT = inspirational_artisan TRACK = sculpture PROGRESS = 2 }
						}
					}
				}
				20 = { #author
					trigger = {
						OR = {
							has_inspirational_lifestyle_trait_trigger = no
							has_trait = inspirational_author
						}
					}
					inspirational_progress_point_gain_single_track_effect = { INSPIRATIONAL_TRAIT = inspirational_author PROGRESS = 2 }
				}
				20 = { #weaver
					trigger = {
						OR = {
							has_inspirational_lifestyle_trait_trigger = no
							has_trait = inspirational_weaver
						}
					}
					inspirational_progress_point_gain_single_track_effect = { INSPIRATIONAL_TRAIT = inspirational_weaver PROGRESS = 2 }
				}
				2 = { #alchemist
					trigger = {
						OR = {
							has_inspirational_lifestyle_trait_trigger = no
							has_trait = inspirational_alchemist
						}
					}
					modifier = { #Alchemy arrived to Europe in the 13th century, but existed basically everywhere else before that
						add = -1
						culture_has_european_heritage_pillar_trigger = yes
						current_date < 1200.01.01
					}
					modifier = { 
						add = 2
						has_trait = lifestyle_mystic
					}
					random_list = {
						1 = {
							inspirational_progress_point_gain_effect = { INSPIRATIONAL_TRAIT = inspirational_alchemist TRACK = theory PROGRESS = 2 }
						}
						1 = {
							inspirational_progress_point_gain_effect = { INSPIRATIONAL_TRAIT = inspirational_alchemist TRACK = applied PROGRESS = 2 }
						}
					}
				}
			}
		}

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

			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 }
			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 = lifestyle_poet } }
					add_trait = lifestyle_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 = {
				culture = {
					has_cultural_parameter = loyal_trait_more_common
				}
				NOT = { has_trait = loyal }
			}
			add_trait = loyal
		}
		10 = {
			trigger = {
				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
			}

			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 = {
				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
				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_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
			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
				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
				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
				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
				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
				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
		}
		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
			}
		}
	}
}

hold_court_queue_post_event_effect = {
	# Sort the ending counter.
	## If there's no ending counter, create one.
	if = {
		limit = {
			NOT = { has_variable = petitioners_dealt_with_count }
		}
		set_variable = {
			name = petitioners_dealt_with_count
			value = 1
		}
	}
	## Else if there is a counter below the total petitioner tally, increment it.
	else_if = {
		limit = { var:petitioners_dealt_with_count < initial_petitioners_value }
		change_variable = {
			name = petitioners_dealt_with_count
			add = 1
		}
	}
	## If appropriate, run the end stuff.
	if = {
		limit = {
			exists = var:petitioners_dealt_with_count
			var:petitioners_dealt_with_count >= initial_petitioners_value
		}
		# Remove the counter.
		remove_variable = petitioners_dealt_with_count
		# Launch into cleanup.
		trigger_event = hold_court.0021
		inspirational_throne_point_gain_effect = yes
		if = {
			limit = {
				any_equipped_character_artifact = {
					artifact_type = throne 
					NOT = { has_variable = inspired_throne }
					has_variable = inspirational_throne
					var:inspirational_throne >= 5
				}
			}
			trigger_event = { id = inspirational.0004 days = 7 }
		}
	}
}