﻿#On actions about titles

# A title change makes the character rank up in the landed tiers (eg Duke -> King)
# root = character ranking up
# scope:title = old primary title
on_rank_up = { # Will not fire during history execution or for dying characters
	first_valid_on_action = {
		calyver_on_rank_up_on_actions
	}
}
calyver_on_rank_up_on_actions = {
	effect = {
		assign_di_child_trait_to_all_children_effect = yes
		if = {
			limit = {
				character:han_8910 = {
					is_alive = yes
					NOT = { has_character_flag = took_former_spouse_as_concubine_flag }
				}
				this = character:han_8910
				any_former_spouse = {
					is_alive = yes
					can_become_concubine_of_character_trigger = { CHARACTER = character:han_8910 }
					NOT = {
						has_demoted_or_divorced_opinion_trigger = {
							TARGET = character:han_8910
						}
					}
				}
			}
			every_former_spouse = {
				limit = {
					is_alive = yes
					can_become_concubine_of_character_trigger = { CHARACTER = character:han_8910 }
					NOT = {
						has_demoted_or_divorced_opinion_trigger = {
							TARGET = character:han_8910
						}
					}
				}
				if = {
					limit = {
						NOT = {
							is_courtier_of = character:han_8910
						}
					}
					character:han_8910 = {
						add_courtier = prev
					}
				}
				character:han_8910 = {
					if = {
						limit = {
							is_character_interaction_valid = {
								recipient = prev
								interaction = ai_make_concubine_interaction
							}
						}
						run_interaction = {
							interaction = ai_make_concubine_interaction
							actor = character:han_8910
							recipient = prev
							execute_threshold = accept
						}
					}
				}
			}
			add_character_flag = took_former_spouse_as_concubine_flag
		}
	}
}