# These replace and complement vanilla employment_decisions.txt

decisions = {
	employ_chancellor = {
		ai_check_interval = 6

		only_playable = yes

		potential = {
			num_of_baron_titles >= 1 # Similar to 'is_landed = yes', but includes family_palace holdings
		}

		allow = {
			wealth >= 10
			in_seclusion = no
		}

		effect = {
			wealth = -10

			if = {
				limit = { NOT = { has_religion_feature = religion_matriarchal } }

				if = {
					limit = {
						OR = {
							has_law = status_of_women_4
							has_religion_feature = religion_matriarchal
							has_gender_equal_game_rule_trigger = yes
						}

						NOT = { has_religion_feature = religion_patriarchal }
					}

					create_random_diplomat = {
						random_traits = yes
						culture = ROOT
						religion = ROOT
						dynasty = actually_culture
						female = 50

						attributes = {
							diplomacy = 8
							learning = 2
							stewardship = 2
							intrigue = 2
							martial = 2
						}
					}
				}
				else = {
					create_random_diplomat = {
						random_traits = yes
						culture = ROOT
						religion = ROOT
						dynasty = actually_culture
						female = no

						attributes = {
							diplomacy = 8
							learning = 2
							stewardship = 2
							intrigue = 2
							martial = 2
						}
					}
				}
			}
			else = {
				create_random_diplomat = {
					random_traits = yes
					culture = ROOT
					religion = ROOT
					dynasty = actually_culture
					female = yes

					attributes = {
						diplomacy = 8
						learning = 2
						stewardship = 2
						intrigue = 2
						martial = 2
					}
				}
			}

			new_character = {
				# TODO: Add random flavor here

				if = {
					limit = { has_dharmic_religion_trigger = yes }

					add_trait = kshatriya
					character_event = { id = RoI.30121 }
				}
				else_if = {
					limit = {
						OR = {
							religion_openly_hellenic_or_reformed_trigger = yes
							has_religion_feature = religion_astrology
						}
					}

					add_western_zodiac_trait_effect = yes
				}

				if = {
					limit = {
						religion_group = pagan_group
						has_religion_feature = religion_no_leader
					}

					random_list = {
						25 = { add_trait = pagan_branch_1 }
						25 = { add_trait = pagan_branch_2 }
						25 = { add_trait = pagan_branch_3 }
						25 = { add_trait = pagan_branch_4 }
					}
				}

				save_event_target_as = invited_character
			}

			character_event = { id = NE.1 }
		}

		ai_will_do = {
			factor = 1

			trigger = {
				NOT = {
					job_chancellor = {
						always = yes
					}
				}
			}
		}
	}

	employ_commander = {
		ai_check_interval = 6

		only_playable = yes

		potential = {
			num_of_baron_titles >= 1 # Similar to 'is_landed = yes', but includes family_palace holdings
		}

		allow = {
			wealth >= 10
			in_seclusion = no
		}

		effect = {
			wealth = -10

			custom_tooltip = {
				text = promoted_commander_TT

				if = {
					limit = {
						any_owned_bloodline = {
							has_bloodline_flag = bloodline_inspire_commanders
							bloodline_is_active_for = PREV
						}
					}

					random_list = {
						95 = { spawn_great_commander_effect = yes }

						5 = {
							spawn_fantastic_commander_effect = yes

							new_character = {
								opinion = {
									name = opinion_legendary_commander
									years = 50
									who = ROOT
								}
							}
						}
					}
				}
				else = {
					spawn_good_commander_effect = yes
				}
			}

			character_event = { id = NE.1 } # Notification event for invited character
		}

		ai_will_do = {
			factor = 1

			trigger = {
				NOT = {
					job_marshal = {
						always = yes
					}
				}
			}
		}
	}

	employ_treasurer = {
		ai_check_interval = 6

		only_playable = yes

		potential = {
			num_of_baron_titles >= 1 # Similar to 'is_landed = yes', but includes family_palace holdings
		}

		allow = {
			wealth >= 10
			in_seclusion = no
		}

		effect = {
			wealth = -10

			if = {
				limit = { NOT = { has_religion_feature = religion_matriarchal } }

				if = {
					limit = {
						OR = {
							has_law = status_of_women_4
							has_religion_feature = religion_matriarchal
							has_gender_equal_game_rule_trigger = yes
						}

						NOT = { has_religion_feature = religion_patriarchal }
					}

					create_random_steward = {
						random_traits = yes
						culture = ROOT
						religion = ROOT
						dynasty = actually_culture
						female = 50

						attributes = {
							diplomacy = 2
							learning = 2
							stewardship = 8
							intrigue = 2
							martial = 2
						}
					}
				}
				else = {
					create_random_steward = {
						random_traits = yes
						culture = ROOT
						religion = ROOT
						dynasty = actually_culture
						female = no

						attributes = {
							diplomacy = 2
							learning = 2
							stewardship = 8
							intrigue = 2
							martial = 2
						}
					}
				}
			}
			else = {
				create_random_steward = {
					random_traits = yes
					culture = ROOT
					religion = ROOT
					dynasty = actually_culture
					female = yes

					attributes = {
						diplomacy = 2
						learning = 2
						stewardship = 8
						intrigue = 2
						martial = 2
					}
				}
			}

			new_character = {
				remove_trait = slow
				remove_trait = imbecile
				remove_trait = dull
				remove_trait = mystic
				remove_trait = socializer
				remove_trait = game_master
				remove_trait = hedonist
				remove_trait = duelist
				remove_trait = hunter
				remove_trait = strategist
				remove_trait = administrator
				remove_trait = architect
				remove_trait = gardener
				remove_trait = master_schemer
				remove_trait = impaler
				remove_trait = master_seducer
				remove_trait = master_seductress
				remove_trait = theologian
				remove_trait = scholar

				# Flavor Randomization
				random_list = {
					35 = {} # Nothing
					15 = { change_stewardship = 2 }
					10 = { add_trait = gardener }
					10 = { add_trait = architect }
					10 = { add_trait = administrator }
					10 = { change_stewardship = 4 }
					5 = { change_stewardship = 6 }
					5 = { add_trait = shrewd }
				}

				if = {
					limit = { has_dharmic_religion_trigger = yes }

					add_trait = kshatriya
					character_event = { id = RoI.30121 }
				}
				else_if = {
					limit = {
						OR = {
							religion_openly_hellenic_or_reformed_trigger = yes
							has_religion_feature = religion_astrology
						}
					}

					add_western_zodiac_trait_effect = yes
				}

				if = {
					limit = {
						religion_group = pagan_group
						has_religion_feature = religion_no_leader
					}

					random_list = {
						25 = { add_trait = pagan_branch_1 }
						25 = { add_trait = pagan_branch_2 }
						25 = { add_trait = pagan_branch_3 }
						25 = { add_trait = pagan_branch_4 }
					}
				}

				save_event_target_as = invited_character
			}

			character_event = { id = NE.1 } # Notification event for invited character
		}

		ai_will_do = {
			factor = 1

			trigger = {
				NOT = {
					job_treasurer = {
						always = yes
					}
				}
			}
		}
	}

	employ_spymaster = {
		ai_check_interval = 6

		only_playable = yes

		potential = {
			num_of_baron_titles >= 1 # Similar to 'is_landed = yes', but includes family_palace holdings
		}

		allow = {
			wealth >= 10
			in_seclusion = no
		}

		effect = {
			wealth = -10

			if = {
				limit = { NOT = { has_religion_feature = religion_matriarchal } }

				if = {
					limit = {
						OR = {
							has_law = status_of_women_4
							has_religion_feature = religion_matriarchal
							has_gender_equal_game_rule_trigger = yes
						}

						NOT = { has_religion_feature = religion_patriarchal }
					}

					create_random_intriguer = {
						random_traits = yes
						culture = ROOT
						religion = ROOT
						dynasty = actually_culture
						female = 50

						attributes = {
							diplomacy = 2
							learning = 2
							stewardship = 2
							intrigue = 8
							martial = 2
						}
					}
				}
				else = {
					create_random_intriguer = {
						random_traits = yes
						culture = ROOT
						religion = ROOT
						dynasty = actually_culture
						female = no

						attributes = {
							diplomacy = 2
							learning = 2
							stewardship = 2
							intrigue = 8
							martial = 2
						}
					}
				}
			}
			else = {
				create_random_intriguer = {
					random_traits = yes
					culture = ROOT
					religion = ROOT
					dynasty = actually_culture
					female = yes

					attributes = {
						diplomacy = 2
						learning = 2
						stewardship = 2
						intrigue = 8
						martial = 2
					}
				}
			}

			new_character = {
				# TODO: Add random flavor here

				if = {
					limit = { has_dharmic_religion_trigger = yes }

					add_trait = kshatriya
					character_event = { id = RoI.30121 }
				}
				else_if = {
					limit = {
						OR = {
							religion_openly_hellenic_or_reformed_trigger = yes
							has_religion_feature = religion_astrology
						}
					}

					add_western_zodiac_trait_effect = yes
				}

				if = {
					limit = {
						religion_group = pagan_group
						has_religion_feature = religion_no_leader
					}

					random_list = {
						25 = { add_trait = pagan_branch_1 }
						25 = { add_trait = pagan_branch_2 }
						25 = { add_trait = pagan_branch_3 }
						25 = { add_trait = pagan_branch_4 }
					}
				}

				save_event_target_as = invited_character
			}

			character_event = { id = NE.1 }
		}

		ai_will_do = {
			factor = 1

			trigger = {
				NOT = {
					job_spymaster = {
						always = yes
					}
				}
			}
		}
	}

	employ_lord_spiritual = {
		ai_check_interval = 6

		only_playable = yes

		potential = {
			num_of_baron_titles >= 1 # Similar to 'is_landed = yes', but includes family_palace holdings
		}

		allow = {
			piety >= 10
			in_seclusion = no
		}

		effect = {
			piety = -10

			if = {
				limit = { religion_allows_male_temple_holders = yes }

				if = {
					limit = { religion_allows_female_temple_holders = yes }

					create_random_priest = {
						random_traits = yes
						culture = ROOT
						religion = ROOT
						dynasty = actually_culture
						female = 50

						attributes = {
							diplomacy = 2
							learning = 8
							stewardship = 2
							intrigue = 2
							martial = 2
						}
					}
				}
				else = {
					create_random_priest = {
						random_traits = yes
						culture = ROOT
						religion = ROOT
						dynasty = actually_culture
						female = no

						attributes = {
							diplomacy = 2
							learning = 8
							stewardship = 2
							intrigue = 2
							martial = 2
						}
					}
				}
			}
			else = {
				create_random_priest = {
					random_traits = yes
					culture = ROOT
					religion = ROOT
					dynasty = actually_culture
					female = yes

					attributes = {
						diplomacy = 2
						learning = 8
						stewardship = 2
						intrigue = 2
						martial = 2
					}
				}
			}

			new_character = {
				remove_trait = slow
				remove_trait = imbecile
				remove_trait = dull
				remove_trait = mystic
				remove_trait = socializer
				remove_trait = game_master
				remove_trait = hedonist
				remove_trait = duelist
				remove_trait = hunter
				remove_trait = strategist
				remove_trait = administrator
				remove_trait = architect
				remove_trait = gardener
				remove_trait = master_schemer
				remove_trait = impaler
				remove_trait = master_seducer
				remove_trait = master_seductress
				remove_trait = theologian
				remove_trait = scholar

				# Flavor Randomization
				random_list = {
					35 = {} # Nothing
					20 = { add_trait = theologian }
					15 = { change_learning = 2 }
					10 = { change_learning = 4 }
					 5 = { change_learning = 6 }
					 5 = { add_trait = scholar }
					 5 = { add_trait = mystic }
					 5 = { add_trait = shrewd }
				}

				# If we have a wonder upgrade with "inpires_learning" flag, the priest will be better
				if = {
					limit = { ROOT = { realm_wonder_or_upgrade_has_flag_inspires_learning_trigger = yes } }

					random_list = {
						15 = { add_trait = scholar change_learning = 1 }
						10 = { add_trait = scholar change_learning = 2 }
						 5 = { add_trait = scholar change_learning = 3 }
						10 = { add_trait = erudite }
						10 = { add_trait = physician }
						10 = { add_trait = scholarly_theologian }
						10 = { add_trait = mastermind_theologian }
					}

					random_list = {
						50 = { } # Nothing
						10 = { add_trait = genius }
						10 = { add_trait = chaste }
						10 = { add_trait = poet }
						10 = { add_trait = proud }
						10 = { add_trait = humble }
					}
				}

				add_ascetic_trait_effect = yes

				if = {
					limit = {
						religion_group = pagan_group
						has_religion_feature = religion_no_leader
					}

					random_list = {
						25 = { add_trait = pagan_branch_1 }
						25 = { add_trait = pagan_branch_2 }
						25 = { add_trait = pagan_branch_3 }
						25 = { add_trait = pagan_branch_4 }
					}
				}

				save_event_target_as = invited_character
			}

			character_event = { id = NE.1 } # Notification event for invited character
		}

		ai_will_do = {
			factor = 1

			trigger = {
				NOT = {
					job_spiritual = {
						always = yes
					}
				}
			}
		}
	}

	present_debutant = {
		ai_check_interval = 12

		only_playable = yes

		potential = {
			num_of_baron_titles >= 1 # Similar to 'is_landed = yes', but includes family_palace holdings
		}

		allow = {
			wealth >= 10
			is_adult = yes
			in_seclusion = no
		}

		effect = {
			wealth = -10

			if = {
				limit = { ai = yes }
				set_character_flag = employed_debutante
			}

			spawn_debutante_effect = yes

			hidden_effect = {
				event_target:invited_character = {
					remove_trait = slow
					remove_trait = imbecile
					remove_trait = dull
				}
			}

			character_event = { id = NE.1 } # Notification event for invited character
		}

		ai_will_do = {
			factor = 1

			trigger = {
				has_ambition = obj_find_lover
				wealth >= 100

				# To match the debutante spawned by the effect
				trigger_if = {
					limit = { is_female = yes }
					has_religion_feature = religion_matriarchal
				}

				NOR = {
					religion_group = muslim
					has_character_modifier = ai_austerity
					has_character_flag = employed_debutante
				}
			}
		}
	}

}