﻿namespace = lwxxx_event

scripted_effect lwxxx_reclaim_concubines = {
	if = {
		limit = { has_variable_list = lwxxx_concubines_list }

		hidden_effect = {
			every_in_list = {
				variable = lwxxx_concubines_list

				save_scope_as = lwxxx_concubine

				if = {
					limit = { is_concubine = no }

					scope:lwxxx_deposed_character =  { make_concubine = scope:lwxxx_concubine }
				}

				if = {
					limit = { is_landed = no }

					if = {
						limit = { not = { is_courtier_of = scope:lwxxx_deposed_character } }

						scope:lwxxx_deposed_character = { add_courtier = scope:lwxxx_concubine }
					}

					return_to_court = yes
				}
			}
		}
	}
}

lwxxx_event.0100 = {
	hidden = yes

	trigger = {
		is_ai = no
		lwxxx_display_last_will_abdication_event_trigger = yes
		scope:lwxxx_deposed_character ?= { is_alive = yes }
	}

	immediate = {
		debug_log = "lwxxx debug lwxxx_event.0100"

		hidden_effect = {
			if = {
				limit = { any_held_title = { has_variable = lwxxx_title_abdicator } }

				create_title_and_vassal_change = {
					type = granted
					add_claim_on_loss = no
					save_scope_as = change
				}

				every_held_title = {
					limit = { has_variable = lwxxx_title_abdicator }

					change_title_holder = {
						holder = scope:lwxxx_deposed_character
						change = scope:change
					}

					remove_variable = lwxxx_title_abdicator
				}

				resolve_title_and_vassal_change = scope:change

				scope:lwxxx_deposed_character = { lwxxx_reclaim_concubines = yes }
			}

			trigger_event = lwxxx_event.0200
		}
	}

}

lwxxx_event.0200 = {
	type = character_event
	title = lwxxx_event.0200.t
	desc = lwxxx_event.0200.desc

	theme = realm

	left_portrait = {
		character = scope:lwxxx_deposed_character
		animation = beg
	}

	right_portrait = {
		character = root
		animation = dismissal
	}

	option = {
		name = lwxxx_event.0200.play_as.heir
	}

	option = {
		trigger = { scope:lwxxx_deposed_character ?= { is_landed = yes } }
		name = lwxxx_event.0200.play_as.deposed

		trigger_event = lwxxx_event.0210
	}

	option = {
		trigger = {
			has_dlc_feature = roads_to_power
			scope:lwxxx_deposed_character ?= { is_landed = no }
		}
		name = lwxxx_event.0200.play_as.adventurer

		trigger_event = lwxxx_event.0210
	}
}

lwxxx_event.0210 = {
	type = character_event
	title = lwxxx_event.0210.t
	desc = lwxxx_event.0210.desc

	theme = realm

	right_portrait = {
		character = scope:lwxxx_deposed_character
		animation = toast_goblet
	}

	option = {
		name = lwxxx_event.0210.okay

		trigger_event = lwxxx_event.0300
	}

	option = {
		name = lwxxx_event.0210.cancel
	}

}

lwxxx_event.0300 = {
	type = character_event
	title = lwxxx_event.0300.t
	desc = lwxxx_event.0300.desc

	theme = realm

	right_portrait = {
		character = scope:lwxxx_deposed_character
		animation = personality_rational
	}

	option = {
		trigger = { scope:lwxxx_deposed_character ?= { is_landed = yes } }
		name = lwxxx_event.0300.independent

		scope:lwxxx_deposed_character = {
			create_title_and_vassal_change = {
				type = independency
				save_scope_as = change
				add_claim_on_loss = no
			}
			becomes_independent = {
				change = scope:change
			}

			resolve_title_and_vassal_change = scope:change
		}

		set_player_character = scope:lwxxx_deposed_character
	}

	option = {
		trigger = { scope:lwxxx_deposed_character ?= { is_landed = yes } }
		name = lwxxx_event.0300.vassal

		set_player_character = scope:lwxxx_deposed_character
	}

	option = {
		trigger = { scope:lwxxx_deposed_character ?= { is_landed = no } }
		name = lwxxx_event.0300.adventurer

		scope:lwxxx_deposed_character = {
			if = {
				limit = {
					is_ruler = no
				}
				create_landless_adventurer_title_effect = {
					REASON = flag:voluntary
					FLAVOR_CHAR = scope:lwxxx_deposed_character
				}
			}

			scope:lwxxx_deposed_character = { lwxxx_reclaim_concubines = yes }
		}

		set_player_character = scope:lwxxx_deposed_character
	}

	option = {
		name = lwxxx_event.0300.cancel
	}

}
