﻿
# Fires when a character joins a court. Not fired for just generated characters
# Root is the character
# scope:new_employer is their new employer
# scope:old_employer is their old employer (if they had one; otherwise unset)
on_join_court = {
	events = {
		court_maintenance.0005 # Add 'Order member' trait to courtiers who join holy order court
		unop_court_maintenance.5005 #If the court is NOT a holy order, remove the trait 'Order member' and gain modifier 'holy_order_experience_modifier'
		unop_court_maintenance.0005 #If the court is a holy order, remove the modifier 'holy_order_experience_modifier'
	}
}

# Fires when a character leaves a court. Not fired when leaving due to death or similar
# Will still fire even if on_join_court is firing (fires just before it)
# Root is the character
# scope:old_employer is their old employer
on_leave_court = {
	effect = {
		scope:old_employer = {
			every_courtier = {
				limit = { exists = var:booner_target }
				employed_booner_invalidation_effect = { EMPLOYEE = this LIEGE = scope:old_employer }
			}
			if = {
				limit = {
					is_alive = yes
					has_variable_list = halved_position_salary_employees
				}
				remove_list_variable = {
					name = halved_position_salary_employees
					target = root
				}
			}
			if = {
				limit = { 
					is_alive = yes
					has_variable_list = increased_position_salary_employees
				}
				remove_list_variable = {
					name = increased_position_salary_employees
					target = root
				}
			}
		}
		root = {
			if = {
				limit = {
					has_character_flag = suzerains_missionary
				}
				remove_character_flag = suzerains_missionary
			}
		}
		remove_variable = court_8311_cooldown
	}
	events = {
		stewardship_duty.1064 # Cancels the employment contract between this character and their former employer.
		unop_court_maintenance.0006 # Remove 'Order member' trait to courtiers who leave holy order court & add the corresponding modifier
	}
}
