﻿#Used in the debug interaction debug_move_domicile_interaction
on_travel_court_guest_start = {
	effect = {
		if = {
			limit = {
				exists = court_owner
			}
			court_owner = {
				save_scope_as = previous_liege
			}
		}
		if = {
			limit = {
				exists = host
			}
			host = {
				save_scope_as = previous_liege
			}
			if = {
				limit = {
					NOT = {
						exists = var:last_visited_ruler
					}
				}
				set_variable = {
					name = last_visited_ruler
					value = this.host
					days = 1825
				}
			}
		}
		if = {
			limit = {
				exists = scope:previous_liege
			}
			scope:previous_liege = {
				if = {
					limit = {
						scope:actor = {
							OR = {
								is_knight_of = scope:previous_liege
								is_councillor_of = scope:previous_liege
								any_court_position_employer = { this = scope:previous_liege }
							}
						}
					}
					add_opinion = {
						target = scope:actor
						modifier = quit_court_important_courtier_opinion
					}
					scope:actor = {
						add_prestige = minor_prestige_loss
					}
				}
				else_if = {
					limit = {
						any_courtier = {
							this = scope:actor
						}
					}
					add_opinion = {
						target = scope:actor
						modifier = quit_court_opinion
					}
				}
				remove_courtier_or_guest = scope:actor
				#if = {
				#	limit = {
				#		any_courtier_or_guest = {
				#			OR = {	
				#				is_close_family_of = scope:actor
				#				is_consort_of = scope:actor
				#			}
				#		can_leave_court_trigger = yes
				#			NOT = { exists = current_travel_plan }
				#		}
				#	}
				#	every_courtier_or_guest = {
				#		limit = {
				#			any_courtier_or_guest = {
				#				OR = {	
				#					is_close_family_of = scope:actor
				#					is_consort_of = scope:actor
				#				}
				#				can_leave_court_trigger = yes
				#			}
				#			NOT = { exists = current_travel_plan }
				#		}
				#		scope:previous_liege = {
				#			remove_courtier_or_guest = prev
				#		}
				#		scope:actor.current_travel_plan = {
				#			add_companion = prev
				#		}
				#	}
				#}
			}
		}
	}
}

on_travel_court_guest_end = {
	effect = {
		if = {
			limit = {
				exists = root.location.barony
			}
			root.location.barony.holder = {
				save_scope_as = barony_owner
			}
			hidden_effect = {
				visit_court_of = scope:barony_owner
			}
			send_interface_message = {
				type = msg_visiting_court
				left_icon = scope:barony_owner
			}
			if = {
				limit = {
					exists = var:last_visited_ruler
				}
				remove_variable = last_visited_ruler
			}
			set_variable = {
				name = last_visited_ruler
				value = this.host
				days = 1825
			}
		}
	}
}