Items: how they are built ​
The Items chapter explains the editors. This page explains the code: what is a resource, what is an object that lives while the game runs, who owns what, and where an item can go wrong.
Definitions and instances ​
| Definition | Instance | |
|---|---|---|
| What | A shared DatabaseResource in res://src/data/items/. Never changed while the game runs | An ItemInstance, a RefCounted made when an item enters a bag, a shop or a chest |
| Holds | The kind, the stack size, the stat bonuses, the effect, the value | The stack count, the charges, the cooldown, the sockets and their gems, the enchantments with their timers, runtime_data overrides |
| Made by | The Items editor | InstanceUtility |
Always ask the instance for a value that can change (get_max_stack_size(), get_vendor_value()), not the definition: an instance may override it.
Generated items and loot ​
An item can be made with a roll: its quality, its affixes (and so its stats and effects), its item level, its name and its sockets are rolled by ItemGeneratorfrom a stat budget (ItemBudget), and kept in the instance. Loot is handed out by the loot rules of an NPC or an object. See Generated items: how they are built and Loot: how it is built.
The kinds of item ​
ItemDefinition is the base. Every kind is a subclass; the Items editor offers them in its Add dialog.
| Class | Adds |
|---|---|
ItemDefinitionConsumable | consume_effect_id, consume_amount, consume_effect_per_amount, the cooldown |
ItemDefinitionEquipment | stat_bonuses, equipment_type, armor_class, equipment_effects, on_use_ability_id, socket_definitions, full_sockets_effect, set_bonus_definition, modular_mesh_data |
ItemDefinitionEquipmentWeapon | weapon_class, the damage range and type, weapon_speed, collision_template. get_weapon_hand_requirement() is 2 when the weapon type blocks slots |
ItemDefinitionAmmo | ammo_effects. It is equipment: it sits in the ammo slot |
ItemDefinitionOnUse | ability_id and the charges |
ItemDefinitionMaterial, ItemDefinitionReadable, ItemDefinitionQuest, ItemDefinitionSocketable, ItemDefinitionEnchantScroll | Their own small sets of fields |
Using an item is ItemInstance.use(user): the definition validates (can_use) and executes (execute_use), then the instance consumes (stack, charges, cooldown). The entity announces it with entity_item_used and entity_item_consumed; a used-up item raises item_removed from its slot and entity_item_depleted.
Containers ​
| Class | Holds | Used by |
|---|---|---|
InventoryComponent | Slots of InventorySlotInstance and the currency amounts by id | Players, NPCs, chests, corpses |
EquipmentInventoryComponent | Slots of EquipmentSlotInstance, made from the slot definitions, locked or not | Entities that wear equipment |
VendorInventoryComponent | The stock and the purse of a vendor | Vendor interactables |
InventoryComponent.add_item_definition is all or nothing and splits into stacks; add_item_definition_partial adds what fits. A key item cannot be discarded: can_discard_item and discard_item are the calls a UI delete must use.
EquipmentInventoryComponent applies and removes everything an item brings: the stat bonuses, equipment_effects, the effects of its gems, the full sockets bonus, the set bonus effects, and the visuals (through signals that the rig listens to). equip_item moves the item out of the bag itself, then looks for a slot (find_best_compatible_slot: free slots first, then a displaceable one); forced = true skips the requirements of the item (used by NPC behaviors, starting gear, rewards, ammo refills and loading a save). A weapon whose type blocks slots empties them first (_handle_weapon_slot_conflicts), or moves the weapon in the way to another slot.
Crafting ​
CraftingManager (on the party manager) holds one CraftSchoolInstance for each CraftSchoolDefinition. A school keeps the skill level and experience, the learned recipe ids, a queue of CraftingJobs with one timer each, and the finished items that wait for room. start_craft checks the recipe (CraftingRecipeDefinition.can_craft), takes the materials, checks the room for the result (and gives the materials back if there is none), and queues a job for each piece. Crafts in progress are saved with who started them and restored on load.
Loot ​
LootTable.generate_loot(looter) returns {item_id: quantity}: the guaranteed entries first, then randi_range(min_items, max_items) weighted picks. An entry that cannot duplicate is excluded after it has dropped. The looter's loot_rarity gain channel raises the weight of the entries that are lighter than the average; the loot_quantity channel raises the stack sizes. Entity calls it with the entity that dealt the last damage as the looter, once when the NPC spawns or dies (LootTableLogic); a container calls it with no looter.
Vendors ​
VendorItemStock.calculate_sell_price is base_value x sell_value_multiplier x weight x item_price_modifier, rounded down and at least 1. VendorInventoryComponent.calculate_sell_price(item_instance) is what the vendor pays: vendor_value x buy_value_multiplier, at least 1, 0 when the vendor cannot afford it. sell_item_to_player and buy_item_from_player return a dictionary with success, a message, the payment and the currency_id. Restocking uses ChronoManager.total_game_hours, one timer per stocked item (item_restock_times), and starts the wait again whenever a restock is due.
Rewards and room ​
Every Reward has get_block_reason(player). Player.grant_reward keeps a blocked reward in pending_rewards (saved), warns through InstanceUtility.warn_player, and gives it when the bag has room (reward_blocked, reward_given). Quest.complete() returns false while a reward does not fit.
Saving ​
Instances save the stack, charges, cooldowns, enchantments with their remaining time, and gems. Currency amounts are saved per currency (with the maximum applied). The vendor saves its stock levels, the restock times and its purse. The learned recipes are saved as integer ids.
The classes ​
Item definitions ​
| Class | What it is |
|---|---|
| EncumbranceTier | One step of encumbrance: from this share of the carry capacity, an effect is on the character that carries it (slowed, cannot sprint, cannot jump ...). |
| InventoryStyle | The rules of the inventory of one kind of owner: how items take space, where the capacity comes from, and whether items weigh something. |
| ItemBudget | The stat budget of an item: a pool of points that the bonuses of a generated item spend. |
| ItemDefinition | Base class for all item definitions with integrated Requirement system |
| ItemDefinitionAmmo | Ammunition: arrows, bolts, bullets, and anything else an ability spends a piece of per use. |
| ItemDefinitionBag | A bag: equipment that gives its wearer more slots while it is worn (a satchel, a quiver, an herb pouch). |
| ItemDefinitionConsumable | Consumable items that provide immediate effects when used (potions, food, scrolls, etc.) Uses the effect system for all functionality - effects, validation, and state management |
| ItemDefinitionEnchantScroll | Enchantment scrolls that can permanently or temporarily enhance equipment items Uses effects system for actual enchantment functionality |
| ItemDefinitionEquipment | Equipment items that can be worn by characters to provide stat bonuses and visual changes |
| ItemDefinitionEquipmentWeapon | Weapon items that can be equipped to provide combat capabilities Inherits all equipment functionality and adds weapon-specific properties for damage, speed, and combat |
| ItemDefinitionMaterial | Material items used for crafting recipes or sold as vendor trash These items have no direct use functionality but serve as components and resources |
| ItemDefinitionOnUse | Items that function like abilities when used - trigger ability execution with charge consumption Uses charges instead of stacking for cleaner inventory management |
| ItemDefinitionQuest | Quest-related items that trigger quests or serve as quest objectives. |
| ItemDefinitionReadable | Readable items that display text content in a UI panel when used Supports multi-page documents like books, scrolls, letters, and lore texts |
| ItemDefinitionSocketable | Socketable items that can be inserted into socket slots on equipment to provide additional effects The entity that owns the socketed equipment receives the socketable's effect |
| LootEntry | One line of a loot table: an item, an amount of a currency, or another loot table. |
| LootLevelSource | Where the item level of a generated item comes from: loot of an NPC or object, a reward, a vendor. |
| LootRule | One rule of what a holder (an NPC, a chest, a crate) hands out and when: a loot table, a trigger, and where the item level of the drops comes from. |
| LootTable | A shareable resource for randomizing loot drops Can be used by entities, containers, chests, etc. |
Currency, crafting and vendors ​
| Class | What it is |
|---|---|
| CurrencyDefinition | CurrencyDefinition defines a currency type with display properties and limits Create instances as .tres files for each currency (gold, gems, credits, etc.) |
| Class | What it is |
|---|---|
| CraftingJob | Represents an active crafting operation with progress tracking Uses a single completion timer instead of polling for smoother performance Progress is calculated on-demand from timer.time_left when needed |
| CraftingManager | CraftingManager - Main interface for the crafting system Stores the professions (craft schools) of the player(s) and provides the API for UI and gameplay systems. |
| CraftingRecipeDefinition | Definition for a crafting recipe that can be executed multiple times Uses ItemDefinition references and integrates with the database system |
| CraftSchoolDefinition | Definition of a crafting school (Blacksmithing, Tailoring, Alchemy, etc.) Contains static data that can be shared across multiple instances |
| CraftSchoolInstance | Runtime instance of a craft school for a specific entity Contains learned recipes, skill progress, and active crafting state |
| Class | What it is |
|---|---|
| VendorDefinition | VendorDefinition serves as a blueprint/template that multiple vendor instances can share Contains all the static configuration data for a vendor type |
| VendorItemStock | Defines how a vendor stocks a specific item (template for runtime inventory) |
Inventory and equipment (runtime) ​
| Class | What it is |
|---|---|
| DroppedItem | An item (or a pile of a currency) that lies in the world, where a character can pick it up. |
| EquipmentInventoryComponent | Equipment signals for Entity to connect to Emitted when stat bonuses are applied/removed from equipment |
| EquipmentSlotInstance | Equipment slot for single-item equipment storage |
| InventoryComponent | Universal inventory system for storing item instances and currency |
| InventorySlotInstance | Inventory slot with full stacking support and item management |
| ItemInstance | Runtime instance of an item that references an ItemDefinition for configuration Handles individual item state, modifications, effects, and socket management |
| KeptAsideSlotInstance | A stack of an item that is kept aside (see ItemDefinition.is_kept_aside): it lives in the list InventoryComponent.aside_slots, outside the slots, cells and weight of the bag. |
| SlotInstance | Base class for all slot types - provides common interface for item storage |
| VendorInventoryComponent | Stock-based vendor inventory that manages item availability and creates instances on-demand No longer inherits from InventoryComponent - uses pure stock tracking instead |