﻿
#Events handling the Spouse Councillor position in the background

namespace = councillor_spouse_background


#Ongoing event tracking background progress
councillor_spouse_background.0001 = {
	hidden = yes

	trigger = {
		is_alive = yes
		has_council_position = councillor_spouse
		any_spouse = {
			exists = this.cp:councillor_spouse
			this.cp:councillor_spouse = root
		}
	}

	immediate = {
		if = {
			limit = {
				is_landed = no
				is_capable_adult_ai = yes
				NOT = { is_performing_council_task = task_spouse_default }
			}
			#Diplomacy rank up
			if = {
				limit = {
					is_performing_council_task = task_court_politics
					NOT = { has_trait = diplomat }
					var:councillor_spouse_lifestyle_progress > councillor_spouse_lifestyle_rank_up_threshold
				}
				councillor_spouse_lifestyle_rank_up_effect = {
					SKILL = diplomacy
				}
			}
			#Martial rank up
			else_if = {
				limit = {
					is_performing_council_task = task_chivalry
					NOT = { has_trait = strategist }
					var:councillor_spouse_lifestyle_progress > councillor_spouse_lifestyle_rank_up_threshold
				}
				councillor_spouse_lifestyle_rank_up_effect = {
						SKILL = martial
				}
			}
			#Intrigue rank up
			else_if = {
				limit = {
					is_performing_council_task = task_court_intrigue
					NOT = { has_trait = schemer }
					var:councillor_spouse_lifestyle_progress > councillor_spouse_lifestyle_rank_up_threshold
				}
				councillor_spouse_lifestyle_rank_up_effect = {
					SKILL = intrigue
				}
			}
			#Stewardship rank up
			else_if = {
				limit = {
					is_performing_council_task = task_manage_domain
					NOT = { has_trait = architect }
					var:councillor_spouse_lifestyle_progress > councillor_spouse_lifestyle_rank_up_threshold
				}
				councillor_spouse_lifestyle_rank_up_effect = {
					SKILL = stewardship
				}
			}
			#Learning rank up
			else_if = {
				limit = {
					is_performing_council_task = task_patronage
					NOT = { has_trait = scholar }
					var:councillor_spouse_lifestyle_progress > councillor_spouse_lifestyle_rank_up_threshold
				}
				councillor_spouse_lifestyle_rank_up_effect = {
					SKILL = learning
				}
			}
			if = {
				limit = {
					NOT = { exists = scope:ranked_up }
					#Prevent further progress from being added once the councillor is at max lifestyle rank:
					trigger_if = {
						limit = {
							is_performing_council_task = task_court_politics
						}
						NOT = { has_trait = diplomat }
					}
					trigger_else_if = {
						limit = {
							is_performing_council_task = task_chivalry
						}
						NOT = { has_trait = strategist }
					}
					trigger_else_if = {
						limit = {
							is_performing_council_task = task_manage_domain
						}
						NOT = { has_trait = architect }
					}
					trigger_else_if = {
						limit = {
							is_performing_council_task = task_patronage
						}
						NOT = { has_trait = scholar }
					}
					trigger_else_if = {
						limit = {
							is_performing_council_task = task_court_intrigue
						}
						NOT = { has_trait = schemer }
					}
					trigger_else = {
						always = yes
					}
				}
				if = {
					limit = {
						has_variable = councillor_spouse_lifestyle_progress
					}
					change_variable = {
						name = councillor_spouse_lifestyle_progress
						add = councillor_spouse_lifestyle_progress_increase
					}
				}
				else = {
					set_variable = {
						name = councillor_spouse_lifestyle_progress
						value = councillor_spouse_lifestyle_progress_increase
					}
				}
			}
		}

		clear_saved_scope = ranked_up
		trigger_event = {
			id = councillor_spouse_background.0001
			months = 6
		}
	}
}
