﻿ao_ttd_add_character_to_same_court_effect = {
	save_temporary_scope_as = ao_ttd_root_character
	if = {
		limit = { $CHARACTER$ = { is_ruler = no } }
		if = {
			limit = {
				is_ruler = yes
				$CHARACTER$ = { NOT = { is_courtier_of = scope:ao_ttd_root_character } }
			}
			custom_description = {
				text = AO_TTD_JOINS_COURT
				subject = $CHARACTER$
				object = scope:ao_ttd_root_character
				add_courtier = $CHARACTER$
				ao_ttd_treat_character_effect = { CHARACTER = $CHARACTER$ }
			}
		}
		else_if = {
			limit = {
				is_courtier = yes
				exists = scope:ao_ttd_root_character.liege
				$CHARACTER$ = { NOT = { is_courtier_of = scope:ao_ttd_root_character.liege } }
			}
			custom_description = {
				text = AO_TTD_JOINS_COURT
				subject = $CHARACTER$
				object = scope:ao_ttd_root_character
				liege ?= {
					add_courtier = $CHARACTER$
					ao_ttd_treat_character_effect = { CHARACTER = $CHARACTER$ }
				}
			}
		}
		else_if = {
			limit = {
				is_pool_guest = yes
				exists = scope:ao_ttd_root_character.host
				$CHARACTER$ = { NOT = { is_pool_guest_of = scope:ao_ttd_root_character.host } }
			}
			scope:ao_ttd_root_character.host = { add_visiting_courtier = $CHARACTER$ }
		}
		else_if = {
			limit = {
				exists = location
				NOT = { location = $CHARACTER$.location }
			}
			$CHARACTER$ = { move_to_pool_at = prev.location }
		}
	}
}

ao_ttd_treat_character_effect = {
	if = { # Treat the new arrival
		limit = { court_physician_available_trigger = yes }
		$CHARACTER$ = {
			if = {
				limit = {
					has_treatable_disease_trigger = yes
					has_recent_treatment_trigger = no # If already being treated then health event is already set to retrigger
				}
				if = { # If both diseased and wounded delay wounded event to spread them out
					limit = {
						has_wounds_trigger = yes
						has_recent_wound_treatment_trigger = no # If already being treated then health event is already set to retrigger
					}
					trigger_event = {
						id = health.3100
						days = 2
					}
					trigger_event = {
						id = health.4999
						days = 5
					}
				}
				else = {
					trigger_event = {
						id = health.3100
						days = 2
					}
				}
			}
			else_if = {
				limit = {
					has_wounds_trigger = yes
					has_recent_wound_treatment_trigger = no # If already being treated then health event is already set to retrigger
				}
				trigger_event = {
					id = health.4999
					days = 2
				}
			}
		}
	}
}