ItemID

Lightweight value type that uniquely identifies an item by combining a type ID and variant ID. Provides value equality, implicit conversions, and serves as the primary key for item lookups in the ItemDatabase.

Definition

Namespace: Paragon.Townskeep.ItemSystem Assembly: Townskeep.dll

[Serializable]
public struct ItemID : IEquatable<ItemID>

Implements: IEquatable<ItemID>

Remarks

ItemID encodes two dimensions of item identity:

  • TypeID — identifies the item type (e.g., "Iron Sword" = 1, "Health Potion" = 2). This maps to the factory's hash code / ItemData.ItemID.

  • VariantID — identifies a specific variant within the type (e.g., variant 0 = base, variant 1 = enchanted). Defaults to 0.

The struct supports implicit conversions to/from int (TypeID only) and (int, int) tuples (TypeID + VariantID), making it ergonomic for both simple lookups and variant-aware code.

Quick Lookup

Goal
How

Create from type only

ItemID id = 5; or new ItemID(5)

Create with variant

new ItemID(5, 2) or ItemID id = (5, 2);

Get invalid sentinel

ItemID.Invalid (TypeID=-1, VariantID=-1)

Check equality

id1 == id2

Get type as int

int type = itemId; (implicit)

Decompose to tuple

(int type, int variant) = itemId; (implicit)

Display

itemId.ToString()"(5:2)"

Fields

TypeID

The item type identifier. Readonly.

VariantID

The variant identifier within the item type. Readonly. Defaults to 0.

Methods

Constructor

Parameter
Type
Description

typeID

int

The item type identifier

variantID

int

The variant identifier (default: 0)

Equals

Value equality comparing both TypeID and VariantID.

GetHashCode

Combines TypeID and VariantID via HashCode.Combine.

ToString

Returns "(TypeID:VariantID)" format.

Example: new ItemID(3, 1).ToString()"(3:1)"

Statics

Invalid

Sentinel value representing an invalid or unset item ID. Both TypeID and VariantID are -1.

Operators

Equality

Compares both TypeID and VariantID.

Implicit Conversions

From
To
What Transfers

ItemID

(int, int)

(TypeID, VariantID)

ItemID

int

TypeID only

(int, int)

ItemID

(TypeID, VariantID)

int

ItemID

TypeID, VariantID defaults to 0

Common Pitfalls

circle-exclamation
circle-exclamation

Examples

Looking Up an Item

Comparing Items

See Also

  • ItemData — data record containing the raw ItemID and VariantID fields

  • ItemDatabase — registry using ItemID for factory lookups

  • ItemFactory — factory that produces items

Last updated