Skip to content

Itemization API

Oen44 edited this page Jun 5, 2026 · 7 revisions

ItemBase

Description

Base item created using editor, saved as Resource.

New inventory items will reference this base item. Attributes such as name, description, icon, and other properties are stored in this resource.

Properties

name: String # Display name of the item.
description: String # Description text for the item.
icon: Texture2D # Icon used for UI display.
stackable: bool # If true, this item can stack.
max_stacks: int # Maximum quantity per stack (only relevant when stackable is true).
base_value: int # Base value of the item (used e.g. for buy/sell pricing).
slot_type: SlotType # Equipment slot type this item can be equipped into.
armor: int # Armor value (shown/used for armor and shield slot types).
min_damage: int # Minimum damage (shown/used for weapon slot type).
max_damage: int # Maximum damage (shown/used for weapon slot type).
attack_speed: float # Attack speed (shown/used for weapon slot type).
block_chance: int # Block chance (shown/used for shield slot type).
id: String # Auto-generated ID derived from name (snake_case). Computed via _get_id().

Methods

## Returns the item id (auto-generated from name if empty).
_get_id() -> String
## Returns true if the item base is valid (has a name and icon).
is_valid() -> bool
## Hides/shows editor properties based on current slot_type (editor-only validation hook).
_validate_property(property: Dictionary) -> void

Item

Description

An item instance.

Contains a reference to its base item and unique affixes.

Properties

parent_inventory: String # ID of the inventory this item currently belongs to.
slot_id: int # Slot index within the parent inventory (-1 if not placed).
vendor_item: bool # If true, this item is treated as a vendor listing item.
currency_item: ItemBase # Currency item reference (if this item represents currency context).
price: int # Explicit price override (0 means use base.base_value).
base: ItemBase # Reference to the base item definition.
id: String # Convenience id getter (returns base.id).
quantity: int # Stack quantity.
affixes: Array[AffixInstance] # Array of affixes applied to this item (order preserved).

Methods

## Sets the item quantity, recalculates worth, and emits changed(item).
set_quantity(new_quantity: int) -> void
## Rolls a random set of affixes for this item from the AffixPool (up to 4).
roll_affixes() -> void
## Adds an affix instance to this item, recalculates worth, and emits changed(item).
add_affix(affix: AffixInstance) -> void
## Removes an affix by ID (if present), recalculates worth, and emits changed(item).
remove_affix(affix_id: String) -> void
## Returns true if this item has an affix with the given ID.
has_affix(affix_id: String) -> bool
## Returns the affix instance with the given ID, or null if not present.
get_affix(affix_id: String) -> AffixInstance
## Sets the item price, recalculates worth, and emits changed(item).
set_price(new_price: int) -> void
## Returns the calculated worth of this item (base value/price + affix multipliers).
get_worth() -> int
## Serializes this item into a Dictionary (base_id, quantity, affixes).
serialize() -> Dictionary
## Deserializes this item from a Dictionary (currently restores affixes).
deserialize(data: Dictionary) -> void
## Creates a copy of this item with the given quantity, duplicating affixes and key metadata.
clone(amount: int) -> Item

Signals

# Emitted when this item's state changes (quantity, affixes, price, etc.).
changed(item: Item)

AffixPool

Description

A pool of affix definitions to roll from.

Properties

affixes_path: String # Directory where AffixDefinition resources are located.

Methods

## Rolls an affix for the given item from the provided candidates list, avoiding duplicates already on the item.
roll_affix(candidates: Array[AffixDefinition], item: Item) -> AffixInstance
## Retrieves all affixes that can be applied to the given item.
get_affixes_for(item: Item) -> Array[AffixDefinition]
## Retrieves an affix definition by its ID.
get_affix(affix_id: String) -> AffixDefinition
## Loads all AffixDefinition resources from affixes_path.
_load_affixes() -> void
## Performs a weighted random selection from a list of AffixDefinitions.
_weighted_pick(list: Array[AffixDefinition]) -> AffixDefinition

AffixDefinition

Description

An affix definition for items.

Properties

enabled: bool # If false, affix won't be rolled but still working for existing items.
hidden: bool # If true, affix won't be visible in tooltips.
id: String # Unique affix identifier.
description: String # Text to show in tooltips; use # as placeholder for any value (in right order).
weight: int # Relative roll weight used by AffixPool weighted selection.
price_multiplier: float # Multiplies the item's price/base value when the affix is present.

Methods

## Returns true if this affix can be applied to the given item.
can_apply_to(_item: Item) -> bool
## Rolls this affix for the given item and returns an AffixInstance (or null if it cannot roll).
roll(_item: Item) -> AffixInstance
## Returns values range for values at index
range(index: int) -> String

AffixInstance

Description

An instance of an affix applied to an item.

Properties

id: String # Affix ID referencing an AffixDefinition.
values: Array[Variant] # Rolled values for this affix

ItemEvent

Description

Base class for item events (use, equip, unequip).

This class can be extended to create custom events with specific behavior (e.g., healing potions, special equip effects). Intended to be assigned from ItemBase (for example as an on_use event resource instance).

Methods

## Called to check if the item can be used. Return true if it can be used, false otherwise.
can_use(_item: Item, _user: Node) -> bool
## Called when the item is used. Return true if the item was successfully used, false otherwise.
on_use(_item: Item, _user: Node) -> bool
## Called when the item is equipped. Return false to prevent equipping.
on_equip(_item: Item, _user: Node) -> bool
## Called when the item is unequipped.
on_unequip(_item: Item, _user: Node) -> void

Clone this wiki locally