Skip to main content
The Deno 2 Release Candidate is here
Learn more
method ItemHelper.prototype.getAttachmentMainParent
import { ItemHelper } from "https://deno.land/x/sptaki@1.2.0/helpers/ItemHelper.d.ts";

Retrieves the main parent item for a given attachment item.

This method traverses up the hierarchy of items starting from a given itemId, until it finds the main parent item that is not an attached attachment itself. In other words, if you pass it an item id of a suppressor, it will traverse up the muzzle brake, barrel, upper receiver, and return the gun that the suppressor is ultimately attached to, even if that gun is located within multiple containers.

It's important to note that traversal is expensive, so this method requires that you pass it a Map of the items to traverse, where the keys are the item IDs and the values are the corresponding Item objects. This alleviates some of the performance concerns, as it allows for quick lookups of items by ID.

Parameters

itemId: string
  • The unique identifier of the item for which to find the main parent.
itemsMap: Map<string, Item>
  • A Map containing item IDs mapped to their corresponding Item objects for quick lookup.

Returns

Item | null

The Item object representing the top-most parent of the given item, or null if no such parent exists.