ItemInstance ​
Inherits: RefCounted
Runtime instance of an item that references an ItemDefinition for configuration Handles individual item state, modifications, effects, and socket management
Variables ​
ItemDefinition | definition | |
String | instance_id | |
GameHost.SystemHub | system_hub | |
CombatManager: | combat_manager | |
int: | stack_size | |
Dictionary | runtime_data | {} |
Array[EffectInstance] | active_equipment_effects | [] |
bool | is_equipped | false |
Entity | equipped_to | null |
Array[SocketInstance] | socket_instances | [] |
bool | all_sockets_filled | false |
EffectInstance | full_socket_bonus_effect | null |
Timer | cooldown_timer | null |
bool | is_on_cooldown | false |
int | current_charges | 0 |
AbilityInstance | ability_instance | null |
Array[EnchantEntry] | enchants | [] |
Effect: | current_enchant |
Methods ​
SocketInstance | get_socket( index: int ) |
int | get_socket_count() |
int | get_occupied_socket_count() |
bool | are_all_sockets_filled() |
bool | socket_item_at_index( index: int, item: ItemInstance ) |
ItemInstance | unsocket_item_at_index( index: int ) |
int | find_available_socket_for_item( item: ItemInstance ) |
bool | auto_socket_item( item: ItemInstance ) |
Array[ItemInstance] | get_socketed_items() |
String | get_display_name() |
String | get_description() |
Texture2D | get_icon() |
int | get_vendor_value() |
Vector2i | get_shape() |
float | get_unit_weight() |
float | get_total_weight() |
int | get_max_stack_size() |
int | get_item_level() |
Dictionary | get_generated() |
bool | is_generated() |
float | get_scale_factor() |
Quality | get_quality() |
Color | get_quality_color() |
String | get_quality_name() |
int | get_quality_tier() |
void | apply_generated( data: Dictionary ) |
bool | equip( user: Entity ) |
bool | unequip() |
bool | use( user: Entity ) |
bool | can_use( user: Entity ) |
bool | enchant_target_item( target_equipment: ItemInstance, user: Entity ) |
int | get_current_charges() |
int | get_max_charges() |
bool | has_charges() |
bool | is_at_full_charges() |
float | get_charge_percentage() |
bool | can_stack_with( other_item: ItemInstance ) |
int | add_to_stack( amount: int ) |
int | remove_from_stack( amount: int ) |
bool | is_stack_full() |
bool | is_stack_empty() |
bool | meets_requirements( user: Entity ) |
String | get_requirement_failure_message( user: Entity ) |
bool | is_equipment() |
bool | is_consumable() |
bool | is_weapon() |
bool | is_socketable() |
bool | add_enchant_effect( effect: Effect, duration: float = -1, source: String = "" ) |
Dictionary | preview_enchant( effect: Effect ) |
void | remove_enchant( effect: Effect = null, cleanup_reason: String = "" ) |
void | remove_current_enchant( cleanup_reason: String = "" ) |
bool | has_enchant() |
Effect | get_current_enchant() |
Array[Effect] | get_enchant_effects() |
Dictionary | get_enchant_metadata( effect: Effect = null ) |
float | get_enchant_time_remaining( effect: Effect = null ) |
Array | get_enchant_save_data() |
void | restore_enchant_from_save( save_data: Variant ) |
Dictionary | to_save_data() |
void | from_save_data( save_data: Dictionary ) |
void | receive_shared_cooldown( duration: float ) |
void | cleanup() |
Signals ​
item_used( item_instance: ItemInstance ) ​
Emitted when the item is used
item_properties_changed( item_instance: ItemInstance ) ​
Emitted when item properties are dynamically changed (durability, enchantments, etc.)
item_equipped( item_instance: ItemInstance, user: Entity ) ​
Emitted when item is equipped (for equipment items)
item_unequipped( item_instance: ItemInstance, user: Entity ) ​
Emitted when item is unequipped (for equipment items)
item_consumed( item_instance: ItemInstance, user: Entity, amount_consumed: int ) ​
Emitted when item is consumed (for consumable items)
item_depleted( item_instance: ItemInstance ) ​
Emitted when on-use item has no charges left and should be removed
socket_changed( item_instance: ItemInstance, socket_index: int, socketable_item: ItemInstance ) ​
Emitted when a socket state changes (item socketed/unsocketed)
sockets_full_status_changed( item_instance: ItemInstance, are_full: bool ) ​
Emitted when all sockets become filled or unfilled
quest_item_used( item_instance: ItemInstance, quest_id: int, user: Entity ) ​
Emitted when a quest item is used: the item, the quest and the user.
readable_item_used( item_instance: ItemInstance, pages: Array[String] ) ​
Emitted when a readable item is used: the item and its pages.
enchant_applied( item_instance: ItemInstance, enchant_effect: Effect ) ​
Emitted when an enchant is applied to this item
enchant_removed( item_instance: ItemInstance, enchant_effect: Effect, reason: String ) ​
Emitted when an enchant expires or is removed from this item
enchant_scroll_used( item_instance: ItemInstance, enchant_scroll: ItemDefinitionEnchantScroll, user: Entity ) ​
Emitted when an enchant scroll is used (for UI integration)
Variable descriptions ​
ItemDefinition definition ​
Reference to the immutable item definition (shared across instances)
String instance_id ​
Unique instance ID for save/load and tracking
GameHost.SystemHub system_hub ​
Combat system manager
CombatManager: combat_manager ​
The combat manager of the game: item definitions start their effects (consumables, socketed gems) through it
int: stack_size ​
Current stack size for this item instance
Dictionary runtime_data = ​
Runtime data storage for item-specific information
Array[EffectInstance] active_equipment_effects = [] ​
Active effect instances from this equipment (only for ItemDefinitionEquipment)
bool is_equipped = false ​
Whether this equipment is currently equipped
Entity equipped_to = null ​
The entity this equipment is equipped to (if any)
Array[SocketInstance] socket_instances = [] ​
Array of socket instances for this item (only for equipment with sockets)
bool all_sockets_filled = false ​
Whether all sockets are currently filled
EffectInstance full_socket_bonus_effect = null ​
Active effect instance from full socket bonus (if any)
Timer cooldown_timer = null ​
Cooldown timer for consumable items
bool is_on_cooldown = false ​
Whether this consumable is on cooldown
int current_charges = 0 ​
Current charges for on-use items
AbilityInstance ability_instance = null ​
Ability instance for on-use items (holds the runtime state of the item's ability)
Array[EnchantEntry] enchants = [] ​
The enchants of the item (see the enchant system below)
Effect: current_enchant ​
The first enchant effect (null if none), kept for older code
Method descriptions ​
SocketInstance get_socket( index: int ) ​
Get socket instance by index
int get_socket_count() ​
Get total number of sockets
int get_occupied_socket_count() ​
Get number of occupied sockets
bool are_all_sockets_filled() ​
Check if all sockets are filled
bool socket_item_at_index( index: int, item: ItemInstance ) ​
Socket an item into a specific socket
ItemInstance unsocket_item_at_index( index: int ) ​
Remove item from a specific socket
int find_available_socket_for_item( item: ItemInstance ) ​
Find first available socket for a socketable item
bool auto_socket_item( item: ItemInstance ) ​
Auto-socket an item into the first available compatible socket
Array[ItemInstance] get_socketed_items() ​
Get all socketed items
String get_display_name() ​
Get display name from definition (a generated item: with the names of its affixes, as its quality says)
String get_description() ​
Get description from definition
Texture2D get_icon() ​
Get icon from definition
int get_vendor_value() ​
Get vendor value from definition (a generated item: times the value multiplier of its quality and the growth of an item that scales)
Vector2i get_shape() ​
Get max stack size from definition The cells the item covers in a grid (width, height; never below 1 x 1)
float get_unit_weight() ​
What one of this item weighs
float get_total_weight() ​
What the whole stack weighs
int get_max_stack_size() ​
How many of the item fit in one stack.
int get_item_level() ​
The item level (a generated item: the level it was generated at)
Dictionary get_generated() ​
What was rolled for this item (empty for an item that was not generated)
bool is_generated() ​
Was the item generated (random affixes, a level)?
float get_scale_factor() ​
How much the written stats grow for an item that scales with its item level (1 for any other item)
Quality get_quality() ​
The quality of the item: the one that was rolled for a generated item, else the one of the definition
Color get_quality_color() ​
The color of the quality of the item.
String get_quality_name() ​
The name of the quality of the item (Common when it has none).
int get_quality_tier() ​
The tier of the quality of the item (higher is rarer).
void apply_generated( data: Dictionary ) ​
Puts the rolled data on the item: the extra sockets it has, and the data itself (what ItemGenerator made; also what a save gives back)
bool equip( user: Entity ) ​
Equip this item (for equipment items) - now only handles state tracking
bool unequip() ​
Unequip this item - now only handles state tracking
bool use( user: Entity ) ​
Use the item
bool can_use( user: Entity ) ​
Check if this item instance can be used
bool enchant_target_item( target_equipment: ItemInstance, user: Entity ) ​
Enchant a target equipment item (for enchant scrolls)
int get_current_charges() ​
Get current charges for on-use items
int get_max_charges() ​
Get maximum charges for on-use items
bool has_charges() ​
Check if on-use item has charges remaining
bool is_at_full_charges() ​
Check if on-use item is at full charges
float get_charge_percentage() ​
Get charges remaining as a percentage (0.0 to 1.0)
bool can_stack_with( other_item: ItemInstance ) ​
Check if this item can stack with another item instance
int add_to_stack( amount: int ) ​
Add to stack size
int remove_from_stack( amount: int ) ​
Remove from stack size
bool is_stack_full() ​
Check if stack is full
bool is_stack_empty() ​
Check if stack is empty
bool meets_requirements( user: Entity ) ​
Check if this item meets requirements for a user
String get_requirement_failure_message( user: Entity ) ​
Get requirement failure message
bool is_equipment() ​
Check if this is a specific item type
bool is_consumable() ​
Is the item a consumable?
bool is_weapon() ​
Is the item a weapon?
bool is_socketable() ​
Is the item a gem or rune that fits a socket?
bool add_enchant_effect( effect: Effect, duration: float = -1, source: String = "" ) ​
Add an enchant effect to this equipment item. False when the item is not equipment, or a group of the enchant refuses it (the item keeps its enchants)
Dictionary preview_enchant( effect: Effect ) ​
Would this enchant be refused, and which enchants would it replace? (for a scroll or an ability that asks before it spends anything)
void remove_enchant( effect: Effect = null, cleanup_reason: String = "" ) ​
Remove one enchant (null: every enchant of the item)
void remove_current_enchant( cleanup_reason: String = "" ) ​
Remove every enchant (the single enchant of the old rules)
bool has_enchant() ​
Does this item have an enchant?
Effect get_current_enchant() ​
The first enchant effect (null if none); get_enchant_effects lists them all
Array[Effect] get_enchant_effects() ​
The effects of the enchants on the item.
Dictionary get_enchant_metadata( effect: Effect = null ) ​
The data of an enchant (the first one when no effect is given).
float get_enchant_time_remaining( effect: Effect = null ) ​
Time left on an enchant (-1 for permanent, 0 if it is not on the item); the first enchant when none is given
Array get_enchant_save_data() ​
Enchant save data: one entry per enchant
void restore_enchant_from_save( save_data: Variant ) ​
Restore the enchants from save data (a list, or the single enchant dictionary of older saves)
Dictionary to_save_data() ​
Save instance runtime state
void from_save_data( save_data: Dictionary ) ​
Load instance runtime state
void receive_shared_cooldown( duration: float ) ​
A member of one of the item's groups was used: this item is on cooldown for the shared time too (unless it is on a longer one)
void cleanup() ​
Clean up all resources used by this item instance