on_siege_completion = {
	on_actions = {
		saca_loot_court_artifacts_on_capital_capture
	}
}

saca_loot_court_artifacts_on_capital_capture = {
	effect = {
		every_in_list = {
			list = occupied_baronies

			limit = {
				exists = holder
				holder = {
					capital_barony = prev
				}
			}

			holder = {
				every_character_artifact = {
					limit = {
						ep1_artifact_is_court_artifact_trigger = yes
						NOT = {
							has_variable = artifact_prevent_transfer
						}
					}

					add_to_list = saca_looted_court_artifacts
				}
			}
		}

		every_in_list = {
			list = saca_looted_court_artifacts
			save_scope_as = saca_looted_artifact

			artifact_owner = {
				save_scope_as = saca_previous_owner
			}

			set_owner = {
				target = root
				history = {
					actor = scope:saca_previous_owner
					recipient = root
					type = conquest
				}
			}

			scope:saca_previous_owner = {
				add_personal_artifact_claim = scope:saca_looted_artifact
			}
		}
	}
}